Topic: when are indicators redrawn?

In the source code for FSB, for Trailing Stop, I have changed it to show the Trailing Stop with IndChartType.Dot -- makes a dot for the bar to show the Trailing Stop. If I change an indicator parameter and reopen the chart, the Trailing Stop changes and draws correctly.

I don't have an example, but it seems sometimes if I change something in Strategy Properties, like "Next Same Direction Signal Behavior", then reopen the chart, it does not redraw the Trailing Stop correctly, it still has old values.

Is there a function or method to call to ensure redrawing the Trailing Stop in the Strategy Property controls' event handlers?

thanks

Re: when are indicators redrawn?

Here I found an example:
http://s4.postimage.org/2omu09ndw/Indicator_does_not_redraw.jpg

But if I change a parameter, the dots and indicator values do not show, which is the expected behavior.

Re: when are indicators redrawn?

Is there a function or method to call to ensure redrawing the Trailing Stop in the Strategy Property controls' event handlers?

I'll check if a change in strategy Properties calls indicators recalculation. I think this is not the case in current FSB, but it's easy to be done. I'll revert tomorrow.

Re: when are indicators redrawn?

Strategy Properties tool doesn't recalculate the indicators. It doesn't have to do this because nothing is changed in indicators parameters.

The indicators that need information for open positions (like Trailing Stop, Stop Limit, ATR Stop, Account Percent Stop, Stop Loss, Take Profit, and Trailing Stop Limit) are additionally calculated during the backtest. You can find these calculations in Backtester Calculator.cs file in AnalyseExit(int bar) and s.

What you noticed about Trailing Stop is correct. The Component[0] array is not totally updated when you change something in Strategy Properties. The values in this array are somewhat temporary data used only when we transfer position.

We have in TransferFromPreviousBar(int bar) function:

// Saves the Trailing Stop price
if (Strategy.Slot[Strategy.CloseSlot].IndicatorName == "Trailing Stop" &&
    session[bar - 1].Summary.Transaction != Transaction.Transfer)
{
    double deltaStop = Strategy.Slot[Strategy.CloseSlot].IndParam.NumParam[0].Value * InstrProperties.Point;
    double stop = position.FormOrdPrice + (position.PosDir == PosDirection.Long ? -deltaStop : deltaStop);
    Strategy.Slot[Strategy.CloseSlot].Component[0].Value[bar - 1] = stop;
}

Here Strategy.Slot[Strategy.CloseSlot].Component[0].Value[bar - 1] = stop; only when the position was open or modified in the previous bar.
Later we use this value in AnalyseExit(int bar).

if (Strategy.Slot[Strategy.CloseSlot].IndicatorName == "Trailing Stop")
{
...
    // If there is a transferred position, sends a Stop Order for it.
    if (session[bar].Summary.PosDir == PosDirection.Long &&
        session[bar].Summary.Transaction == Transaction.Transfer)
    {
...
        double stop = Strategy.Slot[Strategy.CloseSlot].Component[0].Value[bar - 1];
...

In your screenshot the Trailing Stop component array contains values from the previous calculation  that are not zeroed. But this is not a bug since these values are not used from the backtester.

Re: when are indicators redrawn?

Hello Mr Popov, thanks for the explanation. I see, that makes sense. I suppose that is why the stop indicators are usually not drawn. I'll be sure to turn off drawing them before sending out any experimental builds for testing.

Re: when are indicators redrawn?

I suppose that is why the stop indicators are usually not drawn.

I was not thinking about drawing these indicators, but it must not be difficult to be done. Probably we have to add an additional component, one for long and one for short positions.