Daily Range- Intradaily Range (DR/IDR ) For ThinkOrSwim

MP432

Member
Defining Range DR and Implied Defining Range IDR for regular Session and overnight Session

This script is showing the IDR and DR for the regular trading session and for the overnight session based on the rules from the creator of the DR/IDR concept.
It works for all major Forex Pairs, BTC, ETH and the US Equity indices. This concept is based on rules and has a 80 % probability to be correct.

It should be applied in the 5 Min. Timeframe.

The timings for the RDR are from 09.30 - 10.30 am New York local time.
The timings for the ODR are from 03.00 - 04.00 am New York local time.

Rules:
1. If price in the 5 Min timeframe closes above the DR high after 10.30 am or 04.00 am then the DR low will be with 80 percent probability the low of the trading session. This is called confirmation.
2. If price in the 5 Min timeframe closes below the DR low after 10.30 am or 04.00 am then the DR high will be with 80 percent probability the high of the trading session. This is called confirmation.
3. If price closes above the IDR high after 10.30 am or 04.00 am it is an early indication that the low of the DR will be the low of the day and vice versa.

y6R4nD9.png
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

pls test it since I didn't test in live market.
7ThVD18.png

Author Message: https://www.tradingview.com/script/upzvFFch-DR-IDR-V1/

CODE:
CSS:
#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
declare hide_on_daily;
#//timings
input ShowTodayOnly        = no;   # 'Show complete history ?'
input exchangeOffset       = 0;    # 'Exchange Offset'
input regularTimeStart     = 0930; # 'RDR Time'
input regularTimeEnd       = 1030; # 'RDR Time'
input regularExtendStart   = 1030; # 'RDR Lines Time'
input regularExtendEnd     = 1600; # 'RDR Lines Time'
input overnightTimeStart   = 0400; # 'ODR Time'
input overnightTimeEnd     = 0500; # 'ODR Time'
input overnightExtendStart = 0500; # 'ODR Lines Time'
input overnightExtendEnd   = 0930; # 'ODR Lines Time'
#//lines
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 ?'

def na = Double.NaN;
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);

#---- END Code
 
Last edited by a moderator:
pls test it since I didn't test in live market.
7ThVD18.png

Author Message:
Defining Range DR and Implied Defining Range IDR for regular Session and overnight Session

This script is showing the IDR and DR for the regular trading session and for the overnight session based on the rules from the creator of the DR / IDR concept.
It works for all major Forex Pairs, BTC , ETH and the US Equity indices. This concept is based on rules and has a 80 % probability to be correct.

It should be applied in the 5 Min. Timeframe.

The timings for the RDR are from 09.30 - 10.30 am New York local time.
The timings for the ODR are from 03.00 - 04.00 am New York local time.

Rules:
1. If price in the 5 Min timeframe closes above the DR high after 10.30 am or 04.00 am then the DR low will be with 80 percent probability the low of the trading session. This is called confirmation.
2. If price in the 5 Min timeframe closes below the DR low after 10.30 am or 04.00 am then the DR high will be with 80 percent probability the high of the trading session. This is called confirmation.
3. If price closes above the IDR high after 10.30 am or 04.00 am it is an early indication that the low of the DR will be the low of the day and vice versa.

CODE:
CSS:
#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
declare hide_on_daily;
#//timings
input ShowTodayOnly        = no;   # 'Show complete history ?'
input exchangeOffset       = 0;    # 'Exchange Offset'
input regularTimeStart     = 0930; # 'RDR Time'
input regularTimeEnd       = 1030; # 'RDR Time'
input regularExtendStart   = 1030; # 'RDR Lines Time'
input regularExtendEnd     = 1600; # 'RDR Lines Time'
input overnightTimeStart   = 0400; # 'ODR Time'
input overnightTimeEnd     = 0500; # 'ODR Time'
input overnightExtendStart = 0500; # 'ODR Lines Time'
input overnightExtendEnd   = 0930; # 'ODR Lines Time'
#//lines
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 ?'

def na = Double.NaN;
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);

#---- END Code
Can you add standard deviation levels for the DR?
 
Can you add standard deviation levels for the DR?
eUdyYY8.png

