I am creating some indicators based on various combinations including moving average crossovers. Once I have an UP signal, how can I code the indicator to ignore more UP signals until there has been a DOWN signal?
Make a variable that store the last signal direction and test it before launching a new signal.
Nicolas thanks for your reply but I’m sorry I don’t understand how to do this.
I could show you directly into your code if you can share it with us.
I bump this thread since i want the same thing. For this current easy command i dont want it to give repeated signals when Lower Low and Lower Close repeats.
//defparam CALCULATEONLASTBARS=20
if on=1 then
stoch=Stochastic[12,3](close)
ema=average[10,1](close)
//
ll=low[1]<low[2]
lc=close[1]<close[2]
if ll and lc and stoch[2]>80 and close[2]>ema then
drawtext("LL LC",barindex[1],high[1]+range[1],SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])
endif
//hh=high[1]>high[2]
//hc=close[1]>close[2]
//hc2=high>high[1]
//
//if hh and hc and hc2 then
//drawtext("HH HC",barindex[1],low[1]-range[1],SansSerif,standard,12)coloured(50,255,50)
//drawarrowup(barindex[1],low[1])
//endif
endif
return
Thankful for help!
//Viktor
I tried this
//defparam CALCULATEONLASTBARS=20
if on=1 then
stoch=Stochastic[12,3](close)
ema=average[10,1](close)
//
ll=low[1]<low[2]
lc=close[1]<close[2]
if signal=0 and ll and lc and stoch[2]>80 and close[2]>ema then
drawtext("LL LC",barindex[1],high[1]+range[1],SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])
signal=1
else
signal=0
endif
//hh=high[1]>high[2]
//hc=close[1]>close[2]
//hc2=high>high[1]
//
//if hh and hc and hc2 then
//drawtext("HH HC",barindex[1],low[1]-range[1],SansSerif,standard,12)coloured(50,255,50)
//drawarrowup(barindex[1],low[1])
//endif
endif
return
and it gets rid of one repetition. How do i keep it/determine length?
i did this now and it works OK but if anyone has a better suggestion i all ears 🙂
//defparam CALCULATEONLASTBARS=20
if on=1 then
stoch=Stochastic[12,3](close)
ema=average[10,1](close)
atr=AverageTrueRange[10](close)
//
ll=low[1]<low[2]
lc=close[1]<close[2]
if signal=0 and signal[1]=0 and signal[2]=0 and signal[3]=0 and ll and lc and stoch[2]>80 and close[2]>ema then
drawtext("LL LC",barindex[1],high[1]+atr,SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])
signal=1
else
signal=0
endif
//hh=high[1]>high[2]
//hc=close[1]>close[2]
//hc2=high>high[1]
//
//if hh and hc and hc2 then
//drawtext("HH HC",barindex[1],low[1]-range[1],SansSerif,standard,12)coloured(50,255,50)
//drawarrowup(barindex[1],low[1])
//endif
endif
return
You could have saved the barindex of the first signal and then test if enough bars have passed since then to give a new signal.
Or store the first signal price into a variable and test if the new signal is different from the last saved one.
You mentioned that in your first reply above, but i dont know how to do that. Can you please provide a code example?
Thanks
Sorry @lebrinque, but sometimes between 2 topics, I take some rest 🙂 It was days off yesterday in France also!
This is the amended code:
stoch=Stochastic[12,3](close)
ema=average[10,1](close)
atr=AverageTrueRange[10](close)
//
ll=low[1]<low[2]
lc=close[1]<close[2]
if ll and lc and stoch[2]>80 and close[2]>ema and barindex-lastsignal>2 then
drawtext("LL LC",barindex[1],high[1]+atr,SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])
lastsignal=barindex[1]
endif
return
‘lastsignal’ variable is your new friend, take care of him 🙂
Also @nicolas the other topic i created “Command depending on prior command” as a spinoff from this one – hope it was OK to create a new thread for that.