I am trying to export custom metrics when the portfolio backtester is done with a given test. I have the export function working correctly for individual charts, but I can't figure out how to determine if the Portfolio Backtester is done processing all symbols. (e.g., is there an equivalent of "LastBarOnChart_s" in the Portfolio Backtester).
Since I only want to write a trailer record to a file when the Portfolio Backtester is done processing all symbols, is there an "IF" statement I can use to determine when the Portfolio Backtest is complete?
Thanks,
Dave
Portfolio Backtester - Done Processing Symbols Function? [SOLVED]
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Portfolio Backtester - Done Processing Symbols Function?
Hello Dave,
LastBarOnChart works in Portfolio Backtester. As the calculation is done bar by bar on each instrument vertically you can create a signal that will notify you regarding the calculation on the last bar of the last instrument of the portfolio:
LastBarOnChart works in Portfolio Backtester. As the calculation is done bar by bar on each instrument vertically you can create a signal that will notify you regarding the calculation on the last bar of the last instrument of the portfolio:
Code: Select all
if symbolname = "MSFT" and LastBarOnChart then print ("last bar calculation!");
Re: Portfolio Backtester - Done Processing Symbols Function?
Thanks Henry. Helpful, but is there a way to identify what the last symbol of the backtest is programatically? I don't want to have to update my code every time I change the list of symbols I'm doing a backtest on.
Hello Dave,
LastBarOnChart works in Portfolio Backtester. As the calculation is done bar by bar on each instrument vertically you can create a signal that will notify you regarding the calculation on the last bar of the last instrument of the portfolio:Code: Select all
if symbolname = "MSFT" and LastBarOnChart then print ("last bar calculation!");
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Portfolio Backtester - Done Processing Symbols Function?
There is no way to identify what the last symbol of the backtest is programatically.is there a way to identify what the last symbol of the backtest is programatically?
You can just write the information you need on the last bar of each instrument with Print File or FileAppend command. Current symbol will overwrite the output of the previous symbol and the final result will be the output of the very last symbol of the portfolio:I don't want to have to update my code every time I change the list of symbols I'm doing a backtest on.
Code: Select all
if LastBarOnChart then print (file("C:\test_print.txt"),getsymbolname, "last bar calculation!");
// or
if LastBarOnChart then FileDelete("C:\test_append.txt");
if LastBarOnChart then FileAppend ("C:\test_append.txt","last bar calculation!");
Re: Portfolio Backtester - Done Processing Symbols Function?
Interesting idea! Thanks, I'll try that.
As a related aside, I'd be interested in your (or other people's) opinion about this as a possible solution:
Could you create an array on the first bar of each symbol / chart to count each distinct symbol in the portfolio backtest? Then, you could count the symbols on the last bar and only do the export when the last symbol is processed.
Does that sound feasible? I bring it up because I do want to write trade buy/sell data for each symbol, so the idea about overwriting the data on each new symbol could work for me with some tweaking (I'd probably need to generate separate files for the trade log versus the final metrics, true?), but I want to explore a cleaner solution if possible.
Thanks for your feedback.
As a related aside, I'd be interested in your (or other people's) opinion about this as a possible solution:
Could you create an array on the first bar of each symbol / chart to count each distinct symbol in the portfolio backtest? Then, you could count the symbols on the last bar and only do the export when the last symbol is processed.
Does that sound feasible? I bring it up because I do want to write trade buy/sell data for each symbol, so the idea about overwriting the data on each new symbol could work for me with some tweaking (I'd probably need to generate separate files for the trade log versus the final metrics, true?), but I want to explore a cleaner solution if possible.
Thanks for your feedback.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Portfolio Backtester - Done Processing Symbols Function? [SOLVED]
Yes, that is possible.As a related aside, I'd be interested in your (or other people's) opinion about this as a possible solution:
Could you create an array on the first bar of each symbol / chart to count each distinct symbol in the portfolio backtest? Then, you could count the symbols on the last bar and only do the export when the last symbol is processed.
You can also check the report for each individual symbol in Portfolio Performance Report->Breakdown by symbols