Command depending on prior command
Forums › ProRealTime English forum › ProBuilder support › Command depending on prior command
- This topic has 7 replies, 2 voices, and was last updated 7 years ago by margincallcat.
-
-
11/02/2017 at 10:47 AM #51270
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:
123456789101112131415161718192021222324252627282930313233343536373839//defparam CALCULATEONLASTBARS=20if 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]=0realbody=abs(open-close)//averagebody=average[3](realboody)body=realbody[1]>range[1]/4emaneg= 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 signalchaindrawtext("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=1ll=1elsif ll[1]=1 and body and hhhc and emapos then //and signalchaindrawtext("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=0hh=1endifendifreturn 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
11/02/2017 at 10:50 AM #51271This is without hh=1 and ll=1 conditions:
123456789101112131415161718192021222324252627282930313233343536373839//defparam CALCULATEONLASTBARS=20if 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]=0realbody=abs(open-close)//averagebody=average[3](realboody)body=realbody[1]>range[1]/4emaneg= 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 signalchaindrawtext("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=1elsif body and hhhc and emapos then //and signalchaindrawtext("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=0endifendifreturn ema as "ema"11/02/2017 at 1:53 PM #51310Each 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.
1 user thanked author for this post.
11/02/2017 at 2:05 PM #51313Each 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?
11/02/2017 at 3:50 PM #513321234567891011121314151617181920212223242526272829303132333435363738394041//defparam CALCULATEONLASTBARS=20if on=1 then//stoch=Stochastic[12,3](close)atr=AverageTrueRange[10](close)[1]ema=dema[10](close)emadist=10signalchain=barindex-lastsignal>5lllc=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]>averagebodyemaneg= 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 thendrawtext("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=1lastsignal=barindex[1]signal=1elsif body and hhhc and emapos and signalchain and signal[1]=1 then//and signalchaindrawtext("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=0lastsignal=barindex[1]signal=-1endifendifreturn ema as "ema"doesnt work
11/02/2017 at 4:01 PM #51334123456789101112131415161718192021222324252627282930313233343536373839404142//defparam CALCULATEONLASTBARS=20if on=1 then//stoch=Stochastic[12,3](close)atr=AverageTrueRange[10](close)[1]ema=dema[10](close)//emadist=10signalchain=barindex-lastsignal>2lllc=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=1if signal[1]=-1 and body and lllc and signalchain then //and emanegdrawtext("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=1lastsignal=barindex[1]signal=1elsif signal[1]=1 and body and hhhc and signalchain then //and emapos//and signalchaindrawtext("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=0lastsignal=barindex[1]signal=-1endifendifreturn 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 😀
11/02/2017 at 5:23 PM #5134411/02/2017 at 5:24 PM #51345I understand that 🙂 But without me adding the “once” command nothing happened – that was my questions.
Anyway – many many thanks! Really appreciate it!!
-
AuthorPosts
Find exclusive trading pro-tools on