Fibonacci Structure Engine

Category: Indicators By: Iván González Created: March 25, 2026, 2:29 PM
March 25, 2026, 2:29 PM
Indicators
0 Comments

A complete structure analysis indicator combining swing detection, BOS/CHoCH market structure, Fibonacci retracement levels with golden zone highlighting, engulfing pattern detection, and confluence-based Buy/Sell signals.

 

Description

 

The Fibonacci Structure Engine is an overlay indicator that identifies market structure in real time. It detects swing highs and lows filtered by ATR to reduce noise, classifies them as HH (Higher High), HL (Higher Low), LH (Lower High) or LL (Lower Low), and identifies structural breaks: BOS (Break of Structure) when the trend continues, and CHoCH (Change of Character) when the trend reverses.

 

Once a structural break occurs, the indicator anchors a Fibonacci retracement from the relevant swing range. The golden zone (0.500 to 0.786) and the target zone (-0.5 to -0.618 extension) are highlighted as shaded rectangles. Individual levels (0.236, 0.382, 0.500, 0.618, 0.786) can be toggled on or off.

 

Additionally, the indicator detects bullish and bearish engulfing candle patterns filtered by structural context (premium/discount zones and Fibonacci confluence). A weighted confluence scoring system evaluates how close price is to key Fibonacci and swing levels, and generates Buy/Sell signals when conditions align with the structural bias.

 

Key Features

 

  • ATR-filtered swing detection with configurable length and multiplier to adapt to any instrument and timeframe
  • Market structure labels (HH, HL, LH, LL) on confirmed pivot points with the last 10 swings visible on chart
  • BOS and CHoCH detection with horizontal break lines and labels at the midpoint of the structure
  • Dynamic Fibonacci retracement anchored to the active swing range, with trailing capability on live edges that locks once a pivot confirms
  • Golden zone box (0.500–0.786) and target zone box (-0.5 to -0.618) rendered as shaded rectangles
  • Selectable Fibonacci levels: 0.236, 0.382, 0.500, 0.618, 0.786, -0.5, and -0.618 (Target), each toggled independently
  • Engulfing pattern detection filtered by premium/discount context and confluence scoring
  • Weighted confluence scoring that evaluates proximity to Fibonacci and swing levels (golden zone levels weighted higher)
  • Buy/Sell signals with cooldown to prevent signal clustering during choppy price action
  • Simplified dashboard showing trend direction, active signal, confluence strength, premium/discount zone, and current Fib 0.618 level
  • Four boolean outputs (Buy Signal, Sell Signal, BOS, CHoCH) for configuring ProRealTime alerts

Settings

 

Main Settings

 

  • swingLen (default: 10) — Lookback period for pivot detection. Higher values detect larger swings with less noise. Recommended range: 8–20.
  • useATRFilt (default: 1) — Enables ATR-based filtering of minor swings. Set to 0 to disable.
  • atrMult (default: 0.5) — Minimum swing size as a multiple of ATR. Higher values keep only large swings. Recommended: 0.3–1.0.
  • cooldownBars (default: 5) — Minimum bars between consecutive Buy or Sell signals. Prevents signal clustering.

Fibonacci Levels

 

  • showFib (default: 1) — Master toggle for all Fibonacci levels and zones.
  • fibExtBars (default: 20) — Number of bars to extend Fibonacci lines to the right.
  • showFib236, showFib382, showFib500, showFib618, showFib786 — Toggle each Fibonacci retracement level individually. By default 0.236 is off, all others are on.
  • showFibTgt, showFibT50 — Toggle the Target (-0.618) and -0.5 extension levels. Both on by default.
  • confTol (default: 0.3) — Confluence tolerance as a multiple of ATR. Determines how close price must be to a Fibonacci level to count as confluence. Lower values = stricter. Recommended: 0.2–0.5.

Display Options

 

  • showStruct (default: 1) — Show or hide BOS/CHoCH structure lines and labels.
  • showSwings (default: 1) — Show or hide HH/HL/LH/LL swing labels.
  • showEngulf (default: 1) — Show or hide engulfing pattern markers.
  • showSignals (default: 0) — Show or hide Buy/Sell signal labels. Off by default to keep the chart clean.
  • showDash (default: 1) — Show or hide the simplified info panel in the top-right corner.

