How do Trailing Stops work and how do I code it?

 

Hi all,



I've successfully written a couple EAs, the first one specific for a 4hr chart, using long EMAs and Stochastics, and the second one specific to 5min chart using Envelopes and MACD. I've tried to code a Trailing Stop and just can't get it to work anywhich way. I don't get syntax errors, but it doesn't seem to make any difference whether the code is there or not...



Please help

 

Basic idea is you are long, and price is greater than your stoploss + X pips, you move the stoploss up to price - X pips.

If short, and price is lower than your stoploss - X pips, move the stoploss down to price + X pips.

Now, what do you need help with?

 
phy:

Basic idea is you are long, and price is greater than your stoploss + X pips, you move the stoploss up to price - X pips.

If short, and price is lower than your stoploss - X pips, move the stoploss down to price + X pips.

Now, what do you need help with?

Well, I think I understand the basic concept, but I can't seem to get it to function in my EA.



I must be coding it incorrectly or in the wrong place...

Reason: