positionprofit and portfolio backtester

Questions about MultiCharts and user contributed studies.
Phenydor
Posts: 8
Joined: 19 Jul 2016
Has thanked: 1 time

positionprofit and portfolio backtester

Postby Phenydor » 05 Mar 2017

Hi,

Does the positionprofit function work when using the portfolio backtester. I'm trying this test strategy below:

Code: Select all

if barnumber = 1 then buy next bar at market;
if barnumber = 10 then sell next bar at market;

print( "PositionProfit = ", positionprofit, " OpenPositionProfit = ", openpositionprofit, " BarNumber = ", barnumber );
When I run this, I can see openpositionprofit is showing values from bars 1 through 10. However, positionprofit is always being output as 0.

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: positionprofit and portfolio backtester

Postby Angelina MultiСharts » 07 Mar 2017

Hello Phenydor,

We are analyzing this case. I will get back to you with the answer.

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: positionprofit and portfolio backtester

Postby Angelina MultiСharts » 10 Mar 2017

Hello Phenydor,

Positionprofit returns total realized profit or loss for the specified closed position. When you do not specify PosBack value, it looks at the current position by default, therefore returning the value for the current position.
As current position is always open and your script doesn't produce partial fills, positionprofit will always return 0.

Phenydor
Posts: 8
Joined: 19 Jul 2016
Has thanked: 1 time

Re: positionprofit and portfolio backtester

Postby Phenydor » 10 Mar 2017

Hello Phenydor,

Positionprofit returns total realized profit or loss for the specified closed position. When you do not specify PosBack value, it looks at the current position by default, therefore returning the value for the current position.
Ahh gotcha ... I didn't realize the positionprofit only returns realized profits and not unrealized profits (I suppose that's what gives openpositionprofit a purpose :P)

johnnykf88
Posts: 9
Joined: 07 Mar 2017
Has thanked: 2 times
Been thanked: 1 time

Re: positionprofit and portfolio backtester

Postby johnnykf88 » 29 Aug 2017

Positionprofit returns total realized profit or loss for the specified closed position. When you do not specify PosBack value, it looks at the current position by default, therefore returning the value for the current position.
As current position is always open and your script doesn't produce partial fills, positionprofit will always return 0.
Thanks Angelina :) , your explanation is much clearer than that in the wiki https://www.multicharts.com/trading-sof ... tionProfit where the examples doesn't help to identify its difference from openpositionprofit.

So could you please tell what's the difference between positionprofit and positionprofit_checked keywords?
i did try these 2 in my script for checking the profit of the current position, they both showed '0' while openpositionprofit showed the unrealized profit in the current position.

Thanks.

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

Re: positionprofit and portfolio backtester

Postby Henry MultiСharts » 31 Aug 2017

So could you please tell what's the difference between positionprofit and positionprofit_checked keywords?
These commands work with the Realized PnL only, so you need to have at least a partially filled order in the current position for it to return any value. The only difference is the following: If PosBack value is greater that the real number of previously opened positions, PositionProfit_Checked will generate an error.
i did try these 2 in my script for checking the profit of the current position, they both showed '0' while openpositionprofit showed the unrealized profit in the current position.
That's expected. OpenPositionProfit is specifically designed to show the unrealized profit for the current position, while positionprofit and positionprofit_checked work with the realized PnL.


Return to “MultiCharts”