MQL 4: Stop loss trouble

To add comments, please log in or register
fibioso
10
fibioso  

Hi Everyone,


I've created a strategy that requires me to place a stop loss above/below the previous bar depending on whether I'm short or long. It uses the high/low, (HL), the ATR to guage the distance, and an ATR multiplier to decide on te increment of distance from the high/low. I've worked out the calculations and have found them to be correct (hopefully) but when I test it, the EA places a stop 1-2 pips from where the trade was opened which has not been the right place on any of the occassions I've checked (running test on open prices only for now). 


Could someone please help?


if(LongOrShort == 1) { //long
         HL = Low[1];
         ATR = (volMultiplier * VolATR);
         StopL = NormalizeDouble((HL - ATR), 5); 
         }
     if(LongOrShort ==2) { //short
        HL = High[1];
        ATR = (volMultiplier*VolATR);
        StopL = NormalizeDouble((HL + ATR), 5);
     
Keith Watford
Moderator
14029
Keith Watford  
 ATR = (volMultiplier * VolATR);

Where do you get the highlighted variables' values from?

Ahmet Metin Yilmaz
2978
Ahmet Metin Yilmaz  

it is not right to comment without seeing all of the codes
fibioso
10
fibioso  
Hello, 

VolATR is just an average true range 
iATR(...) 
The multiplier is an external double (I have it set at one by default). 

So in theory, the stop should appear either 1 x the average true range above the previous high for a short or 1 x the average true range below the previous low for a long.  

I’m out and about at the minute so I don’t know how helpful this is. Let me know if you need anything else. Thank you!
To add comments, please log in or register