How It Works

 

Swing Detection

 

The indicator scans for pivot highs and lows using a configurable lookback window (swingLen). A bar is a pivot high if it equals the highest high over 2×swingLen+1 bars centered on it, and similarly for pivot lows. An ATR-based filter then eliminates minor swings: only pivots whose range from the previous opposite swing exceeds atrMult × ATR(14) are accepted. The last two confirmed swing highs and two swing lows are stored and compared to classify each new swing as HH, HL, LH, or LL.

Market Structure (BOS / CHoCH)

 

A bullish break occurs when price closes above the last swing high, and a bearish break when it closes below the last swing low. If the break continues the existing trend, it is labelled BOS (Break of Structure). If it reverses the trend, it is labelled CHoCH (Change of Character). A de-duplication mechanism ensures each swing level can only be broken once.

 

Fibonacci Retracement

 

On each structural break, the Fibonacci range is anchored between the active swing high and swing low. The edge in the direction of the break starts as a live trailing anchor that follows price if it extends further, then locks in place once a confirmed pivot appears. This provides an immediate Fibonacci reference from the moment of the break while refining the range as the move develops. The golden zone (0.500–0.786) and target zone (-0.5 to -0.618) are drawn as shaded rectangles, and individual levels are drawn as horizontal lines extending to the right.

 

Confluence Scoring

 

The indicator calculates a weighted confluence score based on how close price is to each Fibonacci level and the last swing levels. Weights are higher for the golden zone levels (0.618 weighs 2.5, 0.500 weighs 2.0) and lower for peripheral levels (0.236 weighs 1.0). Swing levels contribute 1.0 each. The score ranges from 0 to 100 and is classified as None, Weak, Moderate, or Strong. It is displayed in the dashboard and used to filter signals.

 

Engulfing Patterns

 

Bearish and bullish engulfing patterns are detected when the current candle body is larger than its EMA(14) average and fully engulfs the previous smaller candle. These patterns are only signalled if they occur in the appropriate structural context: bearish engulfing in premium zones or near Fibonacci confluence, bullish engulfing in discount zones or near Fibonacci confluence.

 

Buy/Sell Signals

 

Signals are generated when either a contextual engulfing pattern aligns with the structural bias and meets the confluence threshold, or when a CHoCH reversal occurs. A configurable cooldown (default: 5 bars) prevents signal clustering during choppy conditions.

 

Outputs

 

The indicator returns four boolean values that can be used to set up alerts in ProRealTime:

  • Buy Signal — 1 when a confirmed buy condition fires, 0 otherwise
  • Sell Signal — 1 when a confirmed sell condition fires, 0 otherwise
  • BOS — 1 when a Break of Structure is detected on the current bar
  • CHoCH — 1 when a Change of Character is detected on the current bar

ProBuilder Code

 

//----------------------------------------------------------
// PRC_FIBONACCI STRUCTURE ENGINE
// Original: WillyAlgoTrader (PineScript v6)
// version = 0
// 25.03.2026
// Iván González @ www.prorealcode.com
// Sharing ProRealTime knowledge
//----------------------------------------------------------
defparam drawonlastbaronly = true
//----------------------------------------------------------
// SETTINGS
//----------------------------------------------------------
// ── Main ──
//----------------------------------------------------------
swingLen = 10       // Swing Detection Length (3-50)
useATRFilt = 1      // ATR Swing Filter: 1=ON, 0=OFF
atrMult = 0.5       // ATR Filter Multiplier (0.1-3.0)
cooldownBars = 5    // Signal Cooldown in bars (1-50)
// ── Fibonacci Levels (1=Show, 0=Hide) ──
showFib = 1         // Master toggle Fibonacci
fibExtBars = 20     // Extension bars to the right (5-100)
showFib236 = 0      // 0.236 level
showFib382 = 1      // 0.382 level
showFib500 = 1      // 0.500 level
showFib618 = 1      // 0.618 level
showFib786 = 1      // 0.786 level
showFibTgt = 1      // Target (-0.618)
showFibT50 = 1      // -0.5 level
confTol = 0.3       // Confluence ATR Tolerance (0.05-1.0)
// ── Structure & Display (1=ON, 0=OFF) ──
showStruct = 1      // Show BOS / CHoCH
showSwings = 1      // Show Swing Labels (HH/HL/LH/LL)
showEngulf = 1      // Show Engulfing Signals
showSignals = 0     // Show Buy/Sell Signals
showDash = 1        // Show Dashboard
//----------------------------------------------------------
// INITIALIZATION
//----------------------------------------------------------
once swHigh1 = 0
once swHigh1X = -1
once swHigh2 = 0
once swHigh2X = -1
once swLow1 = 0
once swLow1X = -1
once swLow2 = 0
once swLow2X = -1

