Calculating "Portfolio Entries Today"

Questions about MultiCharts and user contributed studies.
Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Calculating "Portfolio Entries Today"

Postby Xyzzy » 03 Apr 2016

I'm running a strategy on about 100 ETF symbols using the Portfolio Backtester. I'd like the strategy to "know" the total number of entries for the portfolio in the current day (for all symbols in the portfolio). In pseudocode, I'd like something like:

Code: Select all

If PortfolioEntriesToday() < 10 then begin
(do something)
end else if PortfolioEntriesToday() < 20 then begin
(do something else)
end;
Are there any native keywords or functions that would allow me to do this? If not, could anyone point me in the right direction about the best way to go about this?

One possibility would be to use the EntriesToday(date) function for each symbol, and keep track of the the running total for all symbols using All Data Everywhere. However, I'd like to avoid that if there's an easier way.

Thanks in advance for any suggestions!

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Calculating "Portfolio Entries Today"

Postby fbertram » 03 Apr 2016

Your strategies could report to the money-management signal using pmm_set_my_named_num...

Cheers, Felix

Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Re: Calculating "Portfolio Entries Today"

Postby Xyzzy » 05 Apr 2016

Thanks Felix. Unfortunately, I don't think that will work for me -- my code itself (rather than the PMM system) needs to know the number of portfolio entries today for calculating certain limit prices.

My best option seems to be using All Data Everywhere. If anyone has a better suggestion, I'd certainly welcome it.

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Calculating "Portfolio Entries Today"

Postby fbertram » 05 Apr 2016

Xyzzy,

here is what I would do:

In the trading signal:

Code: Select all

variable:
PortfolioEntriesToday(0);
pmm_set_my_named_num("STRATEGY_ENTRIES", EntriesToday);
PortfolioEntriesToday = pmm_get_global_named_num("PORTFOLIO_ENTRIES");
And in the money-management signal:

Code: Select all

variable:
PortfolioEntriesToday(0);

PortfolioEntriesToday = 0;
for value1 = 1 to pmms_strategies_count begin
PortfolioEntriesToday += pmms_get_strategy_named_num(value1, "STRATEGY_ENTRIES");
end;
pmms_set_global_named_num("PORTFOLIO_ENTRIES", PortfolioEntriesToday);
Please note that I didn't test it. There might be a typo or other little flaw here, but you get the idea. Another problem you will need to solve is, that first all the trading signals are calculated and then the money-management signal. You will probably can't read the # of entries from the MM signal earlier than one day after it was calculated.


Hope this helps,
cheers

Felix


Return to “MultiCharts”