1

From the research I've done, the stop level seems to prevent my pending order from being placed. I want to solve this by checking every X minutes if the pending order will go through till it has successfully been placed. How can I do this? I am placing my pending order in the following way:

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);

SuperHueman
  • 165
  • 15
  • Are you sure that the price for your SELL_LIMIT is correct? Bid+stoplevel(1 tick )+bottom-3 ticks, what is bottom? – Daniel Kniaz Aug 16 '19 at 17:24
  • @DanielKniaz I am taking values from a rectangle that I’ve drawn on a chart where `stopLoss` is the top value of the rectangle and `bottom` is the lower value of the rectangle. But I want the `myEntryPrice` to be 3 pips below the `bottom`, that’s why I'm deducting `3*Point`. – SuperHueman Aug 16 '19 at 22:49

1 Answers1

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);
      }
   }
Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20
  • To be honest, I don't understand how to use the information in the link you provided to call `OrderSend()` till it is successful. – SuperHueman Aug 18 '19 at 17:22