0

I wanted to make an indicator for my trading Group that detects and alerts a thing called " 2 Candle Rejection". its a concept used by a couple of traders to determine if a Fair Value gap will hold or not.

For simplicity:

You got a FVG -> you want to have one candle rejecting that FVG (mostly wicked into it) and close above ( for a bullish one ) or underneath (for a bearish one) then it counts as a rejection. OK so far... to be valid to trade you got 2 options now.

  1. the next candle must either Sweep the 1st Candle that was rejecting and then Expand
  2. or directly expand away from that gap.

If that's happening than you got either a one candle Rejection (1CR) or a 2 Candle Rejection (2 CR). so you can trade.

But, if any candle will close underneath either the gap, the 1st Candle that touched the Gap or the low of the 1st. candle (for a bullish example here) it will be invalidated.

I have a problem in getting rejection candles correctly detected.

Here are a few examples:

  1. this is a valid and working example for a bearish 2 CR as it should be
  2. this is a valid and working example for a bearish 1 CR as it should be
  3. this is a valid and working example for a failure of the 2 CR as it should be

And now we get to the part where examples are like the other ones but the indicator fails to print (and also alerts) in the correct way:

  1. this is an example where it should print a 1 CR Line and label but... nothing??
  2. this is an example where the 2CR gets drawn on one candle later than it should be??
  3. same here 2 CR is drawn on the false candle...
  4. another example... where the 2 CR is printed before it is even entering the Zone... i don't get it...

So I don't get the difference between the examples cause i am working with highs and lows mostly. just for invalidation are closes needed. can any one tell me the difference?

Here are the snippets of the 1 CR and the 2 CR that's whats most important for the areas where the problem should be created.

// 6 a) 1 CR State ──────────────────────────────────────────────────
var int state = 0 // 0 = nichts, 1 = 1 CR erkannt, 2 = 2 CR erkannt
// Linien-Enden dynamisch anpassen
if not na(lInner)
 line.set_x1(lInner, barStartInner)
 line.set_x1(lOuter, barStartOuter)
 line.set_x2(lInner, bar_index)
 line.set_x2(lOuter, bar_index)
// 1 CR-Bedingung: erste Berührung der Gap-Zone
if liveReady and state == 0 and priceInGap()
 cr1Level := a1Price
 cr1Line := line.new(barStartInner, cr1Level, bar_index, cr1Level,
 xloc.bar_index, extend.none, ColorCR, line.style_dotted, 2)
 lblCR1 := label.new(barStartInner,
 isBull ? low - offsetY() : high + offsetY(),
 "1CR", yloc = isBull ? yloc.belowbar : yloc.abovebar,
 style = label.style_label_center,
 color = color.new(color.white, 100), textcolor = colCR)
 // ✨ NEU – Candle A = Vorherige Kerze
 candleA_bar := bar_index
 candleAHigh := high
 candleALow := low
 alert("⚠️ " + timeframe.period + " FVG : 1 Candle Rejection erkannt!\n🟢 Entry Erlaubt, wenn 2. Candle Expansion Candle.", alert.freq_once_per_bar)
 state := 1
// 1 CR-Linie verlängern
if state == 1 and not na(cr1Line)
 line.set_x2(cr1Line, bar_index)

//─────────────────────────────────────────────────────────────
// 6 b) 2 CR State (nur erste Candle nach Candle A darf triggern)
//─────────────────────────────────────────────────────────────
isAfterCandleA = not na(candleA_bar) and bar_index > candleA_bar
isFirstValidBreak = false
if state == 1 and isAfterCandleA
 if isBull and low < candleALow
 isFirstValidBreak := true
 if not isBull and high > candleAHigh
 isFirstValidBreak := true
if isFirstValidBreak
 float cr2Level = isBull ? candleALow : candleAHigh
 cr2Line := line.new(candleA_bar, cr2Level, bar_index, cr2Level, xloc.bar_index, extend.none, ColorCR, line.style_dotted, 2)
 lblCR2 := label.new(candleA_bar, isBull ? cr2Level - offsetY() : cr2Level + offsetY(), "2CR", yloc = isBull ? yloc.belowbar : yloc.abovebar, style = label.style_label_center, color = color.new(color.white, 100), textcolor = colCR)
 candleBHigh := high
 candleBLow := low
 candleB_bar := bar_index
 state := 2
 alert("⚠️ " + timeframe.period + " FVG : 2 Candle Rejection erkannt!\n🟢 Entry Erlaubt, wenn 3. Candle Expansion Candle.\n🟢 Alignment TF Entry erlaubt\n->wenn Alignment TF FVG confirmed!", alert.freq_once_per_bar)
DarkBee
14.4k9 gold badges86 silver badges135 bronze badges
asked Jun 23, 2025 at 17:58
5
  • Why don't you debug it and see what is going on? Commented Jun 23, 2025 at 20:33
  • hey - thy for your comment :) eh... as i said i am relatively new to pine and not so much experienced with all the tools i can use. so idk how to debug this. i tried to set debug labels to see when it creates the rejections but it seems all fine. Commented Jun 24, 2025 at 8:49
  • You should use log.*() functions instead. Labels will only tell you what happens at the end of the execution. You can place some log.info() calls in between places and see what is going on step by step. Commented Jun 24, 2025 at 12:26
  • umm ok then i have to first figure out how that works idk about that. thy for the tipp i'll try that if i can figure out how. :) Commented Jun 24, 2025 at 17:54
  • @vitruvius so i've watched a couple of YT videos and let ChatGPT create some log.info commands for my "CR" functions but it isnt really helpful for me since its simply only putting out something in the log Tab, if there is a CR detected. but if it is, then it shows me the CR correctly. if not, even there has to be a CR.. ( what my problem is ) then the log doesnt show anything. so no errors or something were shown in the logs unfortunately. Commented Jun 26, 2025 at 7:36

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.