0
votes

I am trying to identify candle which crosses TC or BC of CPR but the code is not giving correct result. I can see the TC and BC values are correct but the candle which is suppose to cross the TC or BC is not shown. Any help appreciated

strategy("CPR Strategy",overlay=true)
//study("Simple label", "", true)

wLow = security(syminfo.tickerid, 'W', low)
wClose = security(syminfo.tickerid, 'W', close)
wHigh = security(syminfo.tickerid, 'W', high)
wPivot = (wHigh + wClose + wLow)/3
wBC = (wHigh + wLow)/2
wTC = (wPivot - wBC) + wPivot

if wTC < wBC
    wTC :=(wHigh + wLow)/2
    wBC := (wPivot - wBC) + wPivot

plot(wBC,"CPR BC",color=color.green)
plot(wTC,"CPR TC",color=color.orange)

if high >= wBC and close <= wBC  and open < close
    strategy.entry("Sell", strategy.short)
    
if high <= wTC and close >= wTC
    strategy.entry("SBuy", strategy.long)
1

1 Answers

0
votes

Check your buy condition. It seems it's never occurring so the strat enters a sell, then waits forever for the buy condition. It's a good idea to check conditions by coding in plotshapes for the same logic so you can confirm things more easily.

sell = high >= wBC and close <= wBC  and open < close
buy = high <= wTC and close >= wTC

plotshape(sell, location = location.abovebar, style = shape.triangledown, color = color.red, size = size.small)
plotshape(buy, location = location.belowbar, style = shape.triangleup, color = color.red, size = size.small)