MT4
关于重复开仓(平仓)问题的较完美解决方案 好像不太适合现在的EA代码了 谁能给改
回复:0  浏览:13
  • 楼主admin 圈主
  • 2019-05-05 13:00
  • Params
  •         Numeric WaitTime(10);        //预设等待时间,单位为秒,可调整
  •         Numeric ShiftUnit(3);        //下单价格偏移量,可调整
  • Vars
  •         Numeric Lots;
  •         Numeric NewPrice;
  •         Numeric TimeSeconds;
  •         Bool    Openning;
  • Begin
  •         If ( Q_Last == 0 || ( Date != Date[1] && High == Low ) )         Return;        //如果未开盘,则直接返回
  •         If ( GetGlobalVar(10)==InvalidNumric  )        SetGlobalVar(10,0);        //下单时间初始化
  •         TimeSeconds=Value(Left(TimeToString(CurrentTime),2))*3600                //记录系统当前时间,转化为秒数
  •                                 +Value(Mid(TimeToString(CurrentTime),3,2))*60
  •                                 +Value(Right(TimeToString(CurrentTime),2));
  •         If ( TimeSeconds-GetGlobalVar(10)<WaitTime )        Return;        //如果发单后等待时间小于WaitTime,则返回
  •         Openning = Q_Last > Q_LowLimit && Q_Last < Q_UpperLimit;        //停板情况下不允许建仓
  •         If ( A_TotalPosition==0 && Openning==true )
  •         {
  •                 计算开仓手数Lots;
  •                 If ( 满足开多仓条件 )
  •                 {
  •                         NewPrice=Q_AskPrice+ShiftUnit*MinMove*PriceScale;        //计算开仓价格
  •                         A_SendOrder(Enum_Buy,Enum_Entry,Lots,NewPrice);
  •                         SetGlobalVar(10,TimeSeconds);                        //记录下单时间
  •                         Return;
  •                 }
  •                 If ( 满足开空仓条件 )
  •                 {
  •                         NewPrice=Q_BidPrice-ShiftUnit*MinMove*PriceScale;
  •                         A_SendOrder(Enum_Sell,Enum_Entry,Lots,NewPrice);
  •                         SetGlobalVar(10,TimeSeconds);
  •                 }
  •                 Return;
  •         }
  •         If ( A_BuyPosition>0 && 满足平多仓条件 )
  •         {
  •                 NewPrice=Q_BidPrice-ShiftUnit*MinMove*PriceScale;
  •                 A_SendOrder(Enum_Sell,Enum_Exit,A_BuyPosition,NewPrice);
  •                 SetGlobalVar(10,TimeSeconds);
  •         }
  •         If ( A_SellPosition>0 && 满足平空仓条件 )
  •         {
  •                 NewPrice=Q_AskPrice+ShiftUnit*MinMove*PriceScale;
  •                 A_SendOrder(Enum_Buy,Enum_Exit,A_SellPosition,NewPrice);
  •                 SetGlobalVar(10,TimeSeconds);
  •         }
  • End