#import PineCoders/VisibleChart/4 as PCchart
#// © TheMas7er and bmistiaen
#indicator('DR/IDR V1', overlay=true, max_lines_count=500, max_boxes_count=500)
# Converted by Sam4Cok@Samer800 - 12/2022
# Updated by Sam4Cok@Samer800 - 12/2022 - Added levels to DR/IDR
declare hide_on_daily;
#//timings
input ShowTodayOnly = no; # 'Show complete history ?'
input exchangeOffset = 0; # 'Exchange Offset'
input regularTimeStart = 0930; # 'RDR Time'
input regularTimeEnd = 1025; # 'RDR Time'
input regularExtendStart = 1025; # 'RDR Lines Time'
input regularExtendEnd = 1555; # 'RDR Lines Time'
input overnightTimeStart = 0400; # 'ODR Time'
input overnightTimeEnd = 0455; # 'ODR Time'
input overnightExtendStart = 0455; # 'ODR Lines Time'
input overnightExtendEnd = 0925; # 'ODR Lines Time'
#//lines
input LevelLines = yes;
input FibCloud = yes;
input drLines = yes; # 'Show DR Lines ?'
input idrLines = yes; # 'Show IDR Lines ?'
input middleDrLine = no; # 'Show Middle DR Line ?'
input middleIdrLine = yes; # 'Show Middle IDR Line ?'
input ColorBox = yes; # 'Box color based on open and close'
input ShowCloud = {DR,default IDR, None}; # 'Show DR/IDR Box ?'
input extendDrLines = no; # 'Extend DR Lines ?'
input extendIdrLines = no; # 'Extend IDR Lines ?'
input fib1Multi = 0.5;
input fib2Multi = 1.5;
input fib3Multi = 2.0;
input fib4Multi = 2.5;
input fib5Multi = 3.0;
input fib6Multi = 3.5;
input fib7Multi = 4.0;
input fib8Multi = 4.5;
input fib9Multi = 5.0;
input fib10Multi = 5.5;
input fib11Multi = 6.0;
def na = Double.NaN;
#--- Colors
DefineGlobalColor("gr1" , CreateColor(82,191,144));
DefineGlobalColor("gr2" , CreateColor(82,191,144));
DefineGlobalColor("gr3" , CreateColor(73,171,129));
DefineGlobalColor("gr4" , CreateColor(73,171,129));
DefineGlobalColor("gr5" , CreateColor(65,152,115));
DefineGlobalColor("gr6" , CreateColor(65,152,115));
DefineGlobalColor("gr7" , CreateColor(57,133,100));
DefineGlobalColor("gr8" , CreateColor(57,133,100));
DefineGlobalColor("gr9" , CreateColor(49,114,86));
DefineGlobalColor("gr0" , CreateColor(49,114,86));
DefineGlobalColor("re1" , CreateColor(255,186,186));
DefineGlobalColor("re2" , CreateColor(255,186,186));
DefineGlobalColor("re3" , CreateColor(255,123,123));
DefineGlobalColor("re4" , CreateColor(255,123,123));
DefineGlobalColor("re5" , CreateColor(255,82,82));
DefineGlobalColor("re6" , CreateColor(255,82,82));
DefineGlobalColor("re7" , CreateColor(255,0,0));
DefineGlobalColor("re8" , CreateColor(255,0,0));
DefineGlobalColor("re9" , CreateColor(167,0,0));
DefineGlobalColor("re0" , CreateColor(167,0,0));
#-----
def Cloud = if ShowCloud == ShowCloud.IDR then 1 else
if ShowCloud == ShowCloud.DR then -1 else
if ShowCloud == ShowCloud.None then 0 else Cloud[1];
def Highlight = Cloud;
def ExtDR = if !extendDrLines then IsNaN(close) else 0;
def ExtIDR = if !extendIdrLines then IsNaN(close) else 0;
def Today = if GetLastDay() == GetDay() then 1 else 0;
def CurrentAgg = GetAggregationPeriod();
def Agg = CurrentAgg < AggregationPeriod.DAY;
def m5_Agg = AggregationPeriod.FIVE_MIN;
#f_insession(_session) =>
script f_insession {
input _sessionStart = 0930;
input _sessionEnd = 1030;
def insession = if SecondsTillTime(_sessionEnd) > 0 and SecondsFromTime(_sessionStart) >= 0 then 1 else 0;
plot return = insession;
}
def m5_open = open (period = m5_Agg);
def m5_high = high (period = m5_Agg);
def m5_low = low (period = m5_Agg);
def m5_close = close(period = m5_Agg);
def open_value;
def high_value;
def low_value;
def close_value;
if CurrentAgg < m5_Agg {
open_value = m5_open;
high_value = m5_high;
low_value = m5_low;
close_value = m5_close;
} else {
open_value = open;
high_value = high;
low_value = low;
close_value = close;
}
def inRegularSession = f_insession(regularTimeStart, regularTimeEnd);
def inRegularExtend = f_insession(regularExtendStart, regularExtendEnd);
def inOvernightSession = f_insession(overnightTimeStart, overnightTimeEnd);
def inOvernightExtend = f_insession(overnightExtendStart, overnightExtendEnd);
def inSession = inRegularSession or inOvernightSession;
def inExtend = inRegularExtend or inOvernightExtend;
def sessionOpen;
def rdrhigh;
def rdrlow;
def ridrlow;
def ridrhigh;
if Agg and (Today or !ShowTodayOnly) {
if inSession {
if !inSession[1] {
sessionOpen = open_value;
rdrhigh = high_value;
rdrlow = low_value;
ridrhigh = Max(open_value, close_value);
ridrlow = Min(open_value, close_value);
} else {
sessionOpen = sessionOpen[1];
rdrhigh = Max(high_value, rdrhigh[1]);
rdrlow = Min(low_value, rdrlow[1]);
ridrhigh = Max(Max(open_value, close_value), ridrhigh[1]);
ridrlow = Min(Min(open_value, close_value), ridrlow[1]);
}
} else {
sessionOpen = na;
rdrhigh = rdrhigh[1];
rdrlow = rdrlow[1];
ridrlow = ridrlow[1];
ridrhigh = ridrhigh[1];
}
} else {
sessionOpen = na;
rdrhigh = na;
rdrlow = na;
ridrhigh = na;
ridrlow = na;
}
def boxUp;
def boxBackgroundColor;
def boxHighDR;
def boxLowDR;
def boxHighIDR;
def boxLowIDR;
if ColorBox and Highlight != 0 and inSession {
boxUp = close_value > sessionOpen;
boxBackgroundColor = If(boxUp, 1, -1);
boxHighDR = rdrhigh;
boxLowDR = rdrlow;
boxHighIDR = ridrhigh;
boxLowIDR = ridrlow;
} else {
boxUp = na;
boxBackgroundColor = if Highlight != 0 and inSession then 0 else na;
boxHighDR = if Highlight != 0 and inSession then rdrhigh else na;
boxLowDR = if Highlight != 0 and inSession then rdrlow else na;
boxHighIDR = if Highlight != 0 and inSession then ridrhigh else na;
boxLowIDR = if Highlight != 0 and inSession then ridrlow else na;
}
plot rdrhighLine = if !drLines or ExtDR or inSession then na else rdrhigh[exchangeOffset];
rdrhighLine.SetDefaultColor(Color.WHITE);
plot ridrhighLine = if !idrLines or ExtIDR or inSession then na else ridrhigh[exchangeOffset];
ridrhighLine.SetDefaultColor(Color.DARK_ORANGE);
ridrhighLine.SetStyle(Curve.LONG_DASH);
plot ridrlowLine = if !idrLines or ExtIDR or inSession then na else ridrlow[exchangeOffset];
ridrlowLine.SetDefaultColor(Color.DARK_ORANGE);
ridrlowLine.SetStyle(Curve.LONG_DASH);
plot rdrlowLine = if !drLines or ExtDR or inSession then na else rdrlow[exchangeOffset];
rdrlowLine.SetDefaultColor(Color.WHITE);
plot boxHdr = if !drLines then na else boxHighDR[exchangeOffset];
boxHdr.SetDefaultColor(Color.WHITE);
plot boxLdr = if !drLines then na else boxLowDR[exchangeOffset];
boxLdr.SetDefaultColor(Color.WHITE);
plot boxHidr = if !idrLines then na else boxHighIDR[exchangeOffset];
boxHidr.SetDefaultColor(Color.DARK_ORANGE);
plot boxLidr = if !idrLines then na else boxLowIDR[exchangeOffset];
boxLidr.SetDefaultColor(Color.DARK_ORANGE);
#--- Middle Lines
def drMid = (rdrhighLine + rdrlowLine) / 2;
def idrMid = (ridrhighLine + ridrlowLine) / 2;
def boxdrMid = (boxHdr + boxLdr) / 2;
def boxidrMid = (boxHidr + boxLidr) / 2;
plot drMidLine = if !middleDrLine then na else drMid;
drMidLine.SetDefaultColor(Color.GRAY);
plot idrMidLine = if !middleIdrLine then na else idrMid;
idrMidLine.SetDefaultColor(Color.GRAY);
idrMidLine.SetStyle(Curve.SHORT_DASH);
plot boxdrMidLine = if !middleDrLine then na else boxdrMid;
boxdrMidLine.SetDefaultColor(Color.GRAY);
plot boxidrMidLine = if !middleIdrLine then na else boxidrMid;
boxidrMidLine.SetDefaultColor(Color.GRAY);
boxidrMidLine.SetStyle(Curve.SHORT_DASH);
#-- highlights
def boxBGColor = boxBackgroundColor[exchangeOffset];
def boxH = if Highlight < 0 then boxHdr else boxHidr;
def boxL = if Highlight < 0 then boxLdr else boxLidr;
AddCloud(if boxBGColor > 0 and Highlight != 0 then boxH else if boxBGColor < 0 then boxL else na,
if boxBGColor > 0 and Highlight != 0 then boxL else if boxBGColor < 0 then boxH else na,
Color.DARK_GREEN, Color.DARK_RED);
AddCloud(if boxBGColor == 0 and Highlight != 0 then boxH else na, boxL, Color.GRAY, Color.GRAY);
#---- Levels
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
def FstBar = barssince(isNaN(ridrhighLine));
def FirsteBar = FstBar;
def endeBar = ridrhighLine;
def HHidre;def LLidre;def HHe; def LLe;
if !isNaN(endeBar) {
if close > open {
HHe = close;
LLe = open;
} else {
HHe = open;
LLe = close;}
} else {
HHe = close;
LLe = open;
}
HHidre = if !isNaN(endeBar) then fold i= 1 to FirsteBar with p do
if GetValue(close,i)>GetValue(open,i) and GetValue(close,i)>HHidre[1] then GetValue(close,i) else
if GetValue(close,i)<GetValue(open,i) and GetValue(open,i)>HHidre[1] then GetValue(open,i) else HHidre[1] else HHe;
LLidre = if !isNaN(endeBar) then fold j= 1 to FirsteBar with q do
if GetValue(close,j)>GetValue(open,j) and GetValue(open,j)<LLidre[1] then GetValue(open,j) else
if GetValue(close,j)<GetValue(open,j) and GetValue(close,j)<LLidre[1] then GetValue(close,j) else LLidre[1] else
LLe;
#if close>open then open else close;
def fip1Up = HHidre + ((HHidre- LLidre) * fib1Multi);
def fip2Up = HHidre + ((HHidre- LLidre) * fib2Multi);
def fip3Up = HHidre + ((HHidre- LLidre) * fib3Multi);
def fip4Up = HHidre + ((HHidre- LLidre) * fib4Multi);
def fip5Up = HHidre + ((HHidre- LLidre) * fib5Multi);
def fip6Up = HHidre + ((HHidre- LLidre) * fib6Multi);
def fip7Up = HHidre + ((HHidre- LLidre) * fib7Multi);
def fip8Up = HHidre + ((HHidre- LLidre) * fib8Multi);
def fip9Up = HHidre + ((HHidre- LLidre) * fib9Multi);
def fip10Up = HHidre + ((HHidre- LLidre) * fib10Multi);
def fip11Up = HHidre + ((HHidre- LLidre) * fib11Multi);
#-----
def fip1Lo = LLidre - ((HHidre- LLidre) * fib1Multi);
def fip2Lo = LLidre - ((HHidre- LLidre) * fib2Multi);
def fip3Lo = LLidre - ((HHidre- LLidre) * fib3Multi);
def fip4Lo = LLidre - ((HHidre- LLidre) * fib4Multi);
def fip5Lo = LLidre - ((HHidre- LLidre) * fib5Multi);
def fip6Lo = LLidre - ((HHidre- LLidre) * fib6Multi);
def fip7Lo = LLidre - ((HHidre- LLidre) * fib7Multi);
def fip8Lo = LLidre - ((HHidre- LLidre) * fib8Multi);
def fip9Lo = LLidre - ((HHidre- LLidre) * fib9Multi);
def fip10Lo = LLidre - ((HHidre- LLidre) * fib10Multi);
def fip11Lo = LLidre - ((HHidre- LLidre) * fib11Multi);
def eFibo05 = if endeBar then fip1Up else na;
plot eFibo15 = if endeBar then fip2Up else na;
eFibo15.SetDefaultColor(Color.CYAN);
eFibo15.SetHiding(!LevelLines);
def eFibo20 = if endeBar then fip3Up else na;
plot eFibo25 = if endeBar then fip4Up else na;
eFibo25.SetDefaultColor(CreateColor(0,179,179));
eFibo25.SetHiding(!LevelLines);
def eFibo30 = if endeBar then fip5Up else na;
def eFibo35 = if endeBar then fip6Up else na;
plot eFibo40 = if endeBar then fip7Up else na;
eFibo40.SetDefaultColor(CreateColor(0,179,179));
eFibo40.SetHiding(!LevelLines);
def eFibo45 = if endeBar then fip8Up else na;
def eFibo50 = if endeBar then fip9Up else na;
def eFibo55 = if endeBar then fip10Up else na;
def eFibo60 = if endeBar then fip11Up else na;
#-----
def eFiboM05 = if !isNaN(endeBar) then fip1Lo else na;
plot eFiboM15 = if !isNaN(endeBar) then fip2Lo else na;
eFiboM15.SetDefaultColor(Color.MAGENTA);
eFiboM15.SetHiding(!LevelLines);
def eFiboM20 = if !isNaN(endeBar) then fip3Lo else na;
plot eFiboM25 = if !isNaN(endeBar) then fip4Lo else na;
eFiboM25.SetDefaultColor(CreateColor(179,0,179));
eFiboM25.SetHiding(!LevelLines);
def eFiboM30 = if !isNaN(endeBar) then fip5Lo else na;
def eFiboM35 = if !isNaN(endeBar) then fip6Lo else na;
plot eFiboM40 = if !isNaN(endeBar) then fip7Lo else na;
eFiboM40.SetDefaultColor(CreateColor(179,0,179));
eFiboM40.SetHiding(!LevelLines);
def eFiboM45 = if !isNaN(endeBar) then fip8Lo else na;
def eFiboM50 = if !isNaN(endeBar) then fip9Lo else na;
def eFiboM55 = if !isNaN(endeBar) then fip10Lo else na;
def eFiboM60 = if !isNaN(endeBar) then fip11Lo else na;
#-- clouds
AddCloud(if !FibCloud then na else eFibo60, eFibo55, GlobalColor("gr0"), GlobalColor("gr0"));
AddCloud(if !FibCloud then na else eFibo55, eFibo50, GlobalColor("gr9"), GlobalColor("gr9"));
AddCloud(if !FibCloud then na else eFibo50, eFibo45, GlobalColor("gr8"), GlobalColor("gr8"));
AddCloud(if !FibCloud then na else eFibo45, eFibo40, GlobalColor("gr7"), GlobalColor("gr7"));
AddCloud(if !FibCloud then na else eFibo40, eFibo35, GlobalColor("gr6"), GlobalColor("gr6"));
AddCloud(if !FibCloud then na else eFibo35, eFibo30, GlobalColor("gr5"), GlobalColor("gr5"));
AddCloud(if !FibCloud then na else eFibo30, eFibo25, GlobalColor("gr4"), GlobalColor("gr4"));
AddCloud(if !FibCloud then na else eFibo25, eFibo20, GlobalColor("gr3"), GlobalColor("gr3"));
AddCloud(if !FibCloud then na else eFibo20, eFibo15, GlobalColor("gr2"), GlobalColor("gr2"));
AddCloud(if !FibCloud then na else eFibo15, eFibo05, GlobalColor("gr1"), GlobalColor("gr1"));
#-- cloud lower
AddCloud(if !FibCloud then na else eFiboM60, eFiboM55, GlobalColor("re0"), GlobalColor("re0"));
AddCloud(if !FibCloud then na else eFiboM55, eFiboM50, GlobalColor("re9"), GlobalColor("re9"));
AddCloud(if !FibCloud then na else eFiboM50, eFiboM45, GlobalColor("re8"), GlobalColor("re8"));
AddCloud(if !FibCloud then na else eFiboM45, eFiboM40, GlobalColor("re7"), GlobalColor("re7"));
AddCloud(if !FibCloud then na else eFiboM40, eFiboM35, GlobalColor("re6"), GlobalColor("re6"));
AddCloud(if !FibCloud then na else eFiboM35, eFiboM30, GlobalColor("re5"), GlobalColor("re5"));
AddCloud(if !FibCloud then na else eFiboM30, eFiboM25, GlobalColor("re4"), GlobalColor("re4"));
AddCloud(if !FibCloud then na else eFiboM25, eFiboM20, GlobalColor("re3"), GlobalColor("re3"));
AddCloud(if !FibCloud then na else eFiboM20, eFiboM15, GlobalColor("re2"), GlobalColor("re2"));
AddCloud(if !FibCloud then na else eFiboM15, eFiboM05, GlobalColor("re1"), GlobalColor("re1"));
#--------- END CODE