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 )
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
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跳止损,跌停止盈