Iván González

Auto Fibonacci levels

Category: Indicators By: Iván González Created: November 27, 2026, 1:00 PM
November 27, 2026, 1:00 PM
Indicators
0 Comments
Auto Fibonacci levels

Introduction

 

Fibonacci retracements are usually drawn by hand between a swing high and a swing low, and redrawn every time the market makes a new extreme. AutoFib Kriptoborsa removes that chore: it builds the retracement automatically from the highest high and the lowest low of the last N bars, so the levels move with the market.

On top of the channel it prints BUY and SELL signals when the close crosses the middle levels, and it lets you filter those signals with four classic conditions: the trend of a 50-period EMA, volume, a SuperTrend and the RSI. The background then takes the colour of the last signal, so the current bias is visible at a glance.

Theory Behind the Indicator

 

The channel. Over the last periodLength bars (20 by default) the indicator takes the highest high (level 100) and the lowest low (level 0) and places the Fibonacci levels between them: 78.6, 61.8, 50, 38.2 and 23.6. Each band between two levels is shaded, from red at the top through orange, yellow and teal to green at the bottom.

Raw signals.

  • BUY: the close crosses above the 38.2 level or above the 50 level.
  • SELL: the close crosses below the 61.8 level or below the 50 level.

Filters. A raw signal is only printed if every active filter agrees:

  • EMA filter: a buy needs the close above the 50-period EMA, a sell needs it below.
  • Volume filter: volume must be above its 20-bar average.
  • SuperTrend filter (factor 3, ATR 10): a buy needs the SuperTrend in an uptrend, a sell in a downtrend.
  • RSI filter: no buy while the RSI is above the overbought level, no sell while it is below the oversold level.

Background. After a BUY the background turns light green and stays green until the next SELL, which turns it light red.

Key Features at a Glance

 

  • Fibonacci retracement of the last N bars, recalculated on every bar.
  • Six shaded zones between the levels.
  • BUY and SELL labels on crosses of the 38.2, 50 and 61.8 levels.
  • Four switchable filters: EMA 50, volume, SuperTrend and RSI.
  • EMA 50 and SuperTrend plotted on the chart, the SuperTrend coloured by its direction.
  • Background coloured by the last signal.

How to Read the Indicator

 

  • Price in the lower zones (green): price is near the bottom of its recent range. A cross back above the 38.2 or the 50 level, with the filters in agreement, prints BUY.
  • Price in the upper zones (red and orange): price is near the top of its recent range. A cross back below the 61.8 or the 50 level prints SELL.
  • SuperTrend colour: green below price in an uptrend, red above price in a downtrend.
  • Background: the side of the last signal. It is a bias, not a position: it does not change until an opposite signal appears.

Practical Applications

 

  • Pullback entries in a trend: with the EMA and SuperTrend filters on, buys only appear above the EMA and with the SuperTrend up, so they mark recoveries from the lower half of the channel inside an uptrend.
  • Range trading: switch off the EMA and SuperTrend filters to get every reclaim of the middle levels.
  • Context for other setups: the shaded zones show at a glance whether price sits in the upper or lower part of its recent range.

Note: on instruments without volume data the volume filter can never be satisfied. Set useVolFilter = 0 there.

Indicator Configuration

 

  • periodLength (default 20): bars used for the highest high and lowest low of the channel.
  • useEmaFilter (default 1): 1 = buy only above the EMA 50, sell only below it.
  • useVolFilter (default 1): 1 = signals only when volume is above its 20-bar average.
  • useSuperTrend (default 1): 1 = signals only in the direction of the SuperTrend (3, 10).
  • useRsiFilter (default 1): 1 = no buys when the RSI is overbought, no sells when it is oversold.
  • rsiLength (default 14), rsiOverbought (default 70), rsiOversold (default 30): RSI settings for the filter.
  • maxLabels (default 500): how many of the most recent BUY and SELL labels are drawn.

The Code

 