levels added based on the price action. check it out.
CODE:
Level Updated - V1.5
CSS:
#import PineCoders/VisibleChart/4 as PCchart
#// © TheMas7er and bmistiaen
#indicator('DR/IDR V1.5', 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
# Updated by Sam4Cok@Samer800 - 06/2024 - added Dynamic Levels - not exact results.
declare hide_on_daily;
#//timings
input ShowTodayOnly      = no;   # 'Show complete history ?'
input regularTimeStart   = 0930; # 'RDR Time'
input regularTimeEnd     = 1030; # 'RDR Time'
input regularExtendStart = 1030; # 'RDR Lines Time'
input regularExtendEnd   = 1600; # 'RDR Lines Time'
input afterTimeStart     = 1930; # 'ADR Time'
input afterTimeEnd       = 2030; # 'ADR Time'
input afterTimeExtendStart = 2030; # 'ADR Time'
input afterTimeExtendEnd   = 0200; # 'ADR Time'
input overnightTimeStart = 0300; # 'ODR Lines Time'
input overnightTimeEnd   = 0400; # 'ODR Lines Time'
input overnightExtendStart = 0400; # 'ODR Lines Time'
input overnightExtendEnd   = 0830; # 'ODR Lines Time'
#//lines
input showRegularSession = yes; # 'Regular'
input showAfterMarketSession = yes; # 'After'
input showOvernightSession = yes;  # 'Overnight'
input showDrLines      = yes;      # 'Show DR Lines ?'
input showIdrLines     = yes;      # 'Show IDR Lines ?'
input showMiddleDrLine = no;       # 'Show Middle DR Line ?'
input showMiddleIdrLine = yes;     # 'Show Middle IDR Line ?'
input ShowDR_IDR_Box = {DR, IDR, default "Don't Show"}; # 'Show DR/IDR Box ?'
input ColorBox       = yes;        # 'Box color based on open and close'
input extendDrLines  = no;         # 'Extend DR Lines ?'
input extendIdrLines = no;         # 'Extend IDR Lines ?'
input stdStepFactor = 0.5;

def na = Double.NaN;
def last = isNaN(close);
def day = GetYYYYMMDD();
#--- Colors
DefineGlobalColor("cyan" ,CreateColor(0, 179, 179));
DefineGlobalColor("plum" ,CreateColor(179, 0, 179));
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 ExtDR  = if !extendDrLines then last else 0;
def ExtIDR = if !extendIdrLines then last else 0;
def Today = if GetLastDay() == GetDay() then 1 else 0;
def Current = GetAggregationPeriod();
def isintraday = Current < AggregationPeriod.DAY;
def m5_Agg = AggregationPeriod.FIVE_MIN;

#f_insession(_session) =>
script f_insession {
    input Start = 0930;
    input End  = 1030;
    def insession = SecondsTillTime(End) > 0 and SecondsFromTime(Start) >= 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   Current < 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) and showRegularSession;
def inRegularExtend    = f_insession(regularExtendStart, regularExtendEnd) and showRegularSession;
def inAfterSession     = f_insession(afterTimeStart, afterTimeEnd) and showAfterMarketSession;
def inAfterExtend      = f_insession(afterTimeExtendStart, afterTimeExtendEnd) and showAfterMarketSession;
def inOvernightSession = f_insession(overnightTimeStart, overnightTimeEnd) and showOvernightSession;
def inOvernightExtend  = f_insession(overnightExtendStart, overnightExtendEnd) and showOvernightSession;

def inSession = inRegularSession or inOvernightSession or inAfterSession;
def inExtend  = inRegularExtend  or inOvernightExtend or inAfterExtend;
def leaveRegularSession = !inRegularSession and inRegularSession[1];
def enterRegularExtend  = inRegularExtend and !inRegularExtend[1];

def sessionOpen;
def rdrhigh;
def rdrlow;
def ridrlow;
def ridrhigh;

if isintraday 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 = sessionOpen[1];
        rdrhigh     = rdrhigh[1];
        rdrlow      = rdrlow[1];
        ridrlow     = ridrlow[1];
        ridrhigh    = ridrhigh[1];
    }
} else {
    sessionOpen = na;
    rdrhigh     = na;
    rdrlow      = na;
    ridrhigh    = na;
    ridrlow     = na;
}

plot rgDRHigh = if !showDrLines or ExtDR or inSession then na else
                if rdrhigh then rdrhigh else na;
plot rgIDRhigh = if !showIdrLines or ExtIDR or inSession then na else
                 if ridrhigh then ridrhigh else na;
