Daily Range System (DRS) Indicator for ThinkorSwim

korygill

korygill

Member
VIP
Warehouse
Daily Range System (DRS)

The Daily Range System (DRS) is an indicator @BenTen found on TradingView, and I ported it to thinkorswim.

See these pages for more info on how to use this indicator.
https://www.tradingview.com/script/VpEHwgys-DRS-Daily-Range-System/ and https://www.forexfactory.com/showthread.php?t=743125

Here is what it looks like on thinkorswim



Code for DRS

Code:
#
# DailyRangeSystem_DRS
#
# Author: Kory Gill, @korygill
#
# Created from idea on https://www.tradingview.com/script/VpEHwgys-DRS-Daily-Range-System/
# Original idea is from https://www.forexfactory.com/showthread.php?t=743125
#
# VERSION HISTORY (sortable date and time (your local time is fine), and your initials
# 20190909-1200-KG    - Created.
# ...
# ...

input timeFromEST = -300; #hint timeFromEST: 24hr time from EST timezone
input starthr = 6; #hint start: 24hr format hour start time for DRS
input duration = 12; #hint duration: hours for 1st DRS cycle 

def exhr = if starthr+duration > 24 then starthr+duration-24 else starthr+duration;
def start = starthr*100 - timeFromEST;

def nan = Double.NaN;
def bn = BarNumber();

def hi = if bn < 2 then high
         else if SecondsFromTime(start) == 0 
         then high else if high > hi[1]
         then high
         else hi[1];

def lo = if bn < 2 then low
         else if SecondsFromTime(start) == 0 
         then low else if low < lo[1]
         then low
         else lo[1];

def mi = (hi + lo) * 0.50;
def m75 = 0.75 * hi + 0.25 * lo;
def m25 = 0.25 * hi + 0.75 * lo;

def sft = SecondsFromTime(start);

plot p1 = if sft[-1] == 0 then nan else hi;
plot p2 = if sft[-1] == 0 then nan else lo;
plot p3 = if sft[-1] == 0 then nan else m75;
plot p4 = if sft[-1] == 0 then nan else m25;
plot p5 = if sft[-1] == 0 then nan else mi;

p1.SetDefaultColor(Color.Cyan);
p2.SetDefaultColor(Color.Cyan);
p3.SetDefaultColor(Color.Cyan);
p4.SetDefaultColor(Color.Cyan);
p5.SetDefaultColor(Color.Yellow);

p1.SetLineWeight(2);
p2.SetLineWeight(2);

def elapsed = SecondsFromTime(start);
def durationSeconds = duration*60*60;

AddCloud(
    if elapsed <= durationSeconds and elapsed >= 0 then p1 else nan,
    if elapsed <= durationSeconds and elapsed >= 0 then p3 else nan,
    Color.GREEN, Color.GREEN);

AddCloud(
    if elapsed >= durationSeconds or elapsed <= 0 then p1 else nan,
    if elapsed >= durationSeconds or elapsed <= 0 then p3 else nan,
    Color.RED, Color.RED);

AddCloud(
    if elapsed <= durationSeconds and elapsed >= 0 then p2 else nan,
    if elapsed <= durationSeconds and elapsed >= 0 then p4 else nan,
    Color.GREEN, Color.GREEN);

AddCloud(
    if elapsed >= durationSeconds or elapsed <= 0 then p2 else nan,
    if elapsed >= durationSeconds or elapsed <= 0 then p4 else nan,
    Color.RED, Color.RED);
Link to the study

http://tos.mx/UdEXUb

Happy Trading,
Kory Gill, @korygill
 
Last edited:
korygill

korygill

Member
VIP
Warehouse
Completely at loss whats the point of this indicator lol. What exactly does it indicate?
You have to dig into the forex factory article and determine if this indicator actually performs as described. I just wrote the code for fun.
 
H

horserider

Active member
Warehouse
Looks like it is a reversion indicator, for ranging markets, trade from top to bottom and vice versa. But did not even work on my charts. Just a big green area. I think it is for forex so maybe the times are off.
 
korygill

korygill

Member
VIP
Warehouse
Looks like it is a reversion indicator, for ranging markets, trade from top to bottom and vice versa. But did not even work on my charts. Just a big green area. I think it is for forex so maybe the times are off.
what's your timezone? what symbol? what params did you use?
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@horserider found the issue, you must enable extended hours.
 
korygill

korygill

Member
VIP
Warehouse
@horserider found the issue, you must enable extended hours.
there may also be some quirks with time i did not account for....will look to debug this later. sorry for not testing this in more detail folks...will report back soon...
 
H

horserider

Active member
Warehouse
Thanks for the reply and info. No worries on it. It does not look like a study I will choose to use. Great work and hope you can iron it all out.
 
H

horserider

Active member
Warehouse
@korygill Maybe something in this study can help.

Code:
# Mobius
# Chat Room Request 06.05.2015

input TimeBegin  = 1000.0; #hint TimeBegin: Beginning for Period Range
input TimeEnd    = 1200.0; #hint TimeEnd: End of Period Range

   def h = high;
   def l = low;
   def c = close;
   def Today = GetDay() == GetLastDay();
   def TimeActive = if secondsTillTime(TimeEnd) > 0 and
                      secondsFromTime(TimeBegin) >= 0
                   then 1
                   else 0;
   def RHigh = if RHigh[1] == 0
                   or TimeActive[1] == 0 and
                      TimeActive == 1
                 then h
                 else if TimeActive and
                         h > RHigh[1]
                 then h
                 else RHigh[1];
   def RLow = if RLow[1] == 0
                 or TimeActive[1] == 0 and
                    TimeActive == 1
                then l
                else if TimeActive and
                        l < RLow[1]
                then l
                else RLow[1];

  plot RH = if today < 1
              then Double.NaN
              else RHigh;
  plot RL = if today < 1
              then Double.NaN
              else RLow;
       RH.SetDefaultColor(color.green);
       RH.SetStyle(curve.Long_DASH);
       RH.SetLineWeight(3);
       RL.SetDefaultColor(color.red);
       RL.SetStyle(curve.Long_DASH);
       RL.SetLineWeight(3);

# End Code
 

Top