awilson
November 26, 2024, 5:54pm
1
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);
colion
November 26, 2024, 7:02pm
2
Try this: ln(y) = a + bx where a = y intercept and b = slope of line
1 Like
mradtke
November 26, 2024, 7:03pm
3
You could replace your LineArray and Plot calls with:
GfxSetCoordsMode(1);
GfxMoveTo(LastValue(llb), LastValue(ll));
GfxLineTo(LastValue(hhb), LastValue(hh));
1 Like
awilson
November 26, 2024, 7:21pm
4
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
awilson
November 26, 2024, 7:25pm
5
I would like to find y in log scale, not log(y)
colion
November 26, 2024, 7:33pm
6
If, for example, ln(y) = 3, y = e^3
1 Like
mradtke
November 26, 2024, 8:05pm
8
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