Daily Range System (DRS) Indicator for ThinkorSwim

korygill

korygill

Active member
VIP
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

Active member
VIP
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.
 
horserider

horserider

Well-known member
VIP
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

Active member
VIP
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
@horserider found the issue, you must enable extended hours.
 
korygill

korygill

Active member
VIP
@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...
 
horserider

horserider

Well-known member
VIP
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.
 
horserider

horserider

Well-known member
VIP
@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
 
T

Thomas

Active member
@korygill Have ya seen TOSIndicator,...YouTube,.....something similar maybe????
 
korygill

korygill

Active member
VIP
Hi @Thomas, yes, I have seen tosindicators dot com before and their youtube. I dont really like the format of their site, and never proceeded to create an account to download something for free (which means they have lost any opportunity to upsell me on a paid indicator...but I digress, I am usually not the target audience for just about anything). I'd rather harness the power of a community like this.
 
T

Trader Raider

Member
VIP
FWIW, I'm a subscriber to the TOSindicator product. I've overlaid many of the indicators on this site with the TOSindicator product to find the best approximation. @horserider has come the closest with the SD bands.


horserider's SD bands are sometimes more accurate and have prevented me from taking TOSindicator signals that would have gotten stopped out. Mobius trend pivots can also be a good approximation sometimes.
 
T

Thomas

Active member
Hi @Thomas, yes, I have seen tosindicators dot com before and their youtube. I dont really like the format of their site, and never proceeded to create an account to download something for free (which means they have lost any opportunity to upsell me on a paid indicator...but I digress, I am usually not the target audience for just about anything). I'd rather harness the power of a community like this.
I read this awhile ago, but my thoughts are yours,....looked incredible, then in time with that "upsale," I ran...shame, there just seemed never to be an indicator that I liked either,.....and seemed they would leave alot of money on the table with focus on a 2 minute chart....
 

Top