Initialization of backtest buy/sell variables

I'm using ApplyStop() to instruct the backtester when to sell. So, I need not use sell variable.

I would like to use ExRem to remove excessive signals in buy variable.
http://www.amibroker.com/guide/afl/exrem.html

When I run the code below, I encounter error like "sell variable being used when it's unintialised".
buy = ExRem( buy, sell );

What's the best practice for initialising buy/sell backtest variables?

You still need to initialise the Sell variable when using ApplyStop.

So if you are only using ApplyStop for exits then you need;

Sell = 0;
1 Like

Is it good practice to always initialise buy and sell variables to 0?

Yes, Short and Cover variables also.

1 Like

You do not need to use ExRem in your case. In default backtest of Analysis (backtestRegular) excessive signals are removed already.
And in chart pane you rather have to use Equity() function to evaluate stops since you use ApplyStop() function. (In addition Equity() removes excessive signals.)

https://www.amibroker.com/guide/afl/applystop.html
https://www.amibroker.com/guide/afl/equity.html

1 Like

@fxshrat, thank you for your reply.

Should Equity(1) be placed before or after ApplyStop() or doesn't matter?

I look at the links below. One put Equity(1) before, one after.
https://www.amibroker.com/guide/afl/equity.html
https://www.amibroker.com/guide/afl/applystop.html

Equity is placed after signals and after Applystop as shown by Tomasz in comments of your posted link.

Here is another most recent example where you can see that Equity() is applied for chart only.

1 Like