//---------------------------------------------------------------
// PRC_AutoFib Kriptoborsa
// version = 0
// 27.11.2026
// Iván González @ www.prorealcode.com
// Author: kriptoborsatv
// Sharing ProRealTime knowledge
//--------------------------------------------------------------------//
// Fibonacci channel of the last N bars (highest high to lowest low) with
// BUY / SELL signals when the close crosses the middle levels, filtered by
// EMA 50, volume, SuperTrend (3, 10) and RSI.
//--------------------------------------------------------------------//
defparam drawonlastbaronly = true

// ---------------- parameters ----------------
periodLength = 20      // channel period (bars)
useEmaFilter = 1       // 1 = buy only above the EMA 50, sell only below it
useVolFilter = 1       // 1 = signal only when volume is above its 20-bar average
useSuperTrend = 1      // 1 = buy only with SuperTrend up, sell only with SuperTrend down
useRsiFilter = 1       // 1 = no buy when RSI is overbought, no sell when it is oversold
rsiLength = 14
rsiOverbought = 70
rsiOversold = 30
maxLabels = 500        // most recent BUY / SELL labels drawn

// ---------------- Fibonacci channel ----------------
IF barindex < periodLength - 1 THEN
   fib100 = undefined
   fib786 = undefined
   fib618 = undefined
   fib500 = undefined
   fib382 = undefined
   fib236 = undefined
   fib000 = undefined
ELSE
   highLevel = highest[periodLength](high)
   lowLevel = lowest[periodLength](low)
   rangeDiff = highLevel - lowLevel
   fib100 = highLevel
   fib786 = highLevel - rangeDiff * 0.214
   fib618 = highLevel - rangeDiff * 0.382
   fib500 = highLevel - rangeDiff * 0.500
   fib382 = highLevel - rangeDiff * 0.618
   fib236 = highLevel - rangeDiff * 0.764
   fib000 = lowLevel
ENDIF

// shaded zones between the levels
COLORBETWEEN(fib100, fib786, 242, 54, 69, 38)
COLORBETWEEN(fib786, fib618, 255, 152, 0, 38)
COLORBETWEEN(fib618, fib500, 253, 216, 53, 38)
COLORBETWEEN(fib500, fib382, 8, 153, 129, 38)
COLORBETWEEN(fib382, fib236, 76, 175, 80, 38)
COLORBETWEEN(fib236, fib000, 76, 175, 80, 51)

// ---------------- filters ----------------
rsiValue = RSI[rsiLength](close)
ema50 = average[50, 1](close)
volSma = average[20](volume)

// SuperTrend (factor 3, ATR 10), written out to get its direction:
// stDir = -1 is an uptrend (line below price), stDir = 1 a downtrend
atrV = averagetruerange[10](close)
IF barindex < 9 THEN
   stLine = undefined
   stDir = 1
ELSE
   upB = medianprice + 3 * atrV
   loB = medianprice - 3 * atrV
   IF barindex > 9 THEN
      IF NOT (loB > loBand[1] OR close[1] < loBand[1]) THEN
         loB = loBand[1]
      ENDIF
      IF NOT (upB < upBand[1] OR close[1] > upBand[1]) THEN
         upB = upBand[1]
      ENDIF
   ENDIF
   loBand = loB
   upBand = upB
   IF barindex = 9 THEN
      stDir = 1
   ELSIF stLine[1] = upBand[1] THEN
      IF close > upBand THEN
         stDir = -1
      ELSE
         stDir = 1
      ENDIF
   ELSE
      IF close < loBand THEN
         stDir = 1
      ELSE
         stDir = -1
      ENDIF
   ENDIF
   IF stDir = -1 THEN
      stLine = loBand
   ELSE
      stLine = upBand
   ENDIF
ENDIF

IF stDir = -1 THEN
   stR = 76
   stG = 175
   stB = 80
ELSE
   stR = 242
   stG = 54
   stB = 69
ENDIF