plot rgDRLow = if !showDrLines or ExtDR or inSession then na else
               if rdrlow then rdrlow else na;
plot rgIDRlow = if !showIdrLines or ExtIDR or inSession then na else
                if ridrlow then ridrlow else na;
rgDRHigh.SetDefaultColor(Color.WHITE);
rgIDRhigh.SetDefaultColor(Color.DARK_ORANGE);
rgDRLow.SetDefaultColor(Color.WHITE);
rgIDRlow.SetDefaultColor(Color.DARK_ORANGE);
rgIDRhigh.SetStyle(Curve.LONG_DASH);
rgIDRlow.SetStyle(Curve.LONG_DASH);

def cond = !today and !(!isNaN(rgDRHigh) and isNaN(rgDRHigh[1]));
def drPreHi  = if !isNaN(rgDRHigh)  then rgDRHigh  else drPreHi[1];
def drPreLo  = if !isNaN(rgDRLow)   then rgDRLow   else drPreLo[1];
def idrPreHi = if !isNaN(rgIDRhigh) then rgIDRhigh else idrPreHi[1];
def idrPreLo = if !isNaN(rgIDRlow)  then rgIDRlow  else idrPreLo[1];

def drHi  = if cond then na else inertiaAll(drPreHi,  2, extendToLeft = yes);
def idrHi = if cond then na else inertiaAll(idrPreHi, 2, extendToLeft = yes);
def drLo  = if cond then na else inertiaAll(drPreLo,  2, extendToLeft = yes);
def idrLo = if cond then na else inertiaAll(idrPreLo, 2, extendToLeft = yes);

def BX0 = ShowDR_IDR_Box==ShowDR_IDR_Box.DR;
def BX1 = ShowDR_IDR_Box==ShowDR_IDR_Box.IDR;
def BX  = ShowDR_IDR_Box!=ShowDR_IDR_Box."Don't Show";
def boxUp;
def boxBGColor;
def boxHighDR;
def boxLowDR;
def boxHighIDR;
def boxLowIDR;
def boxHigh;
def boxLow;
if BX and inSession {
    boxUp      = close_value > sessionOpen;
    boxBGColor = if ColorBox then If boxUp then 1 else -1 else 0;
    boxHighDR  = drHi; #rdrhigh;
    boxLowDR   = drLo; #rdrlow;
    boxHighIDR = idrHi; #ridrhigh;
    boxLowIDR  = idrLo; #ridrlow;
    boxHigh    = if BX0 then drHi else idrHi;
    boxLow     = if BX0 then drLo else idrLo;
} else {
    boxUp      = na;
    boxBGColor = if BX then boxBGColor[1] else na;
    boxHighDR  = na;
    boxLowDR   = na;
    boxHighIDR = na;
    boxLowIDR  = na;
    boxHigh    = na;
    boxLow     = na;
}

plot boxHdr = if !showDrLines then na else if boxHighDR then boxHighDR else na;
plot boxLdr = if !showDrLines then na else if boxLowDR then boxLowDR else na;
plot boxHidr = if !showIdrLines then na else if boxHighIDR then boxHighIDR else na;
plot boxLidr = if !showIdrLines then na else if boxLowIDR then boxLowIDR else na;
boxHdr.SetDefaultColor(Color.WHITE);
boxLdr.SetDefaultColor(Color.WHITE);
boxHidr.SetDefaultColor(Color.DARK_ORANGE);
boxLidr.SetDefaultColor(Color.DARK_ORANGE);

#--- Middle Lines
def drMid = if showMiddleDrLine then (rgDRHigh + rgDRLow) / 2 else na;
def idrMid = if showMiddleIdrLine then (rgIDRhigh + rgIDRlow) / 2 else na;
def boxdrMid = if showMiddleDrLine then (drHi + drLo) / 2 else na;
def boxidrMid = if showMiddleIdrLine then (idrHi + idrLo) / 2 else na;

