Stoploss an alternative methods

 

Hi guys,

I am a newrier to MQL 4 but I have already coded some EA and testing.

But I am not a professional or expert programmer so I need to an help.

I would like to know how I can set the STOP LOSS for sell and buy market order using a fractal.

I meanI would like to have  a STOPLOSS= fractals or example  SL= highest/lowest into x bar - atr ...

I tried using this code but it doesn't work: this is the error Testing pass stopped due to a critical error in the EA




double StopLong=iFractals(NULL,0,MODE_LOWER,1);                                     

double StopShort=iFractals(NULL,0,MODE_UPPER,1);  

Then for the open trade

......

 {OrderSend(Symbol(),OP_BUY,.1,Ask,Slippage*Point,StopLong,Ask+TPLong*Point,"EA204080_Long",MagicNumber,0,Blue);}

  ..................

   { OrderSend(Symbol(),OP_SELL,.1,Bid,Slippage*Point,StopShort,Bid-TPShort*Point,"EA204080_Short",MagicNumber,0,Green);}

 
double StopLong=iFractals(NULL,0,MODE_LOWER,1);                                     

double StopShort=iFractals(NULL,0,MODE_UPPER,1);  

I can't remember how many closed bars fractals need, but you should not rely on shift 1 having a useable value.

You should maybe loop back until you find an actual fractal and then you will need to check that it can be used as a stoploss (ie it may be higher than the entry for a long which is obviously no use).

 
Keith Watford:

I can't remember how many closed bars fractals need, but you should not rely on shift 1 having a useable value.

You should maybe loop back until you find an actual fractal and then you will need to check that it can be used as a stoploss (ie it may be higher than the entry for a long which is obviously no use).

Thank you Keith but it's the same than I tried

What is the difference?

 

I coded it but I don't take the SL


 OrderSend(Symbol(),OP_BUY,NLots,Ask,Slippage*Point,StopLong,Ask+(TakeProfit*Point),"......................);

        }//end OPEN BUY


SL=0???'

2008.01.30 21:30 buy 5 0.11 1.48671 0.00000 1.49251 0.00 2236.84


Reason: