portfolio_currententries

Questions about MultiCharts and user contributed studies.
waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

portfolio_currententries

Postby waveslider » 17 Nov 2013

This reserved word is not working for me. I want a max. of 10 positions

I use the following:

Code: Select all

if portfolio_currententries<10 then begin
<<code>>
end;
Sticking a print command in at the end of each day (print(date," ",Portfolio_CurrentEntries);)
I routinely get 30+ entries.

PortfolioEntriesPriority is not working either - I have implemented it as Andrew suggested (cut/pasted his code), it does nothing.

I am using basic code, one signal on one day data, no multiple entries permitted.

Thanks

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: portfolio_currententries

Postby Andrew MultiCharts » 18 Nov 2013

Hello waveslider.

Would you be able to provide a piece of code demonstrating (simplified if you want) strategy logic that can be compiled? Including "prints" of course. Thanks.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: portfolio_currententries

Postby waveslider » 18 Nov 2013

When code is compiled as below, there will be more than 10 positions assumed. Daily bars are used. Max capital per position set to 10%.

Code: Select all

if Portfolio_CurrentEntries<10 then begin
if c>o then buy this bar;
end;

if c<o then sell this bar;

print(date," ",Portfolio_CurrentEntries);
When the sell statement is inside the begin...end statement(as below), the proper number of entries is maintained.

Code: Select all

if Portfolio_CurrentEntries<10 then begin
if c>o then buy this bar;
if c<o then sell this bar;
end;

print(date," ",Portfolio_CurrentEntries);
Obviously the sell statement needs to be outside the begin...end loop.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: portfolio_currententries

Postby Andrew MultiCharts » 19 Nov 2013

Waveslider, your code limits order generation only when the number of open positions exceeds 9. Let's assume you have 9 open positions. It checks the condition and see it is ok, then it generates, let's say, 10 more entries. They all will be executed at open of next bar.

If you don't want to have more then 10 open positions in Portfolio Backtester, you should check current Portfolio_CurrentEntries value, then limit the number of orders generated at this moment to make sure you will not send additional orders to end up with number of open positions > 10. Furthermore, you should use global variables to pass number of generated entry orders at current calculation of the script on symbol A to coming calculation of the script on symbol B in order to avoid the same problem (excessive orders).

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: portfolio_currententries

Postby waveslider » 19 Nov 2013

Furthermore, you should use global variables to pass number of generated entry orders at current calculation of the script on symbol A to coming calculation of the script on symbol B in order to avoid the same problem (excessive orders).
Thanks Andrew - would you please provide an example of how this would be done, I am not very comfortable using global variables. It was my understanding that global variables didn't work in backtesting.

I'm sure this will be a good reference for others who have a similar issue in the future. It seems logical that there would be some kind of key word that would limit further entries - like if portfolio_currententries = portfolio_maxentries then trade=false.

Furthermore - not having a limiting functionality means that entries are made when there is not enough cash/margin in the account to fund them. They should automatically be rejected if there is not enough cash/margin, shouldn't they?

Thanks

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: portfolio_currententries

Postby Andrew MultiCharts » 19 Nov 2013

Thanks Andrew - would you please provide an example of how this would be done, I am not very comfortable using global variables.
Unfortunately this goes beyond free level of support we provide in regards to scripting questions.
It was my understanding that global variables didn't work in backtesting.
Your understanding is correct. But due to the sequence of calculations in Portfolio Backtester, it is the exception, GV will work there.
I'm sure this will be a good reference for others who have a similar issue in the future. It seems logical that there would be some kind of key word that would limit further entries - like if portfolio_currententries = portfolio_maxentries then trade=false.
Please leave us such feature request.
Furthermore - not having a limiting functionality means that entries are made when there is not enough cash/margin in the account to fund them. They should automatically be rejected if there is not enough cash/margin, shouldn't they?
They should, but this is something that is limited by Portfolio Settings, not by your code in this case.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: portfolio_currententries

Postby waveslider » 19 Nov 2013

In this case, it doesn't matter what the portfolio settings are, more orders will be generated than there is cash in the account.

here is the feature request:
https://www.multicharts.com/pm/viewissu ... no=MC-1524

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: portfolio_currententries

Postby Andrew MultiCharts » 19 Nov 2013

In this case, it doesn't matter what the portfolio settings are, more orders will be generated than there is cash in the account.
If you believe the settings don't work in Portfolio Backtester, please provide me with the following set of files demonstrating the issue, i'd be glad to study the case:
  1. The portfolio workspace to reproduce the situation.
  2. Export of used symbol (with data) from QuoteManager in .qmd archive,
  3. The exported script with all dependent functions that applied on the workspace.
  4. Specify the bar number, its date and time, where the problem takes place.


Return to “MultiCharts”