Range Measuring Tool

Cribbage

Member
I thought I'd share a tool I like to use for back-testing and ask for help altering part of it if possible. I have been editing one of Halcyon Guy's indicators for marking the different Globex sessions. I'd cut and pasted so much that it got messy and I just made this pared down version.

This indicator is for measuring specific time ranges of your choice. If there are multiple time ranges you want to use it on, I recommend you make copies and just change the colors so you know what's what. It marks start and end time, highs/lows (can choose bodies or wicks), the midline, the total range length, and 3 standard deviations.

NyzgsEa.png


I would like it if someone could help me color the candles within a range. In other words, Can someone help me make all the candles within the designated range a single color?

Here is Halcyon Guy's original script: https://usethinkscript.com/threads/...raday-futures-for-thinkorswim.2087/post-58176
Here is the ToS link: http://tos.mx/TExHsGt
And the Think Script:

Code:
## Range Measuring Tool ##
## Original code by HalcyonGuy, altered by Cribbage to be more speciic ##
## Original Code Link: https://usethinkscript.com/threads/draw-an-overnight-box-on-intraday-futures-for-thinkorswim.2087/post-58176##

declare hide_on_daily;

input candle_levels = {default "wick" , "body"};

input start1_est = 1800;
input end1_est = 500;
def start1 = start1_est;
def end1 = end1_est;

input show_start_end_vertical_lines = yes;
def ssevl = show_start_end_vertical_lines;

DefineGlobalColor("v", Color.WHITE);

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

# chg
def wickht = high - low;

# ---- wicks or body -------------------
def highx;
def lowx;
switch (candle_levels) {
case "wick":
    highx = high;
    lowx = low;
case "body":
    highx = Max( open, close);
    lowx = Min( open, close);
}

# reassign hi lo  to new vars
def hi = highx;
def lo = lowx;
def lastbar = !isnan(close[0]) and isnan(close[-1]);

# ----------------------------------------

input show_mid = yes;
input show_StDevs = yes;

# -----------------------------------------------

#  calc total minutes , from midnight , to each time
def start1hr = Floor(start1 / 100);
def start1min = start1 - (start1hr * 100);
def start1minttl = (start1hr * 60) + start1min;

def end1hr = Floor(end1 / 100);
def end1min = end1 - (end1hr * 100);
def end1minttl = (end1hr * 60) + end1min;

# ===========================>>>>>>>>>>>>>>>>>>>>

#  elapsed min in current period
def stmin2 = SecondsFromTime(start1);
def stmin = stmin2 / (60);

# ===========================>>>>>>>>>>>>>>>>>>>

#  is bar in a time period? , minutes in a day , 24 x 60 = 1440
def daymin = 1440;
def endz = 2359;
def startz = 0000;
def  first1 = if SecondsTillTime(start1) == 0 then 1 else 0;
def  last1 = if SecondsFromTime(end1) == 0 then 1 else 0;

def period1min;
def period1;
if start1minttl > end1minttl
then {
   # spans midnight , period=(24-start)+end , end to start
    period1min = (daymin - start1minttl) + end1minttl;
    period1 = if ((SecondsFromTime(start1) >= 0 and SecondsTillTime(endz) > 0) or ( SecondsFromTime(startz) >= 0 and SecondsTillTime(end1) > 0)) then 1 else 0;
} else {
   # ok , period=end-start , start to end
    period1min = (end1minttl - start1minttl);
    period1 = if SecondsFromTime(start1) >= 0 and SecondsTillTime(end1) > 0 then 1 else 0;
}

# ====================================

AddVerticalLine(ssevl and first1, "", GlobalColor("V"), Curve.MEDIUM_DASH);
AddVerticalLine(ssevl and last1, "", GlobalColor("V"), Curve.MEDIUM_DASH);

# get chart agg minutes
def chagg = GetAggregationPeriod();
def aggmin = chagg / (1000 * 60);

# calc qty of bars of period1, for the current chart time
def period1bars = period1min / aggmin;

# =====================<<<<<<<<<<<<<<<<<<<<<<

#  add check if in period and if last bar
def currentperiodbars = if (period1 and lastbar) then (stmin / aggmin) else 0;

#  find the high of active period, only on last bar
def xhi = fold xi = 0 to currentperiodbars
    with n = hi
    do Max(n, GetValue(hi, xi));

#  find the low of active period, only on last bar
def xlo = fold xj = 0 to currentperiodbars
    with m = lo
    do Min(m, GetValue(lo, xj));

def len = period1bars - 1;

# find high value for previous/complete time period, draw a line
def hi2 = if first1 then Highest(hi[-len], len + 1)
   else if last1 then na
   else if period1 then hi2[1]
   else na;

plot hiline = hi2;
hiline.SetDefaultColor(GlobalColor("V"));
#hiline.SetStyle(Curve.MEDIUM_DASH);
hiline.SetLineWeight(1);
hiline.HideBubble();

# ------------------------------------------------
# find low value for previous/complete time period, draw a line

def lo2 = if first1 then Lowest(lo[-len], len + 1)
   else if last1 then na
   else if period1 then lo2[1]
   else na;

plot loline = lo2;
loline.SetDefaultColor(GlobalColor("V"));
#loline.SetStyle(Curve.MEDIUM_DASH);
loline.SetLineWeight(1);
loline.HideBubble();

# ---------------------------------------------
# Cribbage Start

input show_range_length = YES;
def PRangeL = hiline - loline;

AddChartBubble(show_range_length and first1, hiline, PRangeL,
GlobalColor("V"), yes);

# Cribbage End
# ---------------------------------------------

##CRIBBAGE MIDLINE AND STANDARD DEVIATIONS START##

#Midline#
def MidLine = (PRangeL / 2) + loline;
plot middle = if show_mid then MidLine else na;

middle.SetDefaultColor(GlobalColor("V"));
middle.SetStyle(Curve.SHORT_DASH);

#Extension doesn't work, but would be nice
#def ExtendMid = Midline;
#Def ExtM1 = Midline + 1;
#Def ExtM2 = Midline + 2;
#Def ExtM3 = Midline + 3;

#Standard Deviations#

#Highs#
def SD1 = PRangeL + hiline;
def SD2 = (PRangeL * 2) + hiline;
def SD3 = (PRangeL * 3) + hiline;

plot SDLine1 = if show_StDevs then SD1 else na;
SDLine1.SetDefaultColor(GlobalColor("V"));
SDLine1.SetStyle(Curve.SHORT_DASH);

plot SDLine2 = if show_StDevs then SD2 else na;
SDLine2.SetDefaultColor(GlobalColor("V"));
SDLine2.SetStyle(Curve.SHORT_DASH);

plot SDLine3 = if show_StDevs then SD3 else na;
SDLine3.SetDefaultColor(GlobalColor("V"));
SDLine3.SetStyle(Curve.SHORT_DASH);

#Lows#
def SD4 = loline - PRangeL;
def SD5 = loline - (PRangeL * 2);
def SD6 = loline - (PRangeL * 3);

plot SDLine4 = if show_StDevs then SD4 else na;
SDLine4.SetDefaultColor(GlobalColor("V"));
SDLine4.SetStyle(Curve.SHORT_DASH);

plot SDLine5 = if show_StDevs then SD5 else na;
SDLine5.SetDefaultColor(GlobalColor("V"));
SDLine5.SetStyle(Curve.SHORT_DASH);

plot SDLine6 = if show_StDevs then SD6 else na;
SDLine6.SetDefaultColor(GlobalColor("V"));
SDLine6.SetStyle(Curve.SHORT_DASH);

##CRIBBAGE MIDLINE AND STANDARD DEVIATIONS END##
 
