Author Message:
This powerful indicator leverages supertrend analysis to detect market direction while overlaying dynamic Fibonacci levels to highlight potential support, resistance, and optimal trend entry zones. With its straightforward design, it is perfect for traders looking to simplify their workflow and enhance decision-making.
More Details: https://www.tradingview.com/v/Lrpet5VK/
CODE:
CSS:
#// Indicator for TOS
#// © ChartPrime
#indicator("Fibonacci Trend [ChartPrime]", overlay = true, max_lines_count = 500)
# Converted by Sam4Cok@Samer800 - 01/2025
input showTrend = yes; # "trend"
input trendFactor = 4.0; # "Trend", step = 0.01, inline = "trend", group = "Trend")
input atrLength = 25;
input extendToRight = 5; #, "Extend", group = "Fibonacci",
input fib1 = 0.236; #, "1")*100
input fib2 = 0.382; #, "2")*100
input fib3 = 0.618; #, "3")*100
input fib4 = 0.786; #, "4")*100
def na = DOuble.NaN;
def last = isNaN(Close);
def v_236 = fib1 * 100;
def v_382 = fib2 * 100;
def v_618 = fib3 * 100;
def v_786 = fib4 * 100;
Script supertrend {
input factor = 3;
input atrPeriod = 10;
def last = isNaN(close);
def src = hl2;
def tr = if isNaN(high[1]) then (high - low) else
if !high[1] then (high - low) else TrueRange(high, close, low);
def atr = WildersAverage(tr, atrPeriod);
def upBand = src + factor * atr;
def loBand = src - factor * atr;
def lowerBand; def upperBand;
def prevLowerBand = if isNaN(lowerBand[1]) then loBand else
if !lowerBand[1] then loBand else lowerBand[1];
def prevUpperBand = if isNaN(upperBand[1]) then upBand else
if !upperBand[1] then upBand else upperBand[1];
lowerBand = if loBand > prevLowerBand or close[1] < prevLowerBand then loBand else prevLowerBand;
upperBand = if upBand < prevUpperBand or close[1] > prevUpperBand then upBand else prevUpperBand;
def _direction;
def superTrend;
def prevSuperTrend = superTrend[1];
if !last {
if isNaN(atr[1]) {
_direction = 1;
} else if !atr[1] {
_direction = 1;
} else if prevSuperTrend == prevUpperBand {
_direction = if close > upperBand then -1 else 1;
} else {
_direction = if close < lowerBand then 1 else -1;
}
} else {
_direction = _direction[1];
}
superTrend = if !last then if _direction == -1 then lowerBand else upperBand else prevSuperTrend;
plot st = superTrend;
plot dir = _direction;
}
def trend = supertrend(trendFactor, atrLength).dir;
def st = supertrend(trendFactor, atrLength).st;
plot stUp = if showTrend and !last and trend < 0 then st else na;
plot stDn = if showTrend and !last and trend > 0 then st else na;
stUp.SetDefaultColor(Color.GREEN);
stDn.SetDefaultColor(Color.RED);
#// Creat Fib Lines at the bottom and the top
def atr = atr(Length = 200);
def bar = if !last then bar[1] + 1 else bar[1];
def change = trend!=trend[1];
def lastTrend = if change then bar - 1 else lastTrend[1];
def lastBar = if !last then highestAll(lastTrend) else lastBar[1];
def fibLo; def fibHi;
def barLo; def barHi;
if bar >= lastBar {
if trend == -1 and change {
fibLo = low;
fibHi = high + atr*3;
barLo = 0;
barHi = 0;
} else if trend == 1 and change {
fibLo = high;
fibHi = low-atr*3;
barLo = 0;
barHi = 0;
} else {
if !last {
fibLo = if !fibLo[1] then if(trend == -1, low, high) else Min(low, fibLo[1]);
fibHi = if !fibHi[1] then if(trend == -1, high + atr*3, low-atr*3) else Max(high, fibHi[1]);
} else {
fibLo = if fibLo[1] then fibLo[1] else if(trend == -1, low, high) ;
fibHi = if fibHi[1] then fibHi[1] else if(trend == -1, high + atr*3, low-atr*3);
}
barLo = if low == fibLo then bar else 0;
barHi = if high == fibHi then bar else 0;
}
} else {
fibLo = na;
fibHi = na;
barLo = 0;
barHi = 0;
}
#plot tt = fibLo;
def fibLL = if fibLo then lowestAll(fibLo) else fibLL[1];
def fibHH = if fibHi then highestAll(fibHi) else fibHH[1];
def val0; def val1;
if !last[extendToRight] {
if trend == -1 {
val0 = fibHH;
val1 = fibLL;
} else if trend == 1 {
val0 = fibLL;
val1 = fibHH;
} else {
val0 = val0[1];
val1 = val1[1];
}
} else {
val0 = na;
val1 = na;
}
def lastBarLo = if barLo then highestAll(barLo) else lastBarLo[1];
def lastBarHi = if barHi then highestAll(barHi) else lastBarHi[1];
def size_step = (fibHH - fibLL) / 100;
plot line = if bar == lastBarLo then low else
if bar == lastBarHi then high else na;
line.EnableApproximation();
line.SetStyle(Curve.MEDIUM_DASH);
line.SetDefaultColor(Color.CYAN);
plot fiboLo = if val0 then val0 else na; #fibLL;
plot fiboHi = if val1 then val1 else na; #fibHH;
plot fiboLvL1 = val0 - size_step * v_236 * trend * -1;
plot fiboLvL2 = val0 - size_step * v_382 * trend * -1;
plot fiboMid = val0 - size_step * 50 * trend * -1;
plot fiboLvL3 = val0 - size_step * v_618 * trend * -1;
plot fiboLvL4 = val0 - size_step * v_786 * trend * -1;
fiboLo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fiboHi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fiboLvL1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fiboLvL2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fiboLvL3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fiboLvL4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fiboMid.SetPaintingStrategy(PaintingStrategy.DASHES);
fiboLo.SetDefaultColor(Color.MAGENTA);
fiboHi.SetDefaultColor(Color.MAGENTA);
fiboMid.SetDefaultColor(Color.GRAY);
fiboLvL1.SetDefaultColor(Color.MAGENTA);
fiboLvL2.SetDefaultColor(Color.MAGENTA);
fiboLvL3.SetDefaultColor(Color.MAGENTA);
fiboLvL4.SetDefaultColor(Color.MAGENTA);
#-- Clouds
AddCloud(fiboLvL3, fiboLvL4, Color.DARK_GRAY, Color.DARK_GRAY);
AddCloud(fiboMid, fiboLvL4, Color.DARK_GRAY, Color.DARK_GRAY);
AddCloud(hl2 , stUp, CreateColor(0, 32, 0));
AddCloud(stDn, hl2, CreateColor(42, 0, 0));
#-- Bubbles
AddChartBubble(bar == lastBarLo, low, AsDollars(low), Color.CYAN, no);
AddChartBubble(bar == lastBarHi, high, AsDollars(high), Color.CYAN);
# End of CODE