plot drMidLine = if drMid then drMid else na;
plot idrMidLine = if idrMid then idrMid else na;
plot boxdrMidLine = if boxdrMid then boxdrMid else na;
plot boxidrMidLine = if boxidrMid then boxidrMid else na;
drMidLine.SetDefaultColor(Color.GRAY);
idrMidLine.SetDefaultColor(Color.DARK_ORANGE);
drMidLine.SetStyle(Curve.SHORT_DASH);
idrMidLine.SetStyle(Curve.SHORT_DASH);
boxdrMidLine.SetDefaultColor(Color.GRAY);
boxidrMidLine.SetDefaultColor(Color.DARK_ORANGE);
boxdrMidLine.SetStyle(Curve.SHORT_DASH);
boxidrMidLine.SetStyle(Curve.SHORT_DASH);

#-- highlights
def bgCol = boxBGColor;
def col = highestAll(inertiaAll(bgCol, 2));

AddCloud(if col>0 then boxHigh else na, boxLow, Color.DARK_GREEN);
AddCloud(if col<0 then boxHigh else na, boxLow, Color.DARK_RED);
AddCloud(if bgCol==0 then boxHigh else na, boxLow, Color.DARK_GRAY);

#---- Levels
input stdvLineType = {Default "Static", "Dynamic", "Don't Show"}; #'stdlines'
input stdLineDynamicExtraAuto = no; # 'Auto'
input stdLineDynamicExtraPos = 0; # 'Dynamic (+)'
input stdLineDynamicExtraNeg = 0; # 'Dynamic (-)'
input stdLineStaticExtraPos   = 10; # 'Static (+)'
input stdLineStaticExtraNeg   = 10; # 'Static (-)'

def regidrhigh; def regidrlow;
def sessionHigh; def sessionLow;
def nrLevelsPos; def nrLevelsNeg;

def stdStep = AbsValue(regidrhigh[1] - regidrlow[1])  * stdStepFactor;

if isintraday and stdStep!=0 and (Today or !ShowTodayOnly) {
switch (stdvLineType) {
Case "Don't Show" :
    nrLevelsPos = na;
    nrLevelsNeg = na;
Case "Dynamic" :
    nrLevelsPos = ceil(Max(sessionHigh[1] - regidrhigh[1], 0) / stdStep) +
                 (if stdLineDynamicExtraAuto then 0 else stdLineDynamicExtraPos);
    nrLevelsNeg = ceil(Max(regidrlow[1] - sessionLow[1], 0)   / stdStep) +
                 (if stdLineDynamicExtraAuto then 0 else stdLineDynamicExtraNeg);
Default :
    nrLevelsPos = Min(Max(stdLineStaticExtraPos, 0), 11);
    nrLevelsNeg = Min(Max(stdLineStaticExtraNeg, 0), 11);
}
 } else {
    nrLevelsPos = na;
    nrLevelsNeg = na;
}
def fibCond = Day==Day[-1] and isintraday and (Today or !ShowTodayOnly) and inRegularExtend;
def fip1Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 1 then regidrhigh[1] + stdStep * 1 else fip1Up[1];
def fip2Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 2 then regidrhigh[1] + stdStep * 2 else fip2Up[1];
def fip3Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 3 then regidrhigh[1] + stdStep * 3 else fip3Up[1];
def fip4Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 4 then regidrhigh[1] + stdStep * 4 else fip4Up[1];
def fip5Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 5 then regidrhigh[1] + stdStep * 5 else fip5Up[1];
def fip6Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 6 then regidrhigh[1] + stdStep * 6 else fip6Up[1];
def fip7Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 7 then regidrhigh[1] + stdStep * 7 else fip7Up[1];
def fip8Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 8 then regidrhigh[1] + stdStep * 8 else fip8Up[1];
def fip9Up  = if !fibCond[1] then na else
              if nrLevelsPos >= 9 then regidrhigh[1] + stdStep * 9 else fip9Up[1];
def fip10Up = if !fibCond[1] then na else
              if nrLevelsPos >= 10 then regidrhigh[1] + stdStep * 10 else fip10Up[1];
def fip11Up = if !fibCond[1] then na else
              if nrLevelsPos >= 11 then regidrhigh[1] + stdStep * 11 else fip11Up[1];
