Hello everyone, I want to share a simple but effective code snippet I use to detect Fair Value Gaps (FVG). It highlights both Bullish (green) and Bearish (red) imbalances based on a standard 3-candle pattern. You can easily integrate this logic into your own strategies as a trend or entry filter. Here is the code:
// --- FAIR VALUE GAP (FVG) DETECTION ---
MinGap = 2 * pipsize
// 1. Bullish FVG
BullishFVG = (Low > High[2]) AND (Low - High[2] >= MinGap)
// 2. Bearish FVG
BearishFVG = (High < Low[2]) AND (Low[2] - High >= MinGap)
// --- VISUAL REPRESENTATION ---
IF BullishFVG THEN
DrawRectangle(barindex[2], High[2], barindex, Low) coloured(0,255,0,50) bordercolor(0,255,0,0)
ENDIF
IF BearishFVG THEN
DrawRectangle(barindex[2], Low[2], barindex, High) coloured(255,0,0,50) bordercolor(255,0,0,0)
ENDIF
RETURN
This is the core mathematical logic I use to filter imbalances in my automated systems. If you want to see how I trade these gaps fully automated on Micro Nasdaq (MNQ) and Micro Gold (MGC), you can test my complete strategy free for 30 days here: https://market.prorealcode.com/product/quantra-algorithmic-nasdaq-gold-trend-duo/