Stoploss coding help!

 

Hello,

I am trying to write this line into my EA to set a stop loss, but i don't understand the calculation...

{SL=Low[i]-(MarginPips+StopLoss)*Point;

SL is the Stop loss to be used in the trade, MarginPips is an input parameter aswell as StopLoss, but i dont have a clue what Point is! Its not an input.

Ive run it through a demo account and it just creates a stoploss, not set by my input parameter and at no correlation to it. So what is the formula doing?!?!

Thanks for all your help!!

Ryan

 

Point is the decimal places to the right of the price. EX. the price is 1.5168 point would be 0.0001 if it was 1.51682 it would be 0.00001.

If you plug that into the equation you get the pips from a whole number. 50 * Point (0.0001) = 0.005 which would be what you are adding or subtracting from a price to adjust your SL.


Does that make since?

 

It is used to convert integers down to the appropriate point value

So if you want a 20pip stop (on a 4 digit broker) it will do 20*0.0001=0.0020 which you can now subtract from the price. For a 5 digit broker you would need 200point stop.

https://docs.mql4.com/predefined/variables/point

hth

V

 

Ahhhh... that makes so much sense! But why is it subtrated from 'Low'? And what is the MarginPips all about?!

Thanks very much for your help :)

 

The MarginPips and StopLoss looks like they are variables to me. Low[i] is the low of the bar i behind the current bar. 0 would be current so it is whatever the value of 'i' is.


It is subtracting from the Low[] to get the stop loss. So if the low of the bar i steps away is 1.5693 and the MarginPips+StopLoss = 50 it would subtract 0.005 from that Low[]. However, MarginPips and the StopLoss I think are defined somewhere in the code so I'm not sure how they are deduced.


MQL4 has some good documentation here on their site. https://docs.mql4.com/predefined/variables/low

 

I see.. so if i wanted the stoploss to be 200 pips lower(on a 5 digit broker) it would be {SL=StopLoss*Point;} ?

Cheers guys :)

 

Viffer:

So if you want a 20pip stop (on a 4 digit broker) it will do 20*0.0001=0.0020 which you can now subtract from the price. For a 5 digit broker you would need 200point stop.

A human shouldn't have to adjust values when switching from a 4 digit broker to a 5. Set the variables to pips and the EA should adjust to points:

//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        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

maletf:

I see.. so if i wanted the stoploss to be 200 pips lower(on a 5 digit broker) it would be {SL=StopLoss*Point;} ?

On a 5 digit broker it would be SL= Bid - StopLoss*10*point;
Reason: