How to code my own gain line

Hello,
I'm looking to create a visual representation of my profit line, but I'm having difficulty with the formulation.
Could you help me identify where I am making a mistake?
Best regards,
PS: I know that I can plot the equity line using the _Portfolio_Equity formula, but I want to plot it differently, and to understand the error in my script...

Double_green=C>O AND Ref(C,-1)>Ref(O,-1);
Double_red=C<O AND Ref(C,-1)<Ref(O,-1);

Buy=Double_red;
Sell=Double_green;

Bought=Flip(Buy,Sell);

Line[0]=100;
for (i=1;i<BarCount;i++)
{
if (Bought[i]==1)
	Line[i]== Line[i-1]+Line[i-1]*((C[i]-C[i-1])/C[i-1]);
else (Line[i]==Line[i-1]);
}

Plot(Line, "Line", colorBlack, styleLine, Null,Null,Null,Null, width=-15); 

You have wrong coding there because you mix comparison with assignment!

Instead it should be

if (Bought[i]==1)
	Line[i] = Line[i-1]+Line[i-1]*((C[i]-C[i-1])/C[i-1]);
else Line[i] = Line[i-1];

But you do not need loping at all because to get same result you just need single array processig line:

Line = 100*CumProd(IIf(Bought,ROC(C, 1),0) / 100 + 1);
2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.