logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Crossover521  
#1 Posted : Tuesday, December 8, 2020 9:45:33 AM(UTC)
Crossover521

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 11/13/2020(UTC)
Posts: 10

Was thanked: 3 time(s) in 3 post(s)

Hi, 

I am trying to make a custom profit line.

The way I am trying to go about it is this:

Code:
Buy :=... ;
​​​​​​​

Sell:=... ;

return:= ((C / ValueWhen(1,Buy=1,C))-1); ​​​​​​​

profitrate:= If(BarsSince(buy = 1) < BarsSince(sell =1) OR BarsSince(sell =1) = 0, return,0);

Buy and Sell are the buy and sell conditions.

Return is the % change of the security between the current day and the day that the buy condition was triggered.

Profitrate shows you the return only when you have an open position (when buy was triggered more recently than sell ,you  have an open position).

Plotting the profitrate will show me my return during an open position and also the return at the day of closing the position. My question is how I can use that to compound my hypothetical cash balance.

e.g. I start with 10000

Buy position is triggered. At the day of closing the position (I.e. BarsSince(sell =1) - 0 ) my return is 0.1 or 10% therefore my cash balance should be 10000 * (1 + 0.1) = 11000

After a month a new buy position is triggered and my profit rate when the position is closed is another 10%. Cash Balance should now be 11000 * (1 + 0.1) = 12100.

I am stuck on how I can make this work. I am thinking  that I can somehow use PREV but I am not sure exactly how to do it. Any help much appreciated.

Edit: Also, I don't really care about the cash balance per se. Being able to compound my profitrate would suffice as well. E.g. first trade yields 10%. Second one yields another 10%. Total return should be 21%

Edited by user Tuesday, December 8, 2020 9:51:28 AM(UTC)  | Reason: Not specified

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.