Daily Range System (DRS) Indicator for ThinkorSwim

korygill

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

lPGN2Dg.png


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

https://tos.mx/UdEXUb

Happy Trading,
Kory Gill, @korygill
 

Attachments

  • lPGN2Dg.png
    lPGN2Dg.png
    434.6 KB · Views: 666
Last edited:

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

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.
 
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.
 
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?
 
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.
 
@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
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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