I am amused at how I am able to produce two files with the below code while I want only one. The question is how to properly use Name() function to get only the symbol the formula is run for in the file name and thus only one file?
VarSetText("symbol", Name());
_TRACE("VarGetText symbol: " + VarGetText("symbol"));
symbol = VarGetText("symbol");
_TRACE("symbol: " + symbol);
strategyName = "DESCRIPTIVE_STRATEGY_NAME";
direction = "LongAndShort";
folder = "C:\\tmp\\Trading\\Systems\\";
filepath = folder + strategyName + "_" + symbol + "_" + direction + "_Trades.csv";
mode = "w";
fh = fopen(filepath, mode, True);
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio) {
bo = GetBacktesterObject();
bo.Backtest();
}
Buy = Sell = Short = Cover = 0;
BuyPrice = SellPrice = ShortPrice = CoverPrice = 0;
fputs(symbol + "\n", fh);
fclose(fh);
I get the following output:
I can of course notice that if I remove the custom backtester code my (almost all) "problems" go away. To my untrained newbie eye it looks like when I push "Backtest" formula/code is run twice...
Above is just a snippet of reproducible code. The aim is to use custom backtester to export the trades to csv file.
I know this is all with probability one documented on page 17256394 of AFL manual and in KB 9236572923 and I am to dumb and/or lazy to look it up, however, I still can not resist the urge to ask the experts for explanation of the above phenomenon and what to do to get what I want. Thank you.
It might become obvious to me in a couple of thousand years that if I would have learned how to properly use AFL and do the RTFM I would never feel the desire (which is, I agree, the root of all my suffering) to export trades into csv but would be able to do all the analysis in Amibroker. I am not at that stage yet, so this kind of advice is not helpful at this stage of the learning curve. Thanks for understanding.