#-----
def fip1Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 1 then regidrlow[1] - stdStep * 1 else fip1Lo[1];
def fip2Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 2 then regidrlow[1] - stdStep * 2 else fip2Lo[1];
def fip3Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 3 then regidrlow[1] - stdStep * 3 else fip3Lo[1];
def fip4Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 4 then regidrlow[1] - stdStep * 4 else fip4Lo[1];
def fip5Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 5 then regidrlow[1] - stdStep * 5 else fip5Lo[1];
def fip6Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 6 then regidrlow[1] - stdStep * 6 else fip6Lo[1];
def fip7Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 7 then regidrlow[1] - stdStep * 7 else fip7Lo[1];
def fip8Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 8 then regidrlow[1] - stdStep * 8 else fip8Lo[1];
def fip9Lo  = if !fibCond[1] then na else if nrLevelsNeg >= 9 then regidrlow[1] - stdStep * 9 else fip9Lo[1];
def fip10Lo = if !fibCond[1] then na else if nrLevelsNeg >= 10 then regidrlow[1] - stdStep * 10 else fip10Lo[1];
def fip11Lo = if !fibCond[1] then na else if nrLevelsNeg >= 11 then regidrlow[1] - stdStep * 11 else fip11Lo[1];

plot FibPos1 = if fip1Up then fip1Up else na;
plot FibPos2 = if fip2Up then fip2Up else na;
plot FibPos3 = if fip3Up then fip3Up else na;
plot FibPos4 = if fip4Up then fip4Up else na;
plot FibPos5 = if fip5Up then fip5Up else na;
plot FibPos6 = if fip6Up then fip6Up else na;
plot FibPos7 = if fip7Up then fip7Up else na;
plot FibPos8 = if fip8Up then fip8Up else na;
plot FibPos9 = if fip9Up then fip9Up else na;
plot FibPos10 = if fip10Up then fip10Up else na;
plot FibPos11 = if fip11Up then fip11Up else na;
#-----
plot FibNeg1 = if fip1Lo then fip1Lo else na;
plot FibNeg2 = if fip2Lo then fip2Lo else na;
plot FibNeg3 = if fip3Lo then fip3Lo else na;
plot FibNeg4 = if fip4Lo then fip4Lo else na;
plot FibNeg5 = if fip5Lo then fip5Lo else na;
plot FibNeg6 = if fip6Lo then fip6Lo else na;
plot FibNeg7 = if fip7Lo then fip7Lo else na;
plot FibNeg8 = if fip8Lo then fip8Lo else na;
plot FibNeg9 = if fip9Lo then fip9Lo else na;
plot FibNeg10 = if fip10Lo then fip10Lo else na;
plot FibNeg11 = if fip11Lo then fip11Lo else na;

FibPos1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibPos11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FibNeg11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

FibPos1.SetDefaultColor(GlobalColor("cyan"));
FibPos2.SetDefaultColor(GlobalColor("cyan"));
FibPos3.SetDefaultColor(GlobalColor("cyan"));
FibPos4.SetDefaultColor(GlobalColor("cyan"));
FibPos5.SetDefaultColor(GlobalColor("cyan"));
FibPos6.SetDefaultColor(GlobalColor("cyan"));
FibPos7.SetDefaultColor(GlobalColor("cyan"));
FibPos8.SetDefaultColor(GlobalColor("cyan"));
FibPos9.SetDefaultColor(GlobalColor("cyan"));
FibPos10.SetDefaultColor(GlobalColor("cyan"));
FibPos11.SetDefaultColor(GlobalColor("cyan"));
FibNeg1.SetDefaultColor(GlobalColor("plum"));
FibNeg2.SetDefaultColor(GlobalColor("plum"));
FibNeg3.SetDefaultColor(GlobalColor("plum"));
FibNeg4.SetDefaultColor(GlobalColor("plum"));
FibNeg5.SetDefaultColor(GlobalColor("plum"));
FibNeg6.SetDefaultColor(GlobalColor("plum"));
FibNeg7.SetDefaultColor(GlobalColor("plum"));
FibNeg8.SetDefaultColor(GlobalColor("plum"));
FibNeg9.SetDefaultColor(GlobalColor("plum"));
FibNeg10.SetDefaultColor(GlobalColor("plum"));
FibNeg11.SetDefaultColor(GlobalColor("plum"));


if isintraday and (Today or !ShowTodayOnly) {
if leaveRegularSession {
    regidrhigh = ridrhigh;
    regidrlow  = ridrlow;
    } else {
    regidrhigh = regidrhigh[1];
    regidrlow  = regidrlow[1];
}
    } else {
    regidrhigh = na;
    regidrlow  = na;
}
if isintraday and (Today or !ShowTodayOnly) {
if enterRegularExtend {
    sessionHigh = high_value;
    sessionLow  = low_value;
    } else {
    sessionHigh = max(sessionHigh[1], high_value);
    sessionLow  = if !sessionLow[1] then low_value else min(sessionLow[1], low_value);
}
    } else {
    sessionHigh = na;
    sessionLow = na;
}

