How to calculate the straight line when using the logarithmic scale?

How to calculate the straight line when using the logarithmic scale?

Using the LineArray function and plotting on the logarithmic scale I get the blue line,

How do I get the red line as a result ?

Plot( C, "Close", colorDefault, styleNoTitle | GetPriceStyle() ); 

bi = BarIndex();
llb = bi - LowestBars(Low);
hhb = bi - HighestBars(High);
ll = Lowest(Low);
hh = Highest(High);

//y = LineArray(LastValue(llb), log(LastValue(ll)), LastValue(hhb), log(LastValue(hh)));
y = LineArray(LastValue(llb), LastValue(ll), LastValue(hhb), LastValue(hh), 1);

Plot(y, "y", colorBlue);

Try this: ln(y) = a + bx where a = y intercept and b = slope of line

1 Like

You could replace your LineArray and Plot calls with:

GfxSetCoordsMode(1);
GfxMoveTo(LastValue(llb), LastValue(ll));
GfxLineTo(LastValue(hhb), LastValue(hh));
1 Like

well, this would draw the line as I expected,
but I would also like to have an array of y values.
What I am looking for is the formula of line when scale is logarithmic

I would like to find y in log scale, not log(y)

If, for example, ln(y) = 3, y = e^3

1 Like

See Knowledge Base:

1 Like

Here's another way to do it, with a little help from AI to supplement my rusty math skills:

Plot( C, "Close", colorDefault, styleNoTitle | GetPriceStyle() ); 

bi = BarIndex();
llb = bi - LowestBars(Low);
hhb = bi - HighestBars(High);
ll = Lowest(Low);
hh = Highest(High);

logHH = log(LastValue(hh));
logLL = log(LastValue(ll));
m = (logHH - logLL) / (LastValue(hhb) - LastValue(llb));
x = bi;
b = logLL - m * LastValue(llb);
yPrime = m * x + b;
y = exp(yPrime);

Plot(y, "y", colorRed);
3 Likes

Thank you all !!!!

1 Like