once structBias = 0
once lastBrkHigh = -1
once lastBrkLow = -1

once fibHigh = 0
once fibHighX = -1
once fibLow = 0
once fibLowX = -1
once fibHighLive = 0
once fibLowLive = 0

once barsSinceBuy = 999
once barsSinceSell = 999

// Buffer counters
once swLblCnt = 0
once bosCnt = 0
once engCnt = 0
once sigBuyCnt = 0
once sigSellCnt = 0

maxSwLbl = 10
maxBos = 5
maxEng = 5
maxSig = 3

//----------------------------------------------------------
// CORE CALCULATIONS
//----------------------------------------------------------
atrLen = 14
atrVal = averagetruerange[atrLen]
warmupBars = max(swingLen * 3, 50)
prdWin = 2 * swingLen + 1

//----------------------------------------------------------
// PIVOT DETECTION (ATR-filtered)
//----------------------------------------------------------
newSwHigh = 0
newSwLow = 0

if barindex >= prdWin then
   // ── Pivot High ──
   if high[swingLen] = highest[prdWin](high) then
      ph = high[swingLen]
      phx = barindex - swingLen
      if useATRFilt = 1 then
         minSzH = atrVal * atrMult
      else
         minSzH = 0
      endif
      if swLow1X = -1 then
         passH = 1
      else
         if ph - swLow1 >= minSzH then
            passH = 1
         else
            passH = 0
         endif
      endif
      if passH = 1 then
         swHigh2 = swHigh1
         swHigh2X = swHigh1X
         swHigh1 = ph
         swHigh1X = phx
         newSwHigh = 1
      endif
   endif
   // ── Pivot Low ──
   if low[swingLen] = lowest[prdWin](low) then
      pl = low[swingLen]
      plx = barindex - swingLen
      if useATRFilt = 1 then
         minSzL = atrVal * atrMult
      else
         minSzL = 0
      endif
      if swHigh1X = -1 then
         passL = 1
      else
         if swHigh1 - pl >= minSzL then
            passL = 1
         else
            passL = 0
         endif
      endif
      if passL = 1 then
         swLow2 = swLow1
         swLow2X = swLow1X
         swLow1 = pl
         swLow1X = plx
         newSwLow = 1
      endif
   endif
endif

//----------------------------------------------------------
// SWING LABEL CLASSIFICATION & BUFFER
//----------------------------------------------------------
// Swing highs: HH (type=1) or LH (type=3)
if newSwHigh = 1 and swHigh2X > -1 and barindex >= warmupBars then
   if swHigh1 > swHigh2 then
      swT = 1
   else
      swT = 3
   endif
   if swLblCnt < maxSwLbl then
      $swLblX[swLblCnt] = swHigh1X
      $swLblY[swLblCnt] = swHigh1
      $swLblT[swLblCnt] = swT
      swLblCnt = swLblCnt + 1
   else
      for si = 0 to maxSwLbl - 2 do
         $swLblX[si] = $swLblX[si + 1]
         $swLblY[si] = $swLblY[si + 1]
         $swLblT[si] = $swLblT[si + 1]
      next
      $swLblX[maxSwLbl - 1] = swHigh1X
      $swLblY[maxSwLbl - 1] = swHigh1
      $swLblT[maxSwLbl - 1] = swT
   endif
endif