#--------- END CODE

Code V1.0
CSS:
#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
 
Last edited:
Is there a way to get this onto a Tick chart? Where the time is hard coded in so it can draw onto tick chart? TOS Canada the time charts are 15 minute delayed but the Tick charts are not.
 
@samer800 Thank you for pointing this

I noticed that that Chart does not Plot the DR Box even I have checked the Color Box to "Yes", is there something else I need to do.

1719735946678.png


1719736064960.png


Is it possible to add an arrow sign whenever price closed below the DR line after the first hour of market open ie 1030

In this example, after the first hour 1030, Price broken the DR line at 1215, can a down arrow be plotted after the 1215 is closed.

Similarly, if it broke above the DR line after 1030, then a Up arrow be plotted after the candle has closed.

I tried to do this but it does not work
plot Test = close crossingDirection.BELOW rgDRLow;

Thanks
 
Last edited:
@samer800 Thank you for pointing this

I noticed that that Chart does not Plot the DR Box even I have checked the Color Box to "Yes", is there something else I need to do.





Is it possible to add an arrow sign whenever price closed below the DR line after the first hour of market open ie 1030

In this example, after the first hour 1030, Price broken the DR line at 1215, can a down arrow be plotted after the 1215 is closed.

Similarly, if it broke above the DR line after 1030, then a Up arrow be plotted after the candle has closed.

I tried to do this but it does not work
plot Test = close crossingDirection.BELOW rgDRLow;

Thanks
1719755497847.png


to show the box, enable "Show DR IDR box".

for signals. add the below at the end of the code:

CSS:
input showCrosses = {Default "DR Crosses", "IDR Crosses", "DR/IDR Crosses", "Don't Show Crosses"};

def drCrossUp = close > rdrhigh and close[1] <= rdrhigh[1];
def drCrossDn = close < rdrlow and close[1] >= rdrlow[1];
def idrCrossUp = close > ridrHigh and close[1] <= ridrHigh[1];
def idrCrossDn = close < ridrLow and close[1] >= ridrLow[1];

def drUp; def drDn; def idrUp; def idrDn;

Switch (showCrosses) {
Case "IDR Crosses" :
    drUp = na;
    drDn = na;
    idrUp = if idrCrossUp[1] then rgIDRhigh else na;
    idrDn = if idrCrossDn[1] then rgIDRlow else na;
Case "DR/IDR Crosses" :
    drUp = if drCrossUp[1] then rgDRHigh else na;
    drDn = if drCrossDn[1] then rgDRLow else na;
    idrUp = if idrCrossUp[1] then rgIDRhigh else na;
    idrDn = if idrCrossDn[1] then rgIDRlow else na;
Case "Don't Show Crosses" :
    drUp = na;
    drDn = na;
    idrUp = na;
    idrDn = na;
Default :
    drUp = if drCrossUp then rgDRHigh else na;
    drDn = if drCrossDn then rgDRLow else na;
    idrUp = na;
    idrDn = na;
}

plot drSigUp = if drUp then drUp else na;
plot drSigDn = if drDn then drDn else na;
plot idrSigUp = if idrUp then idrUp else na;
plot idrSigDn = if idrDn then idrDn else na;

drSigUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
drSigDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
idrSigUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
idrSigDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

drSigUp.SetDefaultColor(Color.WHITE);
drSigDn.SetDefaultColor(Color.WHITE);
idrSigUp.SetDefaultColor(Color.DARK_ORANGE);
idrSigDn.SetDefaultColor(Color.DARK_ORANGE);
 
View attachment 22265

to show the box, enable "Show DR IDR box".

for signals. add the below at the end of the code:

CSS:
input showCrosses = {Default "DR Crosses", "IDR Crosses", "DR/IDR Crosses", "Don't Show Crosses"};

def drCrossUp = close > rdrhigh and close[1] <= rdrhigh[1];
def drCrossDn = close < rdrlow and close[1] >= rdrlow[1];
def idrCrossUp = close > ridrHigh and close[1] <= ridrHigh[1];
def idrCrossDn = close < ridrLow and close[1] >= ridrLow[1];

