I'm trying to build a trailing stop that works similar to the one you can do in ATM. ie. If I'm in profit 10 ticks, set the stop loss at 5 ticks and then move it up as the price moves up, always keeping 5 ticks below the current price or even better. After 10 ticks stop the price at +5 ticks...don't do anything until it reaches 15 ticks and if it does, set stop loss to +10 ticks...if it hits +20 then set stop loss, to +15, etc.
Let's say I'm just going long for now. Here's my approximate implementation:
// Somewhere in code: SetStopLoss(signal, CalculationMode.Price, stop, false); EnterLong(signal...);
And then...
protected override void OnBarUpdate() { try { if (BarsInProgress == 0) { if (IsFirstTickOfBar) { if(Open[1] > stop) { stop = Open[1] + tenTicks; SetStopLoss(signal, CalculationMode.Price, Open[1] - fiveTicks, false); } } } // more code.
Alternatively, I could use a plain SetStopLoss until I detect that a certain threshold has been reached and then I can cancel the stoploss and use SetTrailingStop instead, but I'm not sure how I'd do that.
What's the best practice here?
Thx!
Comment