0

I am trying to figure out how to catch a bounce with specific zones. Looking at how I would code when price is above a zone for a certain period (but this period would be based on number of candlesticks opposed to time), then falls into the zone.

Anyone know how to do this?

All the help would be appreciated. Thanks!

I've tried looking into barstate but I am truly lost.

1 Answers1

0

You need a var to count the number of bars and some bool flags to see where you are in relation with the zone.

var cnt = 0
bingo = false

is_above_zone = close > zone_top
is_fall_into_zone = ta.crossunder(close, zone_top)

if ((cnt > your_limit) and is_fall_into_zone)
    bingo := true

cnt := is_above_zone ? cnt + 1 : 0  // Increment the counter if you are above the zone. Set it to 0 otherwise
vitruvius
  • 15,740
  • 3
  • 16
  • 26