// ---------------- signals ----------------
rawBuy = 0
rawSell = 0
IF barindex >= periodLength THEN
   IF close CROSSES OVER fib382 OR close CROSSES OVER fib500 THEN
      rawBuy = 1
   ENDIF
   IF close CROSSES UNDER fib618 OR close CROSSES UNDER fib500 THEN
      rawSell = 1
   ENDIF
ENDIF

emaBuyOk = 1
emaSellOk = 1
IF useEmaFilter = 1 THEN
   emaBuyOk = (close > ema50)
   emaSellOk = (close < ema50)
ENDIF
volOk = 1
IF useVolFilter = 1 THEN
   volOk = (volume > volSma)
ENDIF
stBuyOk = 1
stSellOk = 1
IF useSuperTrend = 1 THEN
   stBuyOk = (stDir = -1)
   stSellOk = (stDir = 1)
ENDIF
rsiBuyOk = 1
rsiSellOk = 1
IF useRsiFilter = 1 THEN
   rsiBuyOk = (rsiValue < rsiOverbought)
   rsiSellOk = (rsiValue > rsiOversold)
ENDIF

finalBuy = rawBuy AND emaBuyOk AND volOk AND stBuyOk AND rsiBuyOk
finalSell = rawSell AND emaSellOk AND volOk AND stSellOk AND rsiSellOk

// signals are logged by index (plain assignments, harmless on every tick)
// and the labels are redrawn on the last bar
ONCE nSig = 0
IF finalBuy OR finalSell THEN
   $sigX[nSig] = barindex
   IF finalBuy THEN
      $sigD[nSig] = 1
      $sigY[nSig] = low - 0.5 * atrV
   ELSE
      $sigD[nSig] = -1
      $sigY[nSig] = high + 0.5 * atrV
   ENDIF
   nSig = nSig + 1
ENDIF

IF islastbarupdate AND nSig > 0 THEN
   FOR k = max(0, nSig - maxLabels) TO nSig - 1 DO
      IF $sigD[k] = 1 THEN
         DRAWTEXT("BUY", $sigX[k], $sigY[k], SansSerif, Bold, 11) COLOURED(76, 175, 80, 255)
      ELSE
         DRAWTEXT("SELL", $sigX[k], $sigY[k], SansSerif, Bold, 11) COLOURED(242, 54, 69, 255)
      ENDIF
   NEXT
ENDIF

// ---------------- background: last signal wins ----------------
ONCE trendState = 0
IF finalBuy THEN
   trendState = 1
ELSIF finalSell THEN
   trendState = -1
ENDIF
IF trendState = 1 THEN
   BACKGROUNDCOLOR(76, 175, 80, 26)
ELSIF trendState = -1 THEN
   BACKGROUNDCOLOR(242, 54, 69, 26)
ENDIF

RETURN fib100 COLOURED(242, 54, 69, 127) AS "Fib 100", fib786 COLOURED(242, 54, 69, 127) AS "Fib 78.6", fib618 COLOURED(255, 152, 0, 127) AS "Fib 61.8", fib500 COLOURED(253, 216, 53, 127) AS "Fib 50.0", fib382 COLOURED(8, 153, 129, 127) AS "Fib 38.2", fib236 COLOURED(76, 175, 80, 127) AS "Fib 23.6", fib000 COLOURED(76, 175, 80, 127) AS "Fib 0", ema50 COLOURED(60, 60, 60, 255) STYLE(line, 1) AS "EMA 50", stLine COLOURED(stR, stG, stB, 255) STYLE(line, 2) AS "SuperTrend"

Original author: kriptoborsatv.

Download
Filename: PRC_AutoFib-Kriptoborsa.itf
Downloads: 12
Iván González
Iván González Legend
As an architect of digital worlds, my own description remains a mystery. Think of me as an undeclared variable, existing somewhere in the code.
Author’s Profile

Comments

ProRealCode ProRealCode
Loading...