I’m trying to code an indicator where the width depends on a condition. As a simply example use a pair of moving averages, e.g. MA20 and MA200.
– if MA20 >MA200, I want the width of MA20 to be 2,
– if MA20 < MA200, I want the width of MA20 to be 1.
Problems:
– RETURN MA20 COLOURED (255,0,0) style(line, 2) only accepts numbers, not code variables (e.g. style(line, x))
I thought of a workaround of plotting an indicator 2x, once with width 1 and once with width 2 (if a condition is met with width 2, otherwise invisible),
– but the transparency alpha in “colored by (r,g,b,alpha)” does not allow two different values.
Any idea how this could be fixed?
Thank you.
Hello,
ma20a=Average[20](close)// ma20 for width=1
ma20b=Average[20](close)// ma20 for width=2
ma200=Average[200](close)
if ma20b>ma200 then // make visible case width=2
alpha=255
else // make invisible case width=1
alpha=0
endif
return ma20a, ma20b coloured(0,0,0,alpha) style(line,2), ma200