So I successfully implemented the above with the trailing stop loss activating above 0.2% profit,
However I am now trying to implement a fall off stop loss, where if profit is under 0.2% and the position has been active for more than 4 periods it will start to reduce the stop loss by a certain factor,
I have got this working with the following code:
private void AdjustFalloffStopLoss()
{
var stopLossPercentage = InitialStopLossPercentage - ((PeriodsInPosition - 3) * StopLossFalloffFactor);
if (Position.MarketPosition == MarketPosition.Long)
{
var newStopLoss = Position.AveragePrice - (Position.AveragePrice * stopLossPercentage);
if (CurrentStopLossPrice != 0 && newStopLoss > CurrentStopLossPrice && newStopLoss < Close[0])
{
SetStopLoss(CalculationMode.Price, newStopLoss);
CurrentStopLossPrice = newStopLoss;
}
}
if (Position.MarketPosition == MarketPosition.Short)
{
var newStopLoss = Position.AveragePrice + (Position.AveragePrice * stopLossPercentage);
if(CurrentStopLossPrice != 0 && newStopLoss < CurrentStopLossPrice && newStopLoss > Close[0])
{
SetStopLoss(CalculationMode.Price, newStopLoss);
CurrentStopLossPrice = newStopLoss;
}
}
}
In my playback connection debugging this code it works perfectly and exactly how I want it to perform, however in the simulation connection it doesn't work and continues to use the initial stop loss that is being set, even though its the same strategy that I'm running and same parameters on the same market and timeline, I am also resetting the stop loss to be the initial value of 0.2% after each time the market position enters flat.
Do you have any idea why this might be so different between connections?
Thank you again in advanced

Edit:
I have tried clearing the cache, There is no difference between the two connections as it also seems to behave incorrectly in the playback connection as well when I skip over the trades, however I then get the different (correct) result when debugging, could it be a performance issue with how the trades are populated on the chart?

Comment