I thought I'd share a tool I like to use for back-testing and ask for help altering part of it if possible. I have been editing one of Halcyon Guy's indicators for marking the different Globex sessions. I'd cut and pasted so much that it got messy and I just made this pared down version.

This indicator is for measuring specific time ranges of your choice. If there are multiple time ranges you want to use it on, I recommend you make copies and just change the colors so you know what's what. It marks start and end time, highs/lows (can choose bodies or wicks), the midline, the total range length, and 3 standard deviations.

NyzgsEa.png


I would like it if someone could help me color the candles within a range. In other words, Can someone help me make all the candles within the designated range a single color?

Here is Halcyon Guy's original script: https://usethinkscript.com/threads/...raday-futures-for-thinkorswim.2087/post-58176
Here is the ToS link: http://tos.mx/TExHsGt
And the Think Script:

Code:
## Range Measuring Tool ##
## Original code by HalcyonGuy, altered by Cribbage to be more speciic ##
## Original Code Link: https://usethinkscript.com/threads/draw-an-overnight-box-on-intraday-futures-for-thinkorswim.2087/post-58176##

declare hide_on_daily;

input candle_levels = {default "wick" , "body"};

input start1_est = 1800;
input end1_est = 500;
def start1 = start1_est;
def end1 = end1_est;

input show_start_end_vertical_lines = yes;
def ssevl = show_start_end_vertical_lines;

DefineGlobalColor("v", Color.WHITE);

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

# chg
def wickht = high - low;

# ---- wicks or body -------------------
def highx;
def lowx;
switch (candle_levels) {
case "wick":
    highx = high;
    lowx = low;
case "body":
    highx = Max( open, close);
    lowx = Min( open, close);
}

# reassign hi lo  to new vars
def hi = highx;
def lo = lowx;
def lastbar = !isnan(close[0]) and isnan(close[-1]);

# ----------------------------------------

input show_mid = yes;
input show_StDevs = yes;

# -----------------------------------------------

#  calc total minutes , from midnight , to each time
def start1hr = Floor(start1 / 100);
def start1min = start1 - (start1hr * 100);
def start1minttl = (start1hr * 60) + start1min;

def end1hr = Floor(end1 / 100);
def end1min = end1 - (end1hr * 100);
def end1minttl = (end1hr * 60) + end1min;

# ===========================>>>>>>>>>>>>>>>>>>>>

#  elapsed min in current period
def stmin2 = SecondsFromTime(start1);
def stmin = stmin2 / (60);

# ===========================>>>>>>>>>>>>>>>>>>>

#  is bar in a time period? , minutes in a day , 24 x 60 = 1440
def daymin = 1440;
def endz = 2359;
def startz = 0000;
def  first1 = if SecondsTillTime(start1) == 0 then 1 else 0;
def  last1 = if SecondsFromTime(end1) == 0 then 1 else 0;

def period1min;
def period1;
if start1minttl > end1minttl
then {
   # spans midnight , period=(24-start)+end , end to start
    period1min = (daymin - start1minttl) + end1minttl;
    period1 = if ((SecondsFromTime(start1) >= 0 and SecondsTillTime(endz) > 0) or ( SecondsFromTime(startz) >= 0 and SecondsTillTime(end1) > 0)) then 1 else 0;
} else {
   # ok , period=end-start , start to end
    period1min = (end1minttl - start1minttl);
    period1 = if SecondsFromTime(start1) >= 0 and SecondsTillTime(end1) > 0 then 1 else 0;
}

# ====================================

AddVerticalLine(ssevl and first1, "", GlobalColor("V"), Curve.MEDIUM_DASH);
AddVerticalLine(ssevl and last1, "", GlobalColor("V"), Curve.MEDIUM_DASH);

# get chart agg minutes
def chagg = GetAggregationPeriod();
def aggmin = chagg / (1000 * 60);

# calc qty of bars of period1, for the current chart time
def period1bars = period1min / aggmin;

# =====================<<<<<<<<<<<<<<<<<<<<<<

