Metatrader deletes my Pending Order Script.

 

Hi folk,

I have the following situation with a script; I have tried many things but no way to have my very basic script up and running correctly.

When I use this script, MetaTrader deletes it as soon as the ask line reaches the order price.

int start()
{
OrderSend(Symbol(),OP_BUYSTOP,10,Bid+20*Point,3,0,Bid+30*Point,"BUYSTOP",0,0,Lime);
return;
}

***Then I tried to increase the magic number to 16384 :

int start()
{
OrderSend(Symbol(),OP_BUYSTOP,10,Bid+20*Point,3,0,Bid+30*Point,"BUYSTOP",16384,0,Lime);
return;
}

=> the pb remained.

*** Then I tried to increase the expiration time:

int start()
{
OrderSend(Symbol(),OP_BUYSTOP,10,Bid+20*Point,3,0,Bid+30*Point,"BUYSTOP",0,10800,Lime);
// 60 * 60 * 3 = 10800 seconds = 3 hours
return;
}

=> This time, the script does not start.

*** Then I tried to modify the 'return' command:

int start()
{
OrderSend(Symbol(),OP_BUYSTOP,10,Bid+20*Point,3,0,Bid+30*Point,"BUYSTOP",0,0,Lime);
return(0);
}

=> the pb remained.

*** Then I tried to define a SL
int start()
{
OrderSend(Symbol(),OP_BUYSTOP,10,Bid+20*Point,3,Bid-30*Point,Bid+30*Point,"BUYSTOP",0,0,Lime);
return(0);
}
=> The pb remains.

Then I tried all together, (except the expiration parameter let to 0) as it does not allow the script to start.

int start()
{
OrderSend(Symbol(),OP_BUYSTOP,10,Bid+20*Point,3,Bid-30*Point,Bid+30*Point,"BUYSTOP",16384,0,Lime);
return(0);
}

=> The pb remains.

===> I have no clue why this script is deleted by MetaTrader when the ask line reaches the order price. I have checked in docs.mql4.com/, it looks like for a pending order, I should set up the expiration parameter (https://docs.mql4.com/trading/OrderSend) but it does not work for me. I wondered whether this could come from the fact I use the Bid instead of Ask price, but I have the same result with sell stop order using the Ask Price.
Maybe I should use the Bid and Ask Price all the way around: define my buy stop entry with the Ask price, and my sell stop entry with the Bid Price, or only use the Ask Price for both ?????

Somebody can help please?
 
Your TP is 1 pip or 10 pips above your entry ? I guess it's 1 pip and is too close for your platform.
 
RaptorUK:
Your TP is 1 pip or 10 pips above your entry ? I guess it's 1 pip and is too close for your platform.


Thanx RaptorUK; actually it works if I define my entry / Ask Price only not the Bid Price; (TP = 1, = typo error, sorry about that).

 
Bid+20*Point,3, Bid-30*Point,Bid+30*Point

Is meaningless since we don't know whither you're on a 4 or 5 digit broker.

  1. EA's must adjust TP, SL AND slippage
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    
    Also you can't open or set stops closer than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point which is 30 (3 pips on IBFX) your Bid+20 would fail.
  2. => This time, the script does not start.
    Doesn't start is not the same as doesn't work. Put some print statements so you know which. Also ALWAYS check return codes
    int ticket = OrderSend(...);
    if (ticket < 0) Alert("OrderSend failed: ", GetLastError());


 

Thank you WHRoeder for your explanations.

Actually, it works if I define my settings depending on the Ask Price not the Bid Price; Now, when the market price reaches my entry price, the order stays opened and is not removed by MetaTrader.

Regarding the open price too close to the market price I noticed that as well: In this case, the script cannot start anyway.

Thanks again.