Issue with ApplyStop in AFL

Hi

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:
//StopLoss=Param("StopLoss",1.5,1,5,0.5);
//ProfitTarget=Param("ProfitTarget",24.5,15,30,0.5);
//TrailingStop=Param("TrailingStop",8.5,5,15,0.5);
//NBarStop=Param("NBarStop",72,50,100,1);

//ApplyStop(Type=0,Mode=1,Amount=StopLoss);
//ApplyStop(Type=1,Mode=1,Amount=ProfitTarget);
//ApplyStop(Type=2,Mode=1,Amount=TrailingStop);
//ApplyStop(Type=3,Mode=1,Amount=NBarStop);

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:

knipsel

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.

image

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,
Ghanshyam

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