// Swing lows: HL (type=2) or LL (type=4)
if newSwLow = 1 and swLow2X > -1 and barindex >= warmupBars then
   if swLow1 > swLow2 then
      swT = 2
   else
      swT = 4
   endif
   if swLblCnt < maxSwLbl then
      $swLblX[swLblCnt] = swLow1X
      $swLblY[swLblCnt] = swLow1
      $swLblT[swLblCnt] = swT
      swLblCnt = swLblCnt + 1
   else
      for si = 0 to maxSwLbl - 2 do
         $swLblX[si] = $swLblX[si + 1]
         $swLblY[si] = $swLblY[si + 1]
         $swLblT[si] = $swLblT[si + 1]
      next
      $swLblX[maxSwLbl - 1] = swLow1X
      $swLblY[maxSwLbl - 1] = swLow1
      $swLblT[maxSwLbl - 1] = swT
   endif
endif

//----------------------------------------------------------
// STRUCTURE DETECTION (BOS / CHoCH)
//----------------------------------------------------------
isBOS = 0
isCHoCH = 0
isBullBrk = 0
isBearBrk = 0

// ── Bullish break: close > swHigh1 ──
if swHigh1X > -1 and barindex >= warmupBars then
   if close > swHigh1 then
      brkNewH = 0
      if lastBrkHigh = -1 then
         brkNewH = 1
      elsif swHigh1 <> lastBrkHigh then
         brkNewH = 1
      endif
      if brkNewH = 1 then
         if structBias <= 0 then
            isCHoCH = 1
         else
            isBOS = 1
         endif
         structBias = 1
         isBullBrk = 1
         lastBrkHigh = swHigh1
      endif
   endif
endif

// ── Bearish break: close < swLow1 ──
if swLow1X > -1 and barindex >= warmupBars then
   if close < swLow1 then
      brkNewL = 0
      if lastBrkLow = -1 then
         brkNewL = 1
      elsif swLow1 <> lastBrkLow then
         brkNewL = 1
      endif
      if brkNewL = 1 then
         if structBias >= 0 then
            isCHoCH = 1
         else
            isBOS = 1
         endif
         structBias = -1
         isBearBrk = 1
         lastBrkLow = swLow1
      endif
   endif
endif

// ── Store BOS/CHoCH in buffer ──
if isBOS = 1 or isCHoCH = 1 then
   if isBullBrk = 1 then
      brkPrice = swHigh1
      brkStartX = swHigh1X
   else
      brkPrice = swLow1
      brkStartX = swLow1X
   endif
   brkEndX = barindex
   if isCHoCH = 1 then
      brkType = 2
   else
      brkType = 1
   endif
   if isBullBrk = 1 then
      brkDir = 1
   else
      brkDir = -1
   endif
   if bosCnt < maxBos then
      $bosStartX[bosCnt] = brkStartX
      $bosEndX[bosCnt] = brkEndX
      $bosPrice[bosCnt] = brkPrice
      $bosType[bosCnt] = brkType
      $bosDir[bosCnt] = brkDir
      bosCnt = bosCnt + 1
   else
      for si = 0 to maxBos - 2 do
         $bosStartX[si] = $bosStartX[si + 1]
         $bosEndX[si] = $bosEndX[si + 1]
         $bosPrice[si] = $bosPrice[si + 1]
         $bosType[si] = $bosType[si + 1]
         $bosDir[si] = $bosDir[si + 1]
      next
      $bosStartX[maxBos - 1] = brkStartX
      $bosEndX[maxBos - 1] = brkEndX
      $bosPrice[maxBos - 1] = brkPrice
      $bosType[maxBos - 1] = brkType
      $bosDir[maxBos - 1] = brkDir
   endif
endif

//----------------------------------------------------------
// FIBONACCI ANCHORS
//----------------------------------------------------------
// On bullish break: top = current high (live trail), bottom = swLow1 (locked)
if isBullBrk = 1 then
   fibHigh = high
   fibHighX = barindex
   fibLow = swLow1
   fibLowX = swLow1X
   fibHighLive = 1
   fibLowLive = 0
endif

// On bearish break: bottom = current low (live trail), top = swHigh1 (locked)
if isBearBrk = 1 then
   fibLow = low
   fibLowX = barindex
   fibHigh = swHigh1
   fibHighX = swHigh1X
   fibLowLive = 1
   fibHighLive = 0
endif

