user15088974
user15088974

Reputation: 47

strategy to catching high and low

I'm trying a strategy with rising and falling function where: if there were 3 consecutive lower low (falling) and current low is higher (rising) then BUY. if there were 3 consecutive higher low (rising) and current low is lower (falling) then SELL. But the AND condition never trigger. Can you point it out to my why?

//@version=4
study(title="RiseFall", overlay=true)

TrendPrd  = input (defval=3, title="Trend Period",  type=input.integer, minval=3, step=1)
ChangePrd = input (defval=1, title="Change Period", type=input.integer, minval=1, step=1)

Fall2Rise = falling(low, TrendPrd) and rising (low,ChangePrd)
Rise2Fall = rising (low, TrendPrd) and falling(low,ChangePrd)

plotshape(Fall2Rise, title="BUY",  style=shape.labelup,   location=location.belowbar, color=color.black, transp=0, text="BUY",  textcolor=color.white, size=size.tiny)
plotshape(Rise2Fall, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.black, transp=0, text="SELL", textcolor=color.white, size=size.tiny)

It should have worked here as captured. enter image description here

Upvotes: 1

Views: 121

Answers (1)

Starr Lucky
Starr Lucky

Reputation: 1951

Use plots to debug your conditions. Green line is when your rising and falling crossing each other. which is never happens:

//@version=4
study(title="RiseFall", overlay=false)

TrendPrd  = input (defval=3, title="Trend Period",  type=input.integer, minval=3, step=1)
ChangePrd = input (defval=1, title="Change Period", type=input.integer, minval=1, step=1)

Fall2Rise =  ( falling(low, TrendPrd) and rising (low,ChangePrd) )

// simplifying Fall2Rise:
plot ( falling(low, TrendPrd) ? 1 : 0 )
plot ( rising (low,ChangePrd) ? 1 : 0, color = color.red)

plot ( Fall2Rise ? 1 : 0 , color = color.green )

Upvotes: 1

Related Questions