Download MetaTrader 5

Help with Invalid Stops pleae

To add comments, please log in or register
Sign up for MQL5.community to post your Forum topic
Arthur Ockwell
41
Arthur Ockwell 2016.03.22 13:28 

Hi,

I calculate my trade parameters as follows:

entry=iLow(NULL,0,1)-20.0;
tp=entry-InitalTarget;
sl=entry+InitalStop;

Print(DisplayTimeStr," [",Symbol(),"] Time ["+LondonDate+" "+LondonTime+"]",
                                       " BuyOrSell '",BuyOrSell,"' entry ", DoubleToString(entry,Digits)," TP ",DoubleToString(tp,Digits),
                                       " SL ",DoubleToString(sl,Digits)," Ask ",DoubleToString(Ask,Digits)," Bid ", DoubleToString(Bid, Digits)); 

The -20.0 on the entry price is to ensure that I am not too close to the Bid price, in reality this will be set to 2.0. Trade is triggered immediately on candle close, so I think I can get away with this.

Here is the code around OrderSend, I have put in extra tracing in an attempt to find the problem!

    RefreshRates();
    Print(DisplayTimeStr," [",Symbol(),"] Time ["+LondonDate+" "+LondonTime+"]",
                                       " TypeOfOrderReqd '",TypeOfOrderReqd,"' entry ", entry,
                                       " Ask ",DoubleToString(Ask,Digits)," Bid ", DoubleToString(Bid, Digits)); 

    if(TypeOfOrderReqd=="Sell")
      Ticket=OrderSend(Symbol(),OP_SELLLIMIT,NumberOfLots,NormalizeDouble(entry,Digits),0,0,0,NULL,Magic,0,Red);
      Print("OrderSend(",Symbol(),",OP_SELLLIMIT,",NumberOfLots,",",DoubleToStr(entry,Digits),",0,","0",",","0",",NULL,",Magic,",0,Red)");  

and here is what I find in the Journal when using Strategy Tester:

GER30(£),M1: 18/03/16 10:57 [GER30(£)] Time [21.03.2016 07:10] BuyOrSell 'Sell' entry 9889.7 TP 9869.7 SL 9909.7 Ask 9913.0 Bid 9910.7
GER30(£),M1: 18/03/16 10:57 [GER30(£)] Time [21.03.2016 07:10] TypeOfOrderReqd 'Sell' entry 9889.700000000001 Ask 9913.0 Bid 9910.7
GER30(£),M1: OrderSend error 130
GER30(£),M1: OrderSend(GER30(£),OP_SELLLIMIT,2.0,9889.7,0,0,0,NULL,237502,0,Red)
GER30(£),M1: Alert: 18/03/16 10:57 [GER30(£)]  *** Sell order open failed -error code: 130 (invalid stops)

Firstly, I know I am not supplying any stops, that should be OK. I have tried amending the code to Normalised stops and targets with a 100 pip range just to make sure though; it didn't help :(

I think the problem could be in the value of the entry, but as you can see I have used NormalizeDouble. I am aware of the problem with Print() and that it uses a different precision unless DoubleToString is used, hence the 9889.7000000000001 in the print string above shouldn't be a problem.

Grateful for nay advice or assistance.

Thanks

Art

Arthur Ockwell
41
Arthur Ockwell 2016.03.23 13:31  
I am, of course, an idiot and mixed up Limit and Stop...again.
Aleksei Beliakov
23854
Aleksei Beliakov 2016.03.24 06:53  
right you trying to set OP_SELLLIMIT below the market price
Siti Latifah
6446
Siti Latifah 2016.03.28 04:04  

your code=> 

entry=iLow(NULL,0,1)-20.0;

it should be

entry=iLow(NULL,0,1)-20.0*Point;
To add comments, please log in or register