Hello!
I am coding a Higher High Higher Close + Lower Low Lower Close indicator which tells me when some conditions are met.
I want to tell the indicator only to give a HHHC if the last one was LLLC and vice versa.
This is the code so far:
//defparam CALCULATEONLASTBARS=20
if on=1 then
//stoch=Stochastic[12,3](close)
atr=AverageTrueRange[10](close)[1]
ema=dema[20](close)
//signalchain=signal=0 and signal[1]=0 and signal[2]=0 and signal[3]=0
realbody=abs(open-close)
//averagebody=average[3](realboody)
body=realbody[1]>range[1]/4
emaneg= ema[2]>ema[10] and low[1]<ema[1] and open[2]>ema[2]
emapos=ema[2]<ema[10] and high[1]>ema[1] and open[2]<ema[2]
lllc=low[1]<low[2] and close[1]<close[2]
hhhc=high[1]>high[2] and close[1]>close[2]
if hh[1]=1 and body and lllc and emaneg then // and signalchain
drawtext("LL LC",barindex[1],high[1]+atr,SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])coloured(255,50,50,150)
//signal=1
ll=1
elsif ll[1]=1 and body and hhhc and emapos then //and signalchain
drawtext("HH HC",barindex[1],low[1]-atr,SansSerif,standard,12)coloured(0,200,0)
drawarrowup(barindex[1],low[1])coloured(0,200,0,150)
//signal=1
//else
//signal=0
hh=1
endif
endif
return ema as "ema"
I have tried giving the different conditions variables as hh=1 and ll=1 and test if condtions are met but what happens is all my drawings disapear so i guess ive done something wrong.
Please help!
/Viktor
This is without hh=1 and ll=1 conditions:
//defparam CALCULATEONLASTBARS=20
if on=1 then
//stoch=Stochastic[12,3](close)
atr=AverageTrueRange[10](close)[1]
ema=dema[20](close)
//signalchain=signal=0 and signal[1]=0 and signal[2]=0 and signal[3]=0
realbody=abs(open-close)
//averagebody=average[3](realboody)
body=realbody[1]>range[1]/4
emaneg= ema[2]>ema[10] and low[1]<ema[1] and open[2]>ema[2]
emapos=ema[2]<ema[10] and high[1]>ema[1] and open[2]<ema[2]
lllc=low[1]<low[2] and close[1]<close[2]
hhhc=high[1]>high[2] and close[1]>close[2]
if body and lllc and emaneg then // and signalchain
drawtext("LL LC",barindex[1],high[1]+atr,SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])coloured(255,50,50,150)
//signal=1
elsif body and hhhc and emapos then //and signalchain
drawtext("HH HC",barindex[1],low[1]-atr,SansSerif,standard,12)coloured(0,200,0)
drawarrowup(barindex[1],low[1])coloured(0,200,0,150)
//signal=1
//else
//signal=0
endif
endif
return ema as "ema"
Each time you find a new lllc give ‘signal’ variable a -1 value and each time you find a new hhhc signal give ‘signal’ variable a 1 value. Test this variable accordingly before giving a new signal.
Each time you find a new lllc give ‘signal’ variable a -1 value and each time you find a new hhhc signal give ‘signal’ variable a 1 value. Test this variable accordingly before giving a new signal.
Thank you! So for lllc to be detected it should be “if signal[1]=1 then”? And vice versa?
//defparam CALCULATEONLASTBARS=20
if on=1 then
//stoch=Stochastic[12,3](close)
atr=AverageTrueRange[10](close)[1]
ema=dema[10](close)
emadist=10
signalchain=barindex-lastsignal>5
lllc=low[1]<low[2] and close[1]<close[2]
hhhc=high[1]>high[2] and close[1]>close[2]
realbody=abs(open-close)
//averagebody=average[3](realbody)
body=realbody[1]>range[1]/4 and realbody[1]>realbody[2] // realbody[1]>averagebody
emaneg= ema[2]>ema[emadist] //and low[1]<ema[1] and high[1]>ema[1] and open[2]>ema[2]
emapos=ema[2]<ema[emadist] //and high[1]>ema[1] and low[1]<ema[1] and open[2]<ema[2]
if body and lllc and emaneg and signalchain and signal[1]=-1 then
drawtext("LL LC",barindex[1],high[1]+atr,SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])coloured(255,50,50,150)
//signal=1
lastsignal=barindex[1]
signal=1
elsif body and hhhc and emapos and signalchain and signal[1]=1 then
//and signalchain
drawtext("HH HC",barindex[1],low[1]-atr,SansSerif,standard,12)coloured(0,200,0)
drawarrowup(barindex[1],low[1])coloured(0,200,0,150)
//signal=1
//else
//signal=0
lastsignal=barindex[1]
signal=-1
endif
endif
return ema as "ema"
doesnt work
//defparam CALCULATEONLASTBARS=20
if on=1 then
//stoch=Stochastic[12,3](close)
atr=AverageTrueRange[10](close)[1]
ema=dema[10](close)
//emadist=10
signalchain=barindex-lastsignal>2
lllc=low[1]<low[2] and close[1]<close[2]
hhhc=high[1]>high[2] and close[1]>close[2]
realbody=abs(open-close)
//averagebody=average[3](realbody)
body=realbody[1]>range[1]/4 and realbody[1]>realbody[2] // realbody[1]>averagebody
//emaneg= ema[2]>ema[emadist] //and low[1]<ema[1] and high[1]>ema[1] and open[2]>ema[2]
//emapos=ema[2]<ema[emadist] //and high[1]>ema[1] and low[1]<ema[1] and open[2]<ema[2]
once signal=1
if signal[1]=-1 and body and lllc and signalchain then //and emaneg
drawtext("LL LC",barindex[1],high[1]+atr,SansSerif,standard,12)coloured(255,50,50)
drawarrowdown(barindex[1],high[1])coloured(255,50,50,150)
//signal=1
lastsignal=barindex[1]
signal=1
elsif signal[1]=1 and body and hhhc and signalchain then //and emapos
//and signalchain
drawtext("HH HC",barindex[1],low[1]-atr,SansSerif,standard,12)coloured(0,200,0)
drawarrowup(barindex[1],low[1])coloured(0,200,0,150)
//signal=1
//else
//signal=0
lastsignal=barindex[1]
signal=-1
endif
endif
return ema as "ema"
OK so i added “once signal=1” and now it seems to work fine. Was that correct? I dont quite understand the logic behind this command 😀
“signal” is just a dummy variable to tell your program what was the last thing you plotted on your chart (an arrow up or an arrow down).
I understand that 🙂 But without me adding the “once” command nothing happened – that was my questions.
Anyway – many many thanks! Really appreciate it!!