def drUp; def drDn; def idrUp; def idrDn;

Switch (showCrosses) {
Case "IDR Crosses" :
    drUp = na;
    drDn = na;
    idrUp = if idrCrossUp[1] then rgIDRhigh else na;
    idrDn = if idrCrossDn[1] then rgIDRlow else na;
Case "DR/IDR Crosses" :
    drUp = if drCrossUp[1] then rgDRHigh else na;
    drDn = if drCrossDn[1] then rgDRLow else na;
    idrUp = if idrCrossUp[1] then rgIDRhigh else na;
    idrDn = if idrCrossDn[1] then rgIDRlow else na;
Case "Don't Show Crosses" :
    drUp = na;
    drDn = na;
    idrUp = na;
    idrDn = na;
Default :
    drUp = if drCrossUp then rgDRHigh else na;
    drDn = if drCrossDn then rgDRLow else na;
    idrUp = na;
    idrDn = na;
}

plot drSigUp = if drUp then drUp else na;
plot drSigDn = if drDn then drDn else na;
plot idrSigUp = if idrUp then idrUp else na;
plot idrSigDn = if idrDn then idrDn else na;

drSigUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
drSigDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
idrSigUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
idrSigDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

drSigUp.SetDefaultColor(Color.WHITE);
drSigDn.SetDefaultColor(Color.WHITE);
idrSigUp.SetDefaultColor(Color.DARK_ORANGE);
idrSigDn.SetDefaultColor(Color.DARK_ORANGE);
Thank you so much again!!
 
Hello, any good video's to learn to trade this strategy? I searched on YT and it all seems influencer trying to get followers and no real contents.
 
Hello, any good video's to learn to trade this strategy? I searched on YT and it all seems influencer trying to get followers and no real contents.

Rules for this indicator:
1. If price in the 5 Min timeframe closes above the DR high after 10.30 am or 04.00 am then the DR low will be with 80 percent probability the low of the trading session. This is called confirmation.
2. If price in the 5 Min timeframe closes below the DR low after 10.30 am or 04.00 am then the DR high will be with 80 percent probability the high of the trading session. This is called confirmation.
3. If price closes above the IDR high after 10.30 am or 04.00 am it is an early indication that the low of the DR will be the low of the day and vice versa.

For more information, you would need to contact the OP over on Tradingview:
https://www.tradingview.com/script/upzvFFch-DR-IDR-V1/
 
pls test it since I didn't test in live market.
View attachment 16748
Author Message: https://www.tradingview.com/script/upzvFFch-DR-IDR-V1/

CODE:
CSS:
#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
declare hide_on_daily;
#//timings
input ShowTodayOnly        = no;   # 'Show complete history ?'
input exchangeOffset       = 0;    # 'Exchange Offset'
input regularTimeStart     = 0930; # 'RDR Time'
input regularTimeEnd       = 1030; # 'RDR Time'
input regularExtendStart   = 1030; # 'RDR Lines Time'
input regularExtendEnd     = 1600; # 'RDR Lines Time'
input overnightTimeStart   = 0400; # 'ODR Time'
input overnightTimeEnd     = 0500; # 'ODR Time'
input overnightExtendStart = 0500; # 'ODR Lines Time'
input overnightExtendEnd   = 0930; # 'ODR Lines Time'
#//lines
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 ?'

def na = Double.NaN;
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);

#---- END Code
I like this but admit to pruning down the code for personal use.

This is the pruned code and I'm trying it in place of the ORB on my chart?

Ruby:
#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
#Pruned down to Daily Range Lines Only by C. Ricks 8/7/24
declare hide_on_daily;
#//timings
input ShowTodayOnly = no; # 'Show complete history ?'
input exchangeOffset = 0; # 'Exchange Offset'
input regularTimeStart = 0930; # 'RDR Time'
input regularTimeEnd = 1030; # 'RDR Time'
input regularExtendStart = 1030; # 'RDR Lines Time'
input regularExtendEnd = 1600; # 'RDR Lines Time'
input overnightTimeStart = 0400; # 'ODR Time'
input overnightTimeEnd = 0500; # 'ODR Time'
input overnightExtendStart = 0500; # 'ODR Lines Time'
input overnightExtendEnd = 0930; # 'ODR Lines Time'
#//lines
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 ?'

def na = Double.NaN;
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);



#---- END Code
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
340 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top