开拓者期货期权程序化系统交易论坛

标题: 请老师帮忙一下,这部分代码有错误 [打印本页]

作者: flyer    时间: 2021-5-26 10:28:54     标题: 请老师帮忙一下,这部分代码有错误


           if(MarketPosition==1)   //有多单情况
          {
           if (high >=myentryprice+stop_win )   //止赢条件表达式
           {
           myexitprice=myentryprice+stop_win ;
           if(open >myexitprice)myexitprice=open;   //如果该BAR开盘价有跳空触发,则用开盘价代替
           sell(0,myexitprice);   
           }else        
          if Low <=myentryprice-stop_loss   // 止损条件表达式
          
           {
           myexitprice=myexitprice-stop_loss;
           if (open <myexitprice) myexitprice=open ;  //如果该BAR开盘价有跳空触发,则用开盘价代替
                     sell(0,myexitprice);
           
                   }else if (MarketPosition==-1)   //有空仓的情况
    {
          
           if (low <=myentryprice-stop_win ) //止赢条件表达式
           {
           myexitprice=myentryprice-stop_win;
           if(open<myexitprice) myexitprice=open ;
           BuyToCover(0,myentryprice);
           }else if (high >=myentryprice+stop_loss)      // 止损条件表达式
           {
           myexitprice=myentryprice+stop_loss;
           if (open>myexitprice) myexitprice=open;
           BuyToCover(0,myexitprice);
                      }          
End
作者: Yuen_Lee    时间: 2021-5-27 07:54:16

sell(0,myexitprice);句中的逗号是中文字符。其余的就是缺各种的小括号与中括号。改完的如下:
  1. if(MarketPosition==1)   //有多单情况
  2. {
  3.         if (high >=myentryprice+stop_win )   //止赢条件表达式
  4.         {
  5.                 myexitprice=myentryprice+stop_win ;
  6.                 if(open >myexitprice)myexitprice=open;   //如果该BAR开盘价有跳空触发,则用开盘价代替
  7.                 sell(0,myexitprice);   
  8.         }
  9.         else if (Low <=myentryprice-stop_loss)   // 止损条件表达式
  10.         {
  11.                 myexitprice=myexitprice-stop_loss;
  12.                 if (open <myexitprice) myexitprice=open ;  //如果该BAR开盘价有跳空触发,则用开盘价代替
  13.                 sell(0,myexitprice);
  14.         }
  15. }
  16. else if (MarketPosition==-1)   //有空仓的情况
  17. {
  18.         if (low <=myentryprice-stop_win ) //止赢条件表达式
  19.         {
  20.                 myexitprice=myentryprice-stop_win;
  21.                 if(open<myexitprice) myexitprice=open ;
  22.                 BuyToCover(0,myentryprice);
  23.         }
  24.         else if (high >=myentryprice+stop_loss)      // 止损条件表达式
  25.         {
  26.                 myexitprice=myentryprice+stop_loss;
  27.                 if (open>myexitprice) myexitprice=open;
  28.                 BuyToCover(0,myexitprice);
  29.         }
  30. }
复制代码

作者: flyer    时间: 2021-5-27 18:22:26

Yuen_Lee 发表于 2021-5-27 07:54
sell(0,myexitprice);句中的逗号是中文字符。其余的就是缺各种的小括号与中括号。改完的如下: ...

老师辛苦了,提示缺少分好,在您修改的这个13行
作者: Yuen_Lee    时间: 2021-5-28 07:51:35

flyer 发表于 2021-5-27 18:22
老师辛苦了,提示缺少分好,在您修改的这个13行

第13行用了中文的括弧和逗号,之前没看到
  1. if(MarketPosition==1)   //有多单情况
  2. {
  3.         if (high >=myentryprice+stop_win )   //止赢条件表达式
  4.         {
  5.                 myexitprice=myentryprice+stop_win ;
  6.                 if(open >myexitprice)myexitprice=open;   //如果该BAR开盘价有跳空触发,则用开盘价代替
  7.                 sell(0,myexitprice);   
  8.         }
  9.         else if (Low <=myentryprice-stop_loss)   // 止损条件表达式
  10.         {
  11.                 myexitprice=myexitprice-stop_loss;
  12.                 if (open <myexitprice) myexitprice=open ;  //如果该BAR开盘价有跳空触发,则用开盘价代替
  13.                 sell(0,myexitprice);
  14.         }
  15. }
  16. else if (MarketPosition==-1)   //有空仓的情况
  17. {
  18.         if (low <=myentryprice-stop_win ) //止赢条件表达式
  19.         {
  20.                 myexitprice=myentryprice-stop_win;
  21.                 if(open<myexitprice) myexitprice=open ;
  22.                 BuyToCover(0,myentryprice);
  23.         }
  24.         else if (high >=myentryprice+stop_loss)      // 止损条件表达式
  25.         {
  26.                 myexitprice=myentryprice+stop_loss;
  27.                 if (open>myexitprice) myexitprice=open;
  28.                 BuyToCover(0,myexitprice);
  29.         }
  30. }
复制代码

作者: flyer    时间: 2021-5-29 08:22:04

Yuen_Lee 发表于 2021-5-28 07:51
第13行用了中文的括弧和逗号,之前没看到

感谢老师,我想请老师能不能注释一下每一句代码,我新学习TB,谢谢您啊!

作者: Yuen_Lee    时间: 2021-5-31 08:05:00

flyer 发表于 2021-5-29 08:22
感谢老师,我想请老师能不能注释一下每一句代码,我新学习TB,谢谢您啊!
...

我只是更正了您原程序中的一些符号,没有改动或增加新语句,代码都是您以前的。




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2