// Trail live edge as price extends
if isBullBrk = 0 and isBearBrk = 0 then
   if fibHighLive = 1 and fibHighX > -1 then
      if high > fibHigh then
         fibHigh = high
         fibHighX = barindex
      endif
   endif
   if fibLowLive = 1 and fibLowX > -1 then
      if low < fibLow then
         fibLow = low
         fibLowX = barindex
      endif
   endif
endif

// Lock live edge on confirmed pivot (not on break bar)
if isBullBrk = 0 and isBearBrk = 0 then
   if newSwHigh = 1 and fibHighLive = 1 and swHigh1X > -1 then
      fibHigh = swHigh1
      fibHighX = swHigh1X
      fibHighLive = 0
   endif
   if newSwLow = 1 and fibLowLive = 1 and swLow1X > -1 then
      fibLow = swLow1
      fibLowX = swLow1X
      fibLowLive = 0
   endif
   // Update locked anchors on new confirmed swings
   if newSwHigh = 1 and fibHighLive = 0 and fibHighX > -1 then
      if swHigh1 <> fibHigh then
         fibHigh = swHigh1
         fibHighX = swHigh1X
      endif
   endif
   if newSwLow = 1 and fibLowLive = 0 and fibLowX > -1 then
      if swLow1 <> fibLow then
         fibLow = swLow1
         fibLowX = swLow1X
      endif
   endif
endif

//----------------------------------------------------------
// FIBONACCI PRICE LEVELS
//----------------------------------------------------------
fibValid = 0
fib236 = 0
fib382 = 0
fib500 = 0
fib618 = 0
fib786 = 0
fibTgt50 = 0
fibTgt618 = 0

if fibHighX > -1 and fibLowX > -1 and fibHigh > fibLow then
   fibValid = 1
   fibRng = fibHigh - fibLow
   fib236 = fibHigh - fibRng * 0.236
   fib382 = fibHigh - fibRng * 0.382
   fib500 = fibHigh - fibRng * 0.500
   fib618 = fibHigh - fibRng * 0.618
   fib786 = fibHigh - fibRng * 0.786
   fibTgt50 = fibHigh + fibRng * 0.5
   fibTgt618 = fibHigh + fibRng * 0.618
endif

//----------------------------------------------------------
// PREMIUM / DISCOUNT
//----------------------------------------------------------
inPremium = 0
inDiscount = 0
if fibValid = 1 then
   if close > fib500 then
      inPremium = 1
   else
      inDiscount = 1
   endif
endif

//----------------------------------------------------------
// CONFLUENCE SCORING (weighted)
//----------------------------------------------------------
if atrVal > 0 then
   confDist = atrVal * confTol
else
   confDist = 0.001
endif

confWeight = 0.0
if fibValid = 1 then
   if showFib236 = 1 and abs(close - fib236) <= confDist then
      confWeight = confWeight + 1.0
   endif
   if abs(close - fib382) <= confDist then
      confWeight = confWeight + 1.5
   endif
   if abs(close - fib500) <= confDist then
      confWeight = confWeight + 2.0
   endif
   if abs(close - fib618) <= confDist then
      confWeight = confWeight + 2.5
   endif
   if abs(close - fib786) <= confDist then
      confWeight = confWeight + 1.5
   endif
endif
// Swing level confluence
if swHigh1X > -1 and abs(close - swHigh1) <= confDist then
   confWeight = confWeight + 1.0
endif
if swLow1X > -1 and abs(close - swLow1) <= confDist then
   confWeight = confWeight + 1.0
endif

confScore = min(confWeight * 10, 100)

//----------------------------------------------------------
// ENGULFING PATTERN DETECTION
//----------------------------------------------------------
bodySize = max(close, open) - min(close, open)
bodyAvg = average[14, 1](bodySize)

bearEngulf = 0
if close < open then
   if bodySize > bodyAvg then
      if close[1] > open[1] then
         if bodySize[1] < bodyAvg[1] then
            if close <= open[1] and open >= close[1] then
               if close < open[1] or open > close[1] then
                  bearEngulf = 1
               endif
            endif
         endif
      endif
   endif
endif

