How to code my own gain line

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);



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);

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