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

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:
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
 
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
This is exactly what I was looking for! Thank you.

Will try to be as detailed as I can be but is it possible to add the following?

1) add the ADR (After Defining Range). 7:30 PM - 8:30 PM EST and only valid until 2:00 AM EST.
2) RDR session to stop at 4:00 PM
3) Taking the high IDR to low IDR and adding 50% above and below shown in the picture. Ex: 150%, 200%, 250%, -150%,-200%,-250%. This should only be displayed for the DR session in play (either ADR, ODR, RDR).

Example Image:
Appreciate it :) Please let me know if you need additional clarity
 
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.
 
Was anyone able to get the chart to match the timeframes? I tried to modify it but it wouldn't work properly and I'm not a coder by and stretch. Basically getting the DR time to stop at 1615; ADR starting at 1930 and stopping at 2030 and the ODR from 0300-0400 (all NY time).
 
Was anyone able to get the chart to match the timeframes? I tried to modify it but it wouldn't work properly and I'm not a coder by and stretch. Basically getting the DR time to stop at 1615; ADR starting at 1930 and stopping at 2030 and the ODR from 0300-0400 (all NY time).
Nope still waiting.

It would be nice to just get ADR included at least
 
Thank you, I tried to modify just now too but not a coder either. Below is what is should be. Thank you!

adr.png
 
This is exactly what I was looking for! Thank you.

Will try to be as detailed as I can be but is it possible to add the following?

1) add the ADR (After Defining Range). 7:30 PM - 8:30 PM EST and only valid until 2:00 AM EST.
2) RDR session to stop at 4:00 PM
3) Taking the high IDR to low IDR and adding 50% above and below shown in the picture. Ex: 150%, 200%, 250%, -150%,-200%,-250%. This should only be displayed for the DR session in play (either ADR, ODR, RDR).

Example Image:
Appreciate it :) Please let me know if you need additional clarity
I have two requests, hope someone can help to add few scripts to them

a.I would like to have an option for the OPEN Price to be plotted, just like how the IDRmidline is being plotted after the Defining Range is completed, ie from 0930 to 1630H.


b. After the Defining Range is completed, after 1030 candle, the DR range will be plotted and i would like to have the range of IDR to be divided into 10 equal parts.

Attached is the picture to explain my request.

Thank you
18563[/ATTACH]']
AqkPJIg.jpg
 

Attachments

  • AqkPJIg.jpg
    AqkPJIg.jpg
    33.7 KB · Views: 161
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
is there a simple way to just add a cloud in between those white lines without the std dev? Cant get it to add here for some reason. All I want is a box around DR if possible. Thanks in advance.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
347 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