Problem with Portfolio_OpenPositionProfit

Questions about MultiCharts and user contributed studies.
fltngpnt
Posts: 9
Joined: 14 Jun 2022
Has thanked: 2 times

Problem with Portfolio_OpenPositionProfit

Postby fltngpnt » 11 Feb 2023

I came up with what I thought was a simple signal to close a position when the open profit of the entire portfolio passes a certain level, but when I apply the signal to my portfolio strategy it never triggers during backtesting. It triggers fine when I use a different exit condition, so I'm guessing the problem is with the Portfolio_OpenPositionProfit function. Can it not be used in backtesting? Does it only return values in real-time trading? Is there a backtest-friendly alternative? TIA

Code: Select all

[IntrabarOrderGeneration = false] inputs: TP (100), SL (-100); condition1 = Portfolio_OpenPositionProfit crosses over TP or Portfolio_OpenPositionProfit crosses under SL; condition2 = marketposition > 0; condition3 = marketposition < 0; If condition1 and condition2 then Sell ("LX") next bar at market; If condition1 and condition3 then BuyToCover ("SX") next bar at market;

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Problem with Portfolio_OpenPositionProfit

Postby TJ » 11 Feb 2023


fltngpnt
Posts: 9
Joined: 14 Jun 2022
Has thanked: 2 times

Re: Problem with Portfolio_OpenPositionProfit

Postby fltngpnt » 11 Feb 2023

Thanks for your reply, but I’m not sure how it’s relevant to my question. TP is short for Take Profit, SL is short for Stop Loss.

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Problem with Portfolio_OpenPositionProfit

Postby rrams » 11 Feb 2023

fltngpnt, "crosses under" applies to a plottable number series. You should just use "<" or ">" instead. ...and check using a printout of the Portfolio_OpenPositionProfit at each step.

fltngpnt
Posts: 9
Joined: 14 Jun 2022
Has thanked: 2 times

Re: Problem with Portfolio_OpenPositionProfit

Postby fltngpnt » 11 Feb 2023

Thank you! That did the trick.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Problem with Portfolio_OpenPositionProfit

Postby ABC » 13 Feb 2023

fltngpnt,

some reserved words do not provide previous bar's values and this could cause your conditions not to become true either. You can check if this is the case for Portfolio_OpenPositionProfit and if you find this to be true assign the reserved word to a variable and use this variable within your conditions.

Regards,

ABC


Return to “MultiCharts”