#  add check if in period and if last bar
def currentperiodbars = if (period1 and lastbar) then (stmin / aggmin) else 0;

#  find the high of active period, only on last bar
def xhi = fold xi = 0 to currentperiodbars
    with n = hi
    do Max(n, GetValue(hi, xi));

#  find the low of active period, only on last bar
def xlo = fold xj = 0 to currentperiodbars
    with m = lo
    do Min(m, GetValue(lo, xj));

def len = period1bars - 1;

# find high value for previous/complete time period, draw a line
def hi2 = if first1 then Highest(hi[-len], len + 1)
   else if last1 then na
   else if period1 then hi2[1]
   else na;

plot hiline = hi2;
hiline.SetDefaultColor(GlobalColor("V"));
#hiline.SetStyle(Curve.MEDIUM_DASH);
hiline.SetLineWeight(1);
hiline.HideBubble();

# ------------------------------------------------
# find low value for previous/complete time period, draw a line

def lo2 = if first1 then Lowest(lo[-len], len + 1)
   else if last1 then na
   else if period1 then lo2[1]
   else na;

plot loline = lo2;
loline.SetDefaultColor(GlobalColor("V"));
#loline.SetStyle(Curve.MEDIUM_DASH);
loline.SetLineWeight(1);
loline.HideBubble();

# ---------------------------------------------
# Cribbage Start

input show_range_length = YES;
def PRangeL = hiline - loline;

AddChartBubble(show_range_length and first1, hiline, PRangeL,
GlobalColor("V"), yes);

# Cribbage End
# ---------------------------------------------

##CRIBBAGE MIDLINE AND STANDARD DEVIATIONS START##

#Midline#
def MidLine = (PRangeL / 2) + loline;
plot middle = if show_mid then MidLine else na;

middle.SetDefaultColor(GlobalColor("V"));
middle.SetStyle(Curve.SHORT_DASH);

#Extension doesn't work, but would be nice
#def ExtendMid = Midline;
#Def ExtM1 = Midline + 1;
#Def ExtM2 = Midline + 2;
#Def ExtM3 = Midline + 3;

#Standard Deviations#

#Highs#
def SD1 = PRangeL + hiline;
def SD2 = (PRangeL * 2) + hiline;
def SD3 = (PRangeL * 3) + hiline;

plot SDLine1 = if show_StDevs then SD1 else na;
SDLine1.SetDefaultColor(GlobalColor("V"));
SDLine1.SetStyle(Curve.SHORT_DASH);

plot SDLine2 = if show_StDevs then SD2 else na;
SDLine2.SetDefaultColor(GlobalColor("V"));
SDLine2.SetStyle(Curve.SHORT_DASH);

plot SDLine3 = if show_StDevs then SD3 else na;
SDLine3.SetDefaultColor(GlobalColor("V"));
SDLine3.SetStyle(Curve.SHORT_DASH);

#Lows#
def SD4 = loline - PRangeL;
def SD5 = loline - (PRangeL * 2);
def SD6 = loline - (PRangeL * 3);

plot SDLine4 = if show_StDevs then SD4 else na;
SDLine4.SetDefaultColor(GlobalColor("V"));
SDLine4.SetStyle(Curve.SHORT_DASH);

plot SDLine5 = if show_StDevs then SD5 else na;
SDLine5.SetDefaultColor(GlobalColor("V"));
SDLine5.SetStyle(Curve.SHORT_DASH);

plot SDLine6 = if show_StDevs then SD6 else na;
SDLine6.SetDefaultColor(GlobalColor("V"));
SDLine6.SetStyle(Curve.SHORT_DASH);

##CRIBBAGE MIDLINE AND STANDARD DEVIATIONS END##
Nice work! If you add this to the bottom of the study, it will color the candles in the range white:

def lineAppears = !isNaN(loline);
input colorbars = yes;
AssignPriceColor(if colorbars and lineAppears then Color.WHITE else Color.CURRENT);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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