Thank you for your reply.
You could modify the code so it only updates the CalculatedKValue when you're not in a position:
if(Position.MarketPosition == MarketPosition.Flat)
{
// call a new instance of the Stochastics indicator and assign the K value to our plot so it's drawn to the chart
CalculatedKValue[0] = Stochastics(StochPeriod, BarsAgoDifference, StochSmooth).K[0];
}
else
{
// don't update the K value while we are in a position, use the previous value
CalculatedKValue[0] = CalculatedKValue[1];
}

Comment