- 精华
- 0
- 在线时间
- 322 小时
- UID
- 257171
- 积分
- 133
- 帖子
- 99
- 阅读权限
- 40
- 注册时间
- 2017-9-28
- 最后登录
- 2019-11-16
- 精华
- 0
- UID
- 257171
- 积分
- 133
- 帖子
- 99
- 主题
- 32
- 阅读权限
- 40
- 注册时间
- 2017-9-28
- 最后登录
- 2019-11-16
|
本帖最后由 masterhdd 于 2018-5-31 22:00 编辑
版主,我都晕死了,就这简单的双均线,模拟账户,三秒周期上运行,有时候能正常开平仓,有时就变成哑巴聋子了,彻底没反应,也不开仓,也不平仓。。。。。。快救救俺吧。。。。。严重怀疑自己人品有问题了
Params
Numeric FastLength(2);
Numeric SlowLength(8);
Numeric Lots (1);
Numeric OffSet (8);//委托价格偏移
Vars
NumericSeries AvgValue1;
NumericSeries AvgValue2;
Numeric TemB;//多头持仓
Numeric TemS;//空头持仓
Bool BPcond(False);
bool SPcond(False);
Bool BKcond(False);
Bool SKcond(False);
Numeric HasSP(0);//已平多仓标志
Numeric HasBK (0);//已开多仓标志
Numeric HasBP(0);//已平空仓标志
Numeric HasSK (0);//已开空仓标志
Begin
AvgValue1 = AverageFC(Close,FastLength);
AvgValue2 = AverageFC(Close,SlowLength);
PlotNumeric("MA1",AvgValue1);
PlotNumeric("MA2",AvgValue2);
// 集合竞价和小节休息过滤
If(!CallAuctionFilter()) Return;
if ( GetGlobalVar(0)==InvalidNumeric) //
{
HasSP = 0;
SetGlobalVar (0 ,HasSP);//
}ELse
{
HasSP = GetGlobalVar (0);//
}
if ( GetGlobalVar(2)==InvalidNumeric) //
{
HasBP = 0;
SetGlobalVar (2 ,HasBP);//
}ELse
{
HasBP = GetGlobalVar (2);//
}
If (GetGlobalVar(1)==InvalidNumeric) //
{
If(A_BuyPosition==0)
{
SetGlobalVar(1,0);
} else If(A_BuyPosition>0)
{
SetGlobalVar(1,1);
}
}ELse
{
HasBK = GetGlobalVar (1);//
}
If (GetGlobalVar(3)==InvalidNumeric) //
{
If(A_SellPosition==0)
{
SetGlobalVar(3,0);
} else If(A_SellPosition>0)
{
SetGlobalVar(3,1);
}
} ELse
{
HasSK = GetGlobalVar (3);//
}
BPcond=CrossOver (AvgValue1[1] , AvgValue2[1]);//买平的条件
SPcond=CrossUnder (AvgValue1[1] , AvgValue2[1]);//卖平的条件
BKcond=CrossOver (AvgValue1[1] , AvgValue2[1]);;//开多的条件 ,
SKcond=CrossUnder (AvgValue1[1] , AvgValue2[1]);//卖空的条件 ,
TemB = A_BuyPosition();//多头持仓
TemS = A_SellPosition(); //空头持仓
//开多
If(BKcond &&HasBK==0 and TemB==0&&barstatus==2) // 开多
{
A_SendOrder(Enum_buy,Enum_Entry,Lots,Q_AskPrice+OffSet*MinMove*PriceScale);//开多,
//Buy(lots,(c+OffSet*MinMove*PriceScale));
SetGlobalVar(0,0);//
SetGlobalVar(1,1);//
}
//平多
If(SPcond && HasSP==0 and TemB>0 && barstatus==2 ) // || QC==True ) 平多
{
A_SendOrder(Enum_Sell,Enum_Exit,TemB,Q_BidPrice-offSet*MinMove*PriceScale);//
//Sell(lots,(c-offSet*MinMove*PriceScale));
SetGlobalVar(0,1);//
SetGlobalVar(1,0);//
}
//开空
If(SKcond &&HasSK==0 and TemS==0&&barstatus==2 )
{
A_SendOrder(Enum_Sell,Enum_Entry,Lots,Q_BidPrice-OffSet*MinMove*PriceScale);
SetGlobalVar(2,0);
SetGlobalVar(3,1);
}
//平空
If(BPcond &&HasBP==0 and TemS>0 && barstatus==2 )
{
A_SendOrder(Enum_buy,Enum_Exit,TemS,Q_AskPrice+OffSet*MinMove*PriceScale);//A_SendOrder开多,
SetGlobalVar(2,1);//HasBP ==1,不允许再平空仓
SetGlobalVar(3,0);//HasSK==0,允许开空仓
}
End
|
|