I want to set the backtest settings of Positions to
Short as in the screen capture below.
I would like to do this using AFL code instead of manually configuring it in the backtest settings. If I do not configure this setting, my short backtest afl code does not return any results.
I cannot find this option in
SetOption(). Maybe I carelessly missed out. Can someone help? Thank you.
SetOption field for that setting.
If you want to decide whether "Long" or "Short" or "Long and short" via AFL then simply set "Positions" to "Long and short" and then in code set
Sell variables to zero if you only want to execute Short signals.
// Only short
Buy = Sell = 0;
Short = Cross(MA(C,20),C);
Cover = Cross(C,MA(C,20));
Cover variables to zero if you only want to execute Long signals.
// Only long
Buy = Cross(C,MA(C,20));
Sell = Cross(MA(C,20),C);
Short = Cover = 0;
Also to save analysis settings and AFL you can save to APX project files (via File - Save/Save as).
Thank you for your answer as usual.
I think Amibroker default settings should set to "Long and short" instead of "Long" for more flexibility.
My backtest afl script is still under development and constantly changing. It is not convenient to be saved as APX file which is more suitable for finalised scripts.
There isn't really default analysis setting. The last used analysis settings of the analysis window that is closed as the last one become new default settings.
So close all analysis window except for just single opened one and set to "Long and short" at "Positions" and then click OK and then close that last analysis window. Then re-open new analysis window, go to Analysis settings - General and you will see that "Long and short" has become new default for all next analysis windows (until you will change that setting at last open window again and will close it afterwards).
Thank you. Your solution works! The last used analysis settings of the analysis window that is closed as the last one become new default settings.