Issue with ApplyStop in AFL


I have observed a strange issue while using ApplyStop in AFL and that using Analysis settings -> Stops. I did the following:

  1. For a given trading system used the following parameters to apply Stops on a 15 minutes timeframes and got meaningful results:


The same above-mentioned values were also applied Analysis settings -> Stops.

  1. Optimized these parameters (Stop loss, Target, Trailing stop, and N-Bar stop) using "cmae" Engine and updated the values of these 4 parameters in the AFL as well as using Analysis settings -> Stops.

  2. Re-ran the backtest with these new parameters, and to my surprise, backtested results were different from the one shown in the Optimization report. Here in the report, it was still showing N-Bar (and other parameters) used before the optimization.

  3. To understand it better, I commented the ApplyStop AFL code for all 4 parameters while I retained the values in Analysis settings -> Stops same as mentioned in "2." and this time I got the correct result after backtesting.

Kindly help me understand why there was a difference earlier, as mentioned in Step 3, and how to fix it?

I tried repeating this several times but AFL is not accepting the new optimized values, it is still keeping the previous parameters in its memory (not visible), even though the AFL code is updated and saved before running the backtest.

Thanks and best regards

Did you maybe make a setting here:


Yes, I did, please see my message above, but it is not enough, in order to get the correct result I need to disable AFL ApplyStop section. Why so is not clear to me.

AFL ApplyStop code line overrides according same stop of Analysis UI stops settings.
Also if you want to use AFL ApplyStop function(s) only you should disable UI stops (so to have no additional other enabled stops from there being applied).
You can do this from AFL too

Settings in AFL overrule your settings in that window. Therefore if you add them to your AFL, those will become the value's that will be used.

Please see the pictures attached, in AFL it is showing N-Bar as 106, however, backtest is showing just 73 Bars, if I sort it from max to min. As you have suggested I have disabled it in the GUI Settings, please see below.


You are using Param function!
Open param window of Analysis and see what is set there.
Chances are that it is set to 73, right?

1 Like

Thanks a lot, it is fixed now. Appreciated much.

Best regards,

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.