Page 1 of 1

Portfolio_NetProfit between two dates

Posted: Jun 29 2024
by Tibouss
Hello

I'm getting some trouble to add a condition in my strategy.

Actually i would like to add a condition on a portfolio strategy which trigger another condition after a certain date if my portfolio P&L is above certain amount.

I Don't know if we might use "Portfolio_NetProfit" only between a set of dates, for example between the first of january 2024 and today.

The dummy code of what i want to do is :

Code: Select all

if "Portfolio_NetProfit" between (1240101) and today is >= 1000 then...


Can someone help me to code it?

Many thanks in advance.

Re: Portfolio_NetProfit between two dates

Posted: Jul 01 2024
by ABC
Tibouss,

it depends a bit on whether you want to obtain the value since a specific date and the last bar on a chart or between two dates.
Either way you can start by saving the Portfolio_NetProfit in a variable based on your date requirement (for example once at a specific date or continuously while the date is less than the date in question) and deduct this from the Portfolio_NetProfit in your condition. In case you are looking for a defined range between two dates simply redo the process with a second variable that holds the Portfolio_NetProfit until the second date.

Regards,

ABC

Re: Portfolio_NetProfit between two dates

Posted: Jul 06 2024
by Tibouss
Many thanks ABC.

Actually i wanted to obtain the value since a specific date and the last bar on a chart.

I created an Input to define the beginnig of the calcul (1240101), then store the value of the P&L on the 1240102.

At the end the P&L is deducted with a simple substraction.

I guess there is a more elegant way to code it, but anyway it works as i expect :D

Code below :

Code: Select all

Inputs: Startdateforprofit(1240101); { Start date for MM profit } { Variables for P&L } Var: PL01012024 (0); Var: Startdateforprofit2(0); Var: calculpl(0); if Date = 1240102 then Startdateforprofit2 = NetProfit; if Date>Startdateforprofit then PL01012024 = NetProfit; calculpl = PL01012024 - Startdateforprofit2;

Re: Portfolio_NetProfit between two dates

Posted: Jul 08 2024
by ABC
Tibouss,

with pleasure. To account for situations where your Startdateforprofit date does not exist you might want to consider changing your expression to "if Date <= 1240102 then". Just keep in mind that in that case Startdateforprofit2 could hold values before the Startdateforprofit already.

Regards,

ABC

Re: Portfolio_NetProfit between two dates

Posted: Jul 13 2024
by Tibouss
Thank you ABC!
I was printing the "Startdateforprofit2" variable to make sure it exists.
Your tips make it more easy!