wont open orders with very large stop loss.

 

In backtesting, I have the problem that if I try to send an order with a large stop loss (SL) and/or a large take profit (TP) value (eg. value of 9000, as illustrated by the code below) then the system rejects it and doesnt open it (not all the time though bizarely). If I send it with a lesser value (eg. value of 2000), then it works fine. Why??!! Can anyone help?

The MetaTrader version im using is a download from fxpro and they say (through a live chat conversation ive had with them) that as a broker have no maximal values for SL or TP. But maybe in backtesting there are maximal values? I have played around to try fix eg. increasing the initial deposit account value from 10,000 to 50,000 etc. but to no avail. help!!

int one= 9000; // SL

int two= 9000; // TP

OrderSend(Symbol(),OP_BUY,0.1,NormalizeDouble(Ask,Digits),1,NormalizeDouble(Bid,Digits)-one*Point,NormalizeDouble(Bid,Digits)+two*Point,"finalbuy",timing);

 

On a 4 digit broker, 9000 pips below bid is a NEGATIVE number on some pairs. (e.g. USDCHF 0.88xx-0.9000, USDJPY 81.xx-90.00)

If you don't want a tp or sl, use ZERO in the orderSend/orderModify


EAs must adjust tp, sl, AND slippage for 5 digit brokers. On ECN brokers you must orderSend and THEN set the tp, sl.

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
 
Thank you for the sample code WHRoeder! Using that I was able to go ahead and get the MACD Sample demo EA working properly, it seems. Now on to learn more about MQL4 instead of debugging sample programs. :)
 

"If you don't want a tp or sl, use ZERO in the orderSend/orderModify" - YES!, this is actually what I want.

So, to be clear you mean change it to this:

OrderSend(Symbol(),OP_BUY,0.1,NormalizeDouble(Ask,Digits),1,0,0,"finalbuy",timing);

ie. with a 0 in the TP and SL slots of the ordersend statement.

Thanks so much for this by the way. A great help!

Reason: