Could anyone tell me if there is a way to show or hide an indicator based on conditions relating specifically to the current candle only?
e.g.
If low<EMAx and close>EMAx then display EMAx.
I did try a custom EMA indicator but the the EMA only displayed on each candle in the past which met the criteria rather than just plotting the EMA on the chart.
Thanks.
Try this one (not tested):
MyEma = average[20,1](close)
t = 0 //transparency = invisible
If low < MyEma and close > MyEma then
t = 255
Endif
Return MyEma coloured(0,255,0,t) as “MyEma”
it takes advantage of the optional 4th COLOUR parameter, transparency (0-255), to make ema visible only when conditions are met.
Impressive Wizardry! 🙂
Link to above added as Log 293 here …
Snippet Link Library
Hi,
Unfortunately this is still only displaying the MA on candles which meet the criteria.
Isn’t that what you meant with “If low<EMAx and close>EMAx then display EMAx”?
Sorry, I didn’t make it clear.
I want to be able to display MA[x] on the whole chart but only if the last day’s candle meets the requirements.
So if today meets the conditions then MA[x] is displayed on the whole chart.
Hope that makes sense!
There’s no instruction to achieve that, so it must be coded.
I’ll make it asap.
Bob’s your uncle:
DEFPARAM DrawOnLastBarOnly = True
Periods = 20 //Ema periods
LookBack = 200 //plot Ema on the last 200 bars
MyEma = average[Periods,1](close)
If low < MyEma and close > MyEma then
FOR i = (LookBack - 1) DownTo 0
j = i + 1
DrawSegment(BarIndex[j],MyEma[j],BarIndex[i],MyEma[i]) coloured(0,255,0,255) style(Line,3)
NEXT
Endif
Return
Line 2 are the Ema periods and Line 3 are the number of bars you want the Ema to be plotted when conditions are met.
That’s amazing, thank you!
Works like a charm.