Portfolio Backtester - Done Processing Symbols Function?  [SOLVED]

Questions about MultiCharts and user contributed studies.
dwitkin
Posts: 36
Joined: 18 Apr 2013
Has thanked: 41 times
Been thanked: 11 times

Portfolio Backtester - Done Processing Symbols Function?

Postby dwitkin » 23 Jun 2013

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

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Portfolio Backtester - Done Processing Symbols Function?

Postby Henry MultiСharts » 25 Jun 2013

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!");

dwitkin
Posts: 36
Joined: 18 Apr 2013
Has thanked: 41 times
Been thanked: 11 times

Re: Portfolio Backtester - Done Processing Symbols Function?

Postby dwitkin » 25 Jun 2013

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!");

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Portfolio Backtester - Done Processing Symbols Function?

Postby Henry MultiСharts » 26 Jun 2013

is there a way to identify what the last symbol of the backtest is programatically?
There is no 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.
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:

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!");

dwitkin
Posts: 36
Joined: 18 Apr 2013
Has thanked: 41 times
Been thanked: 11 times

Re: Portfolio Backtester - Done Processing Symbols Function?

Postby dwitkin » 26 Jun 2013

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.

User avatar
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]

Postby Henry MultiСharts » 27 Jun 2013

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.
Yes, that is possible.

You can also check the report for each individual symbol in Portfolio Performance Report->Breakdown by symbols


Return to “MultiCharts”