bullEngulf = 0
if close > open then
   if bodySize > bodyAvg then
      if close[1] < open[1] then
         if bodySize[1] < bodyAvg[1] then
            if close >= open[1] and open <= close[1] then
               if close > open[1] or open < close[1] then
                  bullEngulf = 1
               endif
            endif
         endif
      endif
   endif
endif

// Context filter: premium/discount or confluence
bearEngCtx = 0
if bearEngulf = 1 and barindex >= warmupBars then
   if inPremium = 1 or confWeight >= 1.5 then
      bearEngCtx = 1
   endif
endif

bullEngCtx = 0
if bullEngulf = 1 and barindex >= warmupBars then
   if inDiscount = 1 or confWeight >= 1.5 then
      bullEngCtx = 1
   endif
endif

// ── Store engulfing in buffer ──
if bearEngCtx = 1 then
   if engCnt < maxEng then
      $engX[engCnt] = barindex
      $engY[engCnt] = high
      $engDir[engCnt] = -1
      engCnt = engCnt + 1
   else
      for si = 0 to maxEng - 2 do
         $engX[si] = $engX[si + 1]
         $engY[si] = $engY[si + 1]
         $engDir[si] = $engDir[si + 1]
      next
      $engX[maxEng - 1] = barindex
      $engY[maxEng - 1] = high
      $engDir[maxEng - 1] = -1
   endif
endif

if bullEngCtx = 1 then
   if engCnt < maxEng then
      $engX[engCnt] = barindex
      $engY[engCnt] = low
      $engDir[engCnt] = 1
      engCnt = engCnt + 1
   else
      for si = 0 to maxEng - 2 do
         $engX[si] = $engX[si + 1]
         $engY[si] = $engY[si + 1]
         $engDir[si] = $engDir[si + 1]
      next
      $engX[maxEng - 1] = barindex
      $engY[maxEng - 1] = low
      $engDir[maxEng - 1] = 1
   endif
endif

//----------------------------------------------------------
// SIGNAL LOGIC (with cooldown)
//----------------------------------------------------------
barsSinceBuy = barsSinceBuy + 1
barsSinceSell = barsSinceSell + 1

buyRaw = 0
sellRaw = 0

// Buy: bullish engulfing + bias + confluence, OR bullish CHoCH
if bullEngCtx = 1 and structBias = 1 and confWeight >= 1.5 then
   buyRaw = 1
endif
if isCHoCH = 1 and isBullBrk = 1 then
   buyRaw = 1
endif

// Sell: bearish engulfing + bias + confluence, OR bearish CHoCH
if bearEngCtx = 1 and structBias = -1 and confWeight >= 1.5 then
   sellRaw = 1
endif
if isCHoCH = 1 and isBearBrk = 1 then
   sellRaw = 1
endif

// Apply cooldown
confBuy = 0
confSell = 0
if buyRaw = 1 and barsSinceBuy >= cooldownBars then
   confBuy = 1
   barsSinceBuy = 0
endif
if sellRaw = 1 and barsSinceSell >= cooldownBars then
   confSell = 1
   barsSinceSell = 0
endif

// ── Store signals in buffer ──
if confBuy = 1 then
   if sigBuyCnt < maxSig then
      $sigBuyX[sigBuyCnt] = barindex
      $sigBuyY[sigBuyCnt] = low
      sigBuyCnt = sigBuyCnt + 1
   else
      for si = 0 to maxSig - 2 do
         $sigBuyX[si] = $sigBuyX[si + 1]
         $sigBuyY[si] = $sigBuyY[si + 1]
      next
      $sigBuyX[maxSig - 1] = barindex
      $sigBuyY[maxSig - 1] = low
   endif
endif

if confSell = 1 then
   if sigSellCnt < maxSig then
      $sigSellX[sigSellCnt] = barindex
      $sigSellY[sigSellCnt] = high
      sigSellCnt = sigSellCnt + 1
   else
      for si = 0 to maxSig - 2 do
         $sigSellX[si] = $sigSellX[si + 1]
         $sigSellY[si] = $sigSellY[si + 1]
      next
      $sigSellX[maxSig - 1] = barindex
      $sigSellY[maxSig - 1] = high
   endif
endif

