Independant Trailing Stop for multiple orders

 

EA may have several market orders open at any time, each order has its own indicator set stoploss value.

To trail the same fixed distance from market for an order with SL = 10pips, and one with SL = 150pips is just "stupid".

Trailing must be done proportional to the order's initial SL. Problem is that once trailing starts the initial SL is lost... I need to store it somewhere...

In the order send function we might store ticket and SL in an array, or write to file on disk.

Using order comment is useless as it may or will be overwritten by the trade server.

Another way is to merge the SL price into the magicnumber, this limits the magic to the last two digits of the integer, so magic must range 1 - 99 (no problem).

I have tested this and it works but its a bit laborious to dissasemble the order's magic to extract the true magic and SL.  See code.

Is there a simpler or better way to store the order's SL with the order ?

int MAGIC = 99;//EAs magic number, must be 1 - 99
         int CompMagic_Integer;
         string CompMagic_String;
         CompMagic_String = DoubleToString(NormalizeDouble(OrderStopLoss()* MathPow(10, Digits),7) + IntegerToString(MAGIC,2));
         CompMagic_Integer = StringToInteger(CompMagic_String);         
         Print("    DEBUG: CompMagic "+  DoubleToString(CompMagic_Integer));////Output: EURUSD,M5:     DEBUG: CompMagic 10837499.00000000
 
Pilot65: Is there a simpler or better way to store the order's SL with the order ?

Set GV ISLnnnnnn

 
William Roeder:

Set GV ISLnnnnnn

Eh... GV?  Pls explain just a little bit more...
 
William Roeder:

Set GV ISLnnnnnn

Ah got it, Global Variable. Problem is that one would need one GV for each open order, and then which belongs to to where?? Dangerous in case terminal / EA restart.

Reason: