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

标题: 请帮忙审查一哈,米。 [打印本页]

作者: lcxamm    时间: 2018-11-5 23:26:55     标题: 请帮忙审查一哈,米。

本帖最后由 lcxamm 于 2018-11-6 10:41 编辑

反6跳止损,涨跌停止盈,14.55对价平仓,tick交易,穿越支撑压力线对价开仓。

Params
         Numeric notaft(14.55);
         Numeric upperband(4280);
         Numeric lowerband(4272);
        
Vars
        Numeric minpoint;
bool con;                                         // bool中间变量
bool con1;                                         // bool中间变量
Begin
         MinPoint = MinMove*PriceScale;
         PlotNumeric("upperband=",upperband);
         PlotNumeric("lowerband=",lowerband);
         con = High >= upperband;
         con1= low <= lowerband;
        
         //开仓
        if (a_buyposition==0 and barstatus==2 and con)
            {
            A_SendOrder(Enum_Buy,Enum_Entry,1,Q_AskPrice,Q_AskPrice-6*MinPoint,Q_UpperLimit);;
            }
            
               if (a_sellposition==0 and barstatus==2 and con1 )
            {
           A_SendOrder(Enum_Sell,Enum_Entry,1,Q_BidPrice,Q_AskPrice-6*MinPoint,Q_LowerLimit);;
            }      
         //收盘平仓
          if(Time*100>=notaft and Time<0.1600 and barstatus==2 )

{
       {if(A_BuyPosition>0)
{
   A_SendOrder(Enum_Sell, Enum_Exit, A_BuyPosition(), Q_BidPrice);
}else If(A_SellPosition>0)
{
A_SendOrder(Enum_Buy, Enum_Exit, A_SellPosition(), Q_AskPrice);
}
}
}


End
作者: 小米    时间: 2018-11-6 09:02:47

万不可
作者: lcxamm    时间: 2018-11-6 09:13:33

小米 发表于 2018-11-6 09:02
万不可

愿闻其详啊
作者: 小米    时间: 2018-11-6 09:21:01

本帖最后由 小米 于 2018-11-6 09:22 编辑

1,crossover,crossunder等函数是序列函数,不可放条件内进行运算。可声明中间变量,在条件外先将运算赋值给中间变量,再将中间变量代入条件中进行判断。

2,A函数的属性,只在最后K线有效,所以为提高效率以及减少无效值的判断异常,需要限制在barstatus==2的条件下 。

3,A_sendorder的发单,软件底层是没有做任何控制的。所以需要交易者自己想办法使用代码条件进行控制,以免发生重复发单 。
     而仅有持仓量这个判断是不够的,因为一个委托出去,经过网络,再到交易所撮合成交,再将成交回报返回到本地,这个过程是需要时间的。一个tick内不能完成整个流程,下一个tick是可能会再次发单 ,造成重复。
     所以,a_sendorder发单一般是需要配合使用全交易变量进行发单 次数的控制 。
作者: lcxamm    时间: 2018-11-6 09:23:45

小米 发表于 2018-11-6 09:21
1,crossover,crossunder等函数是序列函数,不可放条件内进行运算。可声明中间变量,在条件外先将运算赋值 ...

谢谢,任重道远。
作者: 小米    时间: 2018-11-6 09:27:26

lcxamm 发表于 2018-11-6 09:23
谢谢,任重道远。


作者: lcxamm    时间: 2018-11-6 10:54:49

本帖最后由 lcxamm 于 2018-11-6 11:11 编辑

1,同一个条件?完全一样?那直接在条件下同时下两个委托语句好了,使用不同的委托价即可。
    如果你说价格下跌后再去加仓,那一定是有条件的不同吧?价格的不同难道不算吗?

4,我觉得开仓时记录一个全局变量,之后每个tick给此全局变量的值+1,待5个tick后,直接判断a_getopenordercount是否大于0,如果大于0就去撤单,然后重下新下单 。
所以还是得当前状态有已报单即a_getopenordercount(0)!=InvalidInteger and >0的情况下,才去取a_openorderfilledprice(0)的值较为合理。
3,善用fileappend来进行,可令公式的调试效率更高。自己拿不准的地方使用fileappend一步步输出或者会有所帮助 。

参考1
if(BarStatus==0)
  SetGlobalVar(0,0);
/* if(GetGlobalVar(0)==0 and A_BuyPosition>0)
  SetGlobalVar(0,1);
if(GetGlobalVar(0)==0 and A_SellPosition>0)
  SetGlobalVar(0,-1);  */
If(BarStatus==2 and A_BuyPosition==0 and GetGlobalVar(0)==0 and  l2[1]==l3[1] and l2>l3 )
   {A_SendOrder(Enum_Buy,Enum_Entry,1,Q_Last);
    SetGlobalVar(0,1);
        PlotString("1","开多",low,red);
}


    If(BarStatus==2 and  A_BuyPosition>0 and GetGlobalVar(0)==1 and  h1[1]==h2[1] and  h1<h2 )
    {A_SendOrder(Enum_Sell,Enum_Exit,1,Q_Last);
         SetGlobalVar(0,0);
    PlotString("2","平多",high,Yellow); }
作者: lcxamm    时间: 2018-11-6 11:11:19

条件分开。一层层定位。。
If(BarStatus==2 and A_BuyPosition==0 )
{
        FileAppend("d:\\testduo1.log","a_buypositon==0");
        If(  myorderbuy==0 )
    {  
                FileAppend("d:\\testduo1.log","myorderbuy==0");
        If(mbuy and High>High[1])
        {
                        A_SendOrder(Enum_Buy,Enum_Entry,lots,Q_BidPrice+OffSet*MinPoint);
                        myentryprice = Q_BidPrice+OffSet*MinPoint;
                        myorderbuy = 1;
                        myordersell = 0;
                        SetGlobalVar(1,myorderbuy);
                        SetGlobalVar(2,myordersell);
                        FileAppend ("d:\\testduo1.log","GlobalVar(1)="+Text(GetGlobalVar(1))+"Date="+DateToString(CurrentDate)+"Time="+TimeToString(CurrentTime)+"委托时间="+TimeToString(A_OrderTime(0))+"mbuy是否成立="+IIFString(MACDDiff>MACDDiff[1],"true","False")+"k是否成立="+IIFString(High>High[1],"yes","no")+"委托价格="+text(myentryprice));
         }
        }
        }
   If(BarStatus==2 and low<low[1] )
   {
                FileAppend("d:\\testduo1.log","low<low[1]");
                If(A_BuyPosition>0 )
                {
                        FileAppend("d:\\testduo1.log","myorderbuy=>0");
                        If(msell )
                        {
                                FileAppend("d:\\testduo1.log","msell==true");
                                If( myordersell==0 )
                                {
                                        FileAppend("d:\\testduo1.log","myordersell==0");
                                       
                                           A_SendOrder(Enum_Sell,Enum_Exit,lots,Q_AskPrice-OffSet*MinPoint);
                                           myexitprice = Q_AskPrice-OffSet*MinPoint;
                                           myordersell = 1;
                                           myorderbuy = 0;
                                           SetGlobalVar(1,myorderbuy);
                                           SetGlobalVar(2,myordersell);
                                          
                                           FileAppend ("d:\\testduoping.log","GlobalVar(2)="+Text(GetGlobalVar(2))+"Date="+DateToString(CurrentDate)+"Time="+TimeToString(CurrentTime)+"委托时间="+TimeToString(A_OrderTime(0))+"msell是否成立="+IIFString(MACDDiff<MACDDiff[1],"true","False")+"k是否成立="+IIFString(low<low[1],"yes","no")+"委托价格="+text(myexitprice));
                }
                        }
                }
        }
复制代码
作者: lcxamm    时间: 2018-11-6 11:48:14

需要使用全局变量来控制撤单 与发单 的委托次数。。
因为委托出去到回报返回到本地,是需要时间的,这个过程中,可能已经有新的tick进来,再次运算,发现当前条件仍满足于是再次委托 。。而事实上之前的委托可能已经到了交易所或是在返回的中途了,这样就会导致重复委托的结果 。。
作者: lcxamm    时间: 2018-11-6 11:58:12

FileAppend("D:\\tick日志.log",DateTimeToString(Date+CurrentTime)+"  OpenOrderCount:"+Text(A_GetOpenOrderCount)+" TP:"+Text(CC)+" TotalPosition:"+Text(A_TotalPosition)) 记录如下:
作者: superwin    时间: 2018-11-6 16:19:31

在没弄懂TB规则以及图表函数之前,请勿轻易尝试账户函数,学习要有个先后过程,直接跳过基础去学进阶的账户函数,并不是个好办法。
作者: lcxamm    时间: 2018-11-6 17:50:33

superwin 发表于 2018-11-6 16:19
在没弄懂TB规则以及图表函数之前,请勿轻易尝试账户函数,学习要有个先后过程,直接跳过基础去学进阶的账户 ...

大神你来了。
作者: lcxamm    时间: 2018-11-7 00:13:18

本帖最后由 lcxamm 于 2018-11-7 00:22 编辑

Params
         Numeric notaft(14.55);//平仓时间
         Numeric upperband(4280);//压力位置
         Numeric lowerband(4272);//支撑位置
        
Vars
        Numeric Minpoint;//最小跳点数
        bool con;                                         // bool中间变量
        bool con1;                                         // bool中间变量

Begin
         if(BarStatus==0)
         SetGlobalVar(0,0); //初始化全局变量
         if(GetGlobalVar(0)==0 and A_BuyPosition>0)
         SetGlobalVar(0,1);//判断多头持仓并标记
         if(GetGlobalVar(0)==0 and A_SellPosition>0)
         SetGlobalVar(0,-1);//判断空头持仓并标记   
         MinPoint = MinMove*PriceScale;//最小变动
         PlotNumeric("upperband=",upperband);
         PlotNumeric("lowerband=",lowerband);
         con = High >= upperband;//多单条件
         con1= low <= lowerband;//空单条件
        
         //开仓
        if (a_buyposition==0&&barstatus==2&&GetGlobalVar(0)==0&&con)//无多单,最新bar,全局变量初始值,多单条件满足
  {A_SendOrder(Enum_Buy,Enum_Entry,1,Q_AskPrice,upperband-6*MinPoint,Q_UpperLimit);;SetGlobalVar(0,1);}//买入开仓1手,对价,压力-6跳止损,涨停止盈

        if (a_sellposition==0&&barstatus==2&&GetGlobalVar(0)==0&&con1 )//无空单,最新bar,全局变量初始值,空单条件满足
        {A_SendOrder(Enum_Sell,Enum_Entry,1,Q_BidPrice,lowerband+6*MinPoint,Q_LowerLimit);;SetGlobalVar(0,-1);} //卖出开仓1手,对价,支撑+6跳止损,跌停止盈     
      
         //收盘平仓
if(barstatus==2&&Time*100>=notaft&&Time<0.1600 )//最新bar,时间超过平仓时间
{
       {if(A_BuyPosition>0&&GetGlobalVar(0)==1)//持有多单
{
A_SendOrder(Enum_Sell, Enum_Exit, A_BuyPosition(), Q_BidPrice);//对价平所有仓
   SetGlobalVar(0,0);}//初始化
else If(A_SellPosition>0&&GetGlobalVar(0)==-1)//持有空单
{A_SendOrder(Enum_Buy, Enum_Exit, A_SellPosition(), Q_AskPrice);//对价平所有仓
SetGlobalVar(0,0);//初始化
}
}
}


End
作者: lcxamm    时间: 2018-11-7 14:29:03

superwin 发表于 2018-11-6 16:19
在没弄懂TB规则以及图表函数之前,请勿轻易尝试账户函数,学习要有个先后过程,直接跳过基础去学进阶的账户 ...

大神,帮我看看修改过的13楼,可以否。




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