Help with Invalid Stops pleae

 

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

 
I am, of course, an idiot and mixed up Limit and Stop...again.
 
right you trying to set OP_SELLLIMIT below the market price
 

your code=> 

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

it should be

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