I'm using the following code for the Linear Regression but it change its color a bar late for...
Code: Select all
inputs:
Price( Close),
Length( 89),
Displace( 0),
UpColor( green),
DnColor (red),
PaintInBarLRCLine ("Yes");
variables:
LinReg( 0 ),Trend (0),Transition (0) ;
if Displace >= 0 or CurrentBar > AbsValue( Displace ) then
begin
LinReg = LinearRegValue( Price, Length, 0 ) ;
If LinReg > LinReg [1] then
Begin
If Trend = -1 then Transition = 1;
If PaintInBarLRCLine = "Yes" then Plot1[Displace]( LinReg, "LinReg", UpColor );
Trend = 1;
End
Else
Begin
If Trend = 1 then Transition = 1;
If PaintInBarLRCLine = "Yes" then Plot1 [Displace] ( LinReg, "LinReg",DnColor ) ;
Trend = -1;
End;
End;
Let's suppose we have an uptrend linear regression (LR) line yellow and then it is approching to switch direction and we came to the point where LR[4] is 12349,70, LR[3] is 12350,80 , LR[2] is 12350,68 and then LR[1] is 12350,49.
Ok so this is the situation that I actually see on my chart:
I have the UpColor between LR4 and LR3, // correct because LR4 12349,70 < LR3 12350,80
I have the UpColor between LR3 and LR2, // wrong because LR3 12350,80 > LR2 12350,68
I have the DownColor between LR2 and LR1, //correct because LR2 12350,68 > LR1 12350,49
So basically the indicator is switching color a bar late and I honestly can't find a way to change it!
... Also I would like to see the last piece of line to change color (if the condition are met) on every tick untill the bar end and its value is definitive so I know that I'm approching the switch...
How can I achive that?
HERE you have a grafic example of what I mean (There's a continuous error during the attachement upload now using Chrome and Images cannot be uploaded) so please visit the following link
Any help would be appreciated.
Thanks