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.
- the next candle must either Sweep the 1st Candle that was rejecting and then Expand
- 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:
- this is a valid and working example for a bearish 2 CR as it should be
- this is a valid and working example for a bearish 1 CR as it should be
- 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:
- this is an example where it should print a 1 CR Line and label but... nothing??
- this is an example where the 2CR gets drawn on one candle later than it should be??
- same here 2 CR is drawn on the false candle...
- 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)
log.*()functions instead. Labels will only tell you what happens at the end of the execution. You can place somelog.info()calls in between places and see what is going on step by step.