Command depending on prior command

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #51270 quote
    margincallcat
    Participant
    Average

    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

    #51271 quote
    margincallcat
    Participant
    Average

    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"
    
    EURUSD-4-hours.png EURUSD-4-hours.png
    #51310 quote
    Nicolas
    Keymaster
    Legend

    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.

    margincallcat thanked this post
    #51313 quote
    margincallcat
    Participant
    Average

    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?

    #51332 quote
    margincallcat
    Participant
    Average
    //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

    #51334 quote
    margincallcat
    Participant
    Average
    //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 😀

    #51344 quote
    Nicolas
    Keymaster
    Legend

    “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).

    #51345 quote
    margincallcat
    Participant
    Average

    I understand that 🙂 But without me adding the “once” command nothing happened – that was my questions.

     

    Anyway – many many thanks! Really appreciate it!!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Command depending on prior command


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by margincallcat
8 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/02/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...