如何尝试每隔X分钟下达待处理订单,直到成功为止?

时间:2019-08-16 15:46:49

标签: mql4 algorithmic-trading metatrader4 mt4

从我所做的研究来看,止损水平似乎阻止了我的挂单下达。我想通过每隔X分钟检查一次挂单是否可以通过直到成功下达,来解决此问题。我怎样才能做到这一点?我通过以下方式下达待处理订单:

double myEntryPrice=NormalizeDouble(Bid+(stopLevel*Point)+(bottom - 3*Point),Digits);
   int ticketSell = OrderSend(Symbol(),OP_SELLLIMIT,lotSize, myEntryPrice,0, stopLoss,dTakeProfit,"SellOrder",magicnumber,0,Red);

1 个答案:

答案 0 :(得分:0)

#include <Arrays\ArrayObj.mqh>
class CPendingOrder : public CObject
   {
public:
    int m_cmd;
    double m_lot;
    double m_osl;
    double m_otp;

    CPendingOrder(const int cmd,const double lot,const double osl,const double otp):
         m_cmd(cmd),m_lot(lot),m_osl(osl),m_otp(otp){}
   ~CPendingOrder(){}
   };

CArrayObj *listOfPendingOrders;
datetime lastPendingAttempt=0;

int OnInit()
   {
    lastPendingAttempt=TimeCurrent();
    listOfPendingOrders=new CArrayObj();
    //---
    return (INIT_SUCCEDED);
   }
void OnDeinit(const int reason){delete(listOfPendingOrders);}
void OnTick()
   {
    checkPendingList();
    //other operations

    //adding a limit order to the list when you need to do that
    int cmd=OP_SELLLIMIT; 
    double lot=0.1, osl=0, otp=0;
    CPendingOrder *newOrder=new CPendingOrder(cmd,lot,osl,otp);
    listOfPendingOrders.Add(newOrder);
   }
void checkPendingList()
   {
    if(iTime(_Symbol,PERIOD_M1,0)<=lastPendingAttempt)return;
    lastPendingAttempt=iTime(_Symbol,PERIOD_M1,0);
    double myEntryPrice=Bid;//set your formulae if needed here
    for(int i=listOfPendingOrders.Total()-1;i>=0;i--)
      {
       CPendingOrder *order=listOfPendingOrders.At(i);
       int ticket=OrderSend(_Symbol,order.m_cmd,order.m_lot,myEntryPrice,0,order.m_osl,order.m_otp,NULL,magicNumber,0);
       if(ticket>0)
            listOfPendingOrders.Delete(i);
      }
   }