# Fibonacci levels, custom start / EndTime time
# Golden Zone script by Bpmstocks - https://www.tradingview.com/v/oIoLaduP/
# For intraday use Only.
# Request from https://usethinkscript.com/ member
# Created by Sam4Cok@Samer800 - 10/2023
input startTime = 0830;
input endTime = 1030;
input showVwmaLine = yes;
input ShowExtremes = yes;
input ShowFiboLevel = yes;
input fibLevel1 = 0.236;
input fibLevel2 = 0.382;
input fibLevel3 = 0.500;
input fibLevel4 = 0.618;
input fibLevel5 = 0.786;
input fibLevel6 = 1.000;
def na = Double.NaN;
def last = isNaN(close);
def bar = AbsValue(BarNumber());
def h = high;
def l = low;
def c = close;
def v = volume;
DefineGlobalColor("786", CreateColor(244,67,54));
DefineGlobalColor("618", CreateColor(129,199,132));
DefineGlobalColor("500", CreateColor(76,175,80));
DefineGlobalColor("382", CreateColor(0,150,136));
DefineGlobalColor("236", CreateColor(100,181,246));
def today = GetDay() == GetLastDay();
def yyyyMmDd = getYyyyMmDd();
def isPeriodRolled = compoundValue(1, yyyyMmDd != yyyyMmDd[1], yes);
def fromTime = if isPeriodRolled then 0 else SecondsFromTime(startTime);
def tillTime = SecondsTillTime(endTime);
def GlobeX = fromTime >= 0 and tillTime > 0;
def condStart = fromTime == 0;
def condEnd = tillTime == 0;
def barEnd = if condEnd then bar else
if isPeriodRolled then na else barEnd[1];
def plotCond = bar >= barEnd and !last;
def ONhigh = if condStart then h else if Globex then Max(ONhigh[1], h) else ONhigh[1];
def ONlow = if condStart then l else if GlobeX then min(if(ONlow[1], ONlow[1], l), l) else ONlow[1];
def lastHigh = if condEnd then ONhigh else lastHigh[1];
def lastLow = if condEnd then ONlow else lastLow[1];
def ONH = if bar >= barEnd then if lastHigh then lastHigh else h else na;
def ONL = if bar >= barEnd then if lastLow then lastLow else l else na;
def ONhighBar = if GlobeX and h == ONhigh then Bar else ONhighBar[1];
def ONlowBar = if GlobeX and l == ONlow then Bar else ONlowBar[1];
def bull = ONhighBar > ONlowBar;
def hiloDif = (lastHigh - lastLow);
#-- VWMA
def vol = if condStart then v else
if GlobeX then vol[1] + v else vol[1];
def volClo = if condStart then v * c else
if GlobeX then volClo[1] + v * c else volClo[1];
def cnt = if condStart then 0 else
if GlobeX then cnt[1] + 1 else cnt[1];
def VWMA = (volClo / cnt) / (vol / cnt);
def vwma1 = if condEnd then VWMA else VWMA1[1];
plot vwmaLine = if showVwmaLine and plotCond then vwma1 else na;
vwmaLine.SetDefaultColor(Color.DARK_ORANGE);
vwmaLine.SetStyle(Curve.POINTS);
#--ZigZag
plot crossLine = if bar== highestAll(ONhighBar) then h else
if bar== highestAll(ONlowBar) then l else na;
crossLine.EnableApproximation();
crossLine.SetDefaultColor(Color.WHITE);
crossLine.SetStyle(Curve.LONG_DASH);
#- Fibo
def lvl000 = if bull then ONL else ONH;
def lvl236 = if bull then ONL + hiloDif * fibLevel1 else ONH - hiloDif * fibLevel1;
def lvl382 = if bull then ONL + hiloDif * fibLevel2 else ONH - hiloDif * fibLevel2;
def lvl500 = if bull then ONL + hiloDif * fibLevel3 else ONH - hiloDif * fibLevel3;
def lvl618 = if bull then ONL + hiloDif * fibLevel4 else ONH - hiloDif * fibLevel4;
def lvl786 = if bull then ONL + hiloDif * fibLevel5 else ONH - hiloDif * fibLevel5;
def lvl100 = if bull then ONL + hiloDif * fibLevel6 else ONH - hiloDif * fibLevel6;
plot lvl10 = if ShowFiboLevel or ShowExtremes then lvl100 else na;
plot lvl78 = if ShowFiboLevel then lvl786 else na;
plot lvl61 = if ShowFiboLevel then lvl618 else na;
plot lvl50 = if ShowFiboLevel then lvl500 else na;
plot lvl38 = if ShowFiboLevel then lvl382 else na;
plot lvl23 = if ShowFiboLevel then lvl236 else na;
plot lvl00 = if ShowFiboLevel or ShowExtremes then lvl000 else na;
lvl10.SetDefaultColor(Color.MAGENTA);
lvl78.SetDefaultColor(GlobalColor("786"));
lvl61.SetDefaultColor(GlobalColor("618"));
lvl50.SetDefaultColor(GlobalColor("500"));
lvl38.SetDefaultColor(GlobalColor("382"));
lvl23.SetDefaultColor(GlobalColor("236"));
lvl00.SetDefaultColor(Color.CYAN);
def lastBarCond = today and GlobeX;
plot VolWMA = if showVwmaLine and lastBarCond then highestAll(inertiaAll(vwma1, 2)) else na;
plot lvl10l = if lastBarCond and (ShowFiboLevel or ShowExtremes) then highestAll(inertiaAll(lvl100, 2)) else na;
plot lvl78l = if lastBarCond and ShowFiboLevel then highestAll(inertiaAll(lvl786, 2)) else na;
plot lvl61l = if lastBarCond and ShowFiboLevel then highestAll(inertiaAll(lvl618, 2)) else na;
plot lvl50l = if lastBarCond and ShowFiboLevel then highestAll(inertiaAll(lvl500, 2)) else na;
plot lvl38l = if lastBarCond and ShowFiboLevel then highestAll(inertiaAll(lvl382, 2)) else na;
plot lvl23l = if lastBarCond and ShowFiboLevel then highestAll(inertiaAll(lvl236, 2)) else na;
plot lvl00l = if lastBarCond and (ShowFiboLevel or ShowExtremes) then highestAll(inertiaAll(lvl000, 2)) else na;
VolWMA.SetStyle(Curve.SHORT_DASH);
lvl10l.SetStyle(Curve.MEDIUM_DASH);
lvl78l.SetStyle(Curve.MEDIUM_DASH);
lvl61l.SetStyle(Curve.MEDIUM_DASH);
lvl50l.SetStyle(Curve.MEDIUM_DASH);
lvl38l.SetStyle(Curve.MEDIUM_DASH);
lvl23l.SetStyle(Curve.MEDIUM_DASH);
lvl00l.SetStyle(Curve.MEDIUM_DASH);
VolWMA.SetDefaultColor(Color.DARK_ORANGE);
lvl10l.SetDefaultColor(Color.MAGENTA);
lvl78l.SetDefaultColor(GlobalColor("786"));
lvl61l.SetDefaultColor(GlobalColor("618"));
lvl50l.SetDefaultColor(GlobalColor("500"));
lvl38l.SetDefaultColor(GlobalColor("382"));
lvl23l.SetDefaultColor(GlobalColor("236"));
lvl00l.SetDefaultColor(Color.CYAN);
#//@version=4
#// This script plots Fibonacci retracements and the Golden Zone to help identify potential future price movements.
#study("Golden Zone", overlay=true)
#// Inputs for customizing the script
input ShowGoldenZone = yes; # "Remove Golden Zone background?
input GoldenZoneCalcMethod = {Default "High/Low", "Day", "Week", "Month"};
input length = 60; # "Length (number of bars)"
input retracementLevel1 = 50; # "Retracement Level 1 (in %)"
input retracementLevel2 = 61.8; # "Retracement Level 2 (in %)"
def time = GetTime();
def RTH = if time >= RegularTradingStart(GetYYYYMMDD()) and time <= RegularTradingEND(GetYYYYMMDD()) then 1 else na;
def ret1 = retracementLevel1 / 100;
def ret2 = retracementLevel2 / 100;
def tfHi = Fundamental(FundamentalType.HIGH, Period = GoldenZoneCalcMethod);
def tfLo = Fundamental(FundamentalType.LOW, Period = GoldenZoneCalcMethod);
#// Get highest high and lowest low
#def day = GetDay();
def dhh = if !isNaN(rth) then tfHi else dhh[1];
def dll = if !isNaN(rth) then tfLo else dll[1];
def chh = highest(h, length);
def cll = lowest(l, length);
def hh; def ll;
Switch (GoldenZoneCalcMethod) {
Case "High/Low" :
hh = chh;
ll = cll;
Default :
hh = dhh;
ll = dll;
}
#// Calculate Fibonacci retracements
def diff = hh - ll;
def fib50 = hh - diff * ret1;
def fib61 = hh - diff * ret2;
#// Draw the filled area or box in the background
def line50 = if !ShowGoldenZone then na else fib50;
def line61 = if !ShowGoldenZone then na else fib61;
AddCloud(if last then na else line50, line61, Color.VIOLET);
# End of Code