AlfyParticipant
Average
Good afternoon guys, i wonder if anyone can help. I am trying to colour my upper and lower Bollinger bands Green when the middle moving average is rising and Red when the middle Moving average is falling. Can someone help please? Ive copied the basic code for the Bollinger Bands themselves. Thanks for any help you can share!
Best regards
a=average [21] (close)
b=STD[21](close)
Bollup= BollingerUp[21](close)
Bolldn=BollingerDown[21](close)
Return Bollup,Bolldn,a
JSParticipant
Senior
LRS = LinearRegressionSlope[21](close)
If LRS > 0 then
Bullish = 1
Bearish = 0
R = 0
G = 255
B = 0
ElsIf LRS < 0 then
Bullish = 0
Bearish = 1
R = 255
G = 0
B = 0
Else
Bullish = 0
Bearish = 0
R = 0
G = 0
B = 255
EndIf
Avg = Average[21](close)
Bollup= BollingerUp[21](close)
Bolldn=BollingerDown[21](close)
Return Bollup Coloured(R,G,B) as "BollingerUp" ,Bolldn Coloured(R,G,B) as "BollingerDown",Avg Coloured(R,G,B) Style(DottedLine)
Hi
@Alfy
To determine the direction of the average, you can use the Linear Regression Slope.
JSParticipant
Senior
You may be thinking, what does linear regression have to do with a moving average?
Where the linear regression intersects with the moving average, that is the zero point of the linear regression slope…