Hi there,
I’m trying to write script where it checks if the MA line color changes from one bar to the next. Is there a property or method to get the color of the MA line e.g. green for bullish and red for bearish?
Thanks for any help!
k
There you go:
MA = average[20,0](close)
BullMA = MA > MA[1]
BearMA = MA < MA[1]
MAchange = (BullMA and BearMA[1]) or (BullMA[1] and BearMA)
lines 2 and 3 retain the trend of the MA, while line 4 returns any change in direction (colour).
Thank you @robertogozzi!
Something I don’t understand as I am new to this scriping language (though I have experience with JavaScript and C#)
BearMA[1]
Shouldn’t the above contain only a true or false value? How can you use it like an array?
JSParticipant
Senior
MySma = average[20,0](close)
Rising = MySma > MySma[1] AND MySma[1] < MySma[2]
Falling = MySma < MySma[1] AND MySma[1] > MySma[2]
if rising then
r = 0
g = 255
elsif falling then
r = 255
g = 0
endif
return mysma coloured(r,g,0)