//----------------------------------------------------------
// DRAWING (all inside islastbarupdate)
//----------------------------------------------------------
if islastbarupdate then
   atrOff = atrVal * 0.3
   
   // ── SWING LABELS (HH/HL/LH/LL) ──
   if showSwings = 1 and swLblCnt > 0 then
      for i = 0 to swLblCnt - 1 do
         if $swLblT[i] = 1 then
            drawtext("HH", $swLblX[i], $swLblY[i] + atrOff) coloured(0, 230, 118)
         elsif $swLblT[i] = 2 then
            drawtext("HL", $swLblX[i], $swLblY[i] - atrOff) coloured(0, 230, 118)
         elsif $swLblT[i] = 3 then
            drawtext("LH", $swLblX[i], $swLblY[i] + atrOff) coloured(255, 82, 82)
         elsif $swLblT[i] = 4 then
            drawtext("LL", $swLblX[i], $swLblY[i] - atrOff) coloured(255, 82, 82)
         endif
      next
   endif
   
   // ── BOS / CHoCH LINES & LABELS ──
   if showStruct = 1 and bosCnt > 0 then
      for i = 0 to bosCnt - 1 do
         if $bosDir[i] = 1 then
            bR = 0
            bG = 230
            bB = 118
         else
            bR = 255
            bG = 82
            bB = 82
         endif
         drawsegment($bosStartX[i], $bosPrice[i], $bosEndX[i], $bosPrice[i]) coloured(bR, bG, bB) style(dottedline, 2)
         midX = round(($bosStartX[i] + $bosEndX[i]) / 2)
         if $bosDir[i] = 1 then
            lblOff = $bosPrice[i] + atrOff * 0.5
         else
            lblOff = $bosPrice[i] - atrOff * 0.5
         endif
         if $bosType[i] = 2 then
            drawtext("CHoCH", midX, lblOff) coloured(bR, bG, bB)
         else
            drawtext("BOS", midX, lblOff) coloured(bR, bG, bB)
         endif
      next
   endif
   
   // ── FIBONACCI LEVELS ──
   if showFib = 1 and fibValid = 1 then
      rightEdge = barindex + fibExtBars
      
      // Reference line (diagonal from swing low to swing high)
      drawsegment(fibLowX, fibLow, fibHighX, fibHigh) coloured(100, 150, 200) style(dottedline, 1)
      
      // Golden zone box (0.500 - 0.786)
      drawrectangle(barindex, fib500, rightEdge, fib786) coloured(255, 214, 0) fillcolor(255, 214, 0, 30)
      
      // Individual levels
      if showFib236 = 1 then
         drawsegment(barindex, fib236, rightEdge, fib236) coloured(100, 160, 220) style(dottedline, 1)
         drawtext("0.236", rightEdge, fib236) coloured(66, 165, 245)
      endif
      if showFib382 = 1 then
         drawsegment(barindex, fib382, rightEdge, fib382) coloured(80, 150, 220) style(dottedline, 1)
         drawtext("0.382", rightEdge, fib382) coloured(66, 165, 245)
      endif
      if showFib500 = 1 then
         drawsegment(barindex, fib500, rightEdge, fib500) coloured(66, 165, 245) style(dottedline, 2)
         drawtext("0.500", rightEdge, fib500) coloured(66, 165, 245)
      endif
      if showFib618 = 1 then
         drawsegment(barindex, fib618, rightEdge, fib618) coloured(66, 165, 245) style(line, 2)
         drawtext("0.618", rightEdge, fib618) coloured(66, 165, 245)
      endif
      if showFib786 = 1 then
         drawsegment(barindex, fib786, rightEdge, fib786) coloured(80, 150, 220) style(dottedline, 1)
         drawtext("0.786", rightEdge, fib786) coloured(66, 165, 245)
      endif
      
      // Target levels (above fibHigh)
      if showFibTgt = 1 then
         drawsegment(barindex, fibTgt618, rightEdge, fibTgt618) coloured(0, 230, 118) style(dottedline, 2)
         drawtext("Target", rightEdge, fibTgt618) coloured(0, 230, 118)
      endif
      if showFibT50 = 1 then
         drawsegment(barindex, fibTgt50, rightEdge, fibTgt50) coloured(0, 180, 100) style(dottedline, 1)
         drawtext("-0.5", rightEdge, fibTgt50) coloured(0, 180, 100)
      endif
      
      // Target zone box (-0.5 to -0.618)
      if showFibTgt = 1 or showFibT50 = 1 then
         drawrectangle(barindex, fibTgt50, rightEdge, fibTgt618) coloured(255, 214, 0) fillcolor(255, 214, 0, 30)
      endif
   endif
   
   // ── ENGULFING MARKERS ──
   if showEngulf = 1 and engCnt > 0 then
      for i = 0 to engCnt - 1 do
         if $engDir[i] = 1 then
            drawtext("▲", $engX[i], $engY[i] - atrOff) coloured(0, 230, 118)
         else
            drawtext("▼", $engX[i], $engY[i] + atrOff) coloured(255, 82, 82)
         endif
      next
   endif
   
   // ── BUY / SELL SIGNALS ──
   if showSignals = 1 then
      if sigBuyCnt > 0 then
         for i = 0 to sigBuyCnt - 1 do
            drawtext("BUY", $sigBuyX[i], $sigBuyY[i] - atrOff * 1.5) coloured(0, 230, 118)
         next
      endif
      if sigSellCnt > 0 then
         for i = 0 to sigSellCnt - 1 do
            drawtext("SELL", $sigSellX[i], $sigSellY[i] + atrOff * 1.5) coloured(255, 82, 82)
         next
      endif
   endif
   
   // ── DASHBOARD (simplified panel) ──
   if showDash = 1 then
      // Title
      drawtext("═ FibStructure ═", -200, -10) anchor(topright, xshift, yshift) coloured(200, 200, 200)
      
      // Trend
      if structBias > 0 then
         drawtext("Trend: Bullish", -200, -25) anchor(topright, xshift, yshift) coloured(0, 230, 118)
      elsif structBias < 0 then
         drawtext("Trend: Bearish", -200, -25) anchor(topright, xshift, yshift) coloured(255, 82, 82)
      else
         drawtext("Trend: Neutral", -200, -25) anchor(topright, xshift, yshift) coloured(150, 150, 150)
      endif
      
      // Signal
      if confBuy = 1 then
         drawtext("Signal: BUY", -200, -40) anchor(topright, xshift, yshift) coloured(0, 230, 118)
      elsif confSell = 1 then
         drawtext("Signal: SELL", -200, -40) anchor(topright, xshift, yshift) coloured(255, 82, 82)
      else
         drawtext("Signal: —", -200, -40) anchor(topright, xshift, yshift) coloured(150, 150, 150)
      endif
      
      // Confluence
      if confScore >= 60 then
         drawtext("Conf: Strong #confScore#", -200, -55) anchor(topright, xshift, yshift) coloured(0, 230, 118)
      elsif confScore >= 30 then
         drawtext("Conf: Moderate #confScore#", -200, -55) anchor(topright, xshift, yshift) coloured(255, 214, 0)
      elsif confScore > 0 then
         drawtext("Conf: Weak #confScore#", -200, -55) anchor(topright, xshift, yshift) coloured(200, 180, 80)
      else
         drawtext("Conf: None", -200, -55) anchor(topright, xshift, yshift) coloured(150, 150, 150)
      endif
      
      // Zone
      if inPremium = 1 then
         drawtext("Zone: Premium", -200, -70) anchor(topright, xshift, yshift) coloured(255, 82, 82)
      elsif inDiscount = 1 then
         drawtext("Zone: Discount", -200, -70) anchor(topright, xshift, yshift) coloured(0, 230, 118)
      else
         drawtext("Zone: —", -200, -70) anchor(topright, xshift, yshift) coloured(150, 150, 150)
      endif
      
      // Fib .618 value
      if fibValid = 1 then
         drawtext("Fib .618: #fib618#", -200, -85) anchor(topright, xshift, yshift) coloured(66, 165, 245)
      endif
   endif
endif
//----------------------------------------------------------
return

Download
Filename: PRC_FIBONACCI-STRUCTURE-ENGINE.itf
Downloads: 3
Iván González Master
Operating in the shadows, I hack problems one by one. My bio is currently encrypted by a complex algorithm. Decryption underway...
Author’s Profile

Comments

Logo Logo
Loading...