Price and Range Lines

abraham

New member
Hi Ben / @korygill , Talented Team,
  • Line in the sand (LIS). I want an aqua colored line drawn using the closing price of the first 5 minute candle in after hours trading (the one from 16:00-16:05). Wherever this candle closes, a horizontal line is drawn in aqua that shows LIS and Price. Based on SHAK today, that line would be at 102.66. No matter what timeframe we move to I want this line to be permanent for the next trading day only. Each day a new line is generated and we don’t see any prior lines.
  • For weekly range lines. I want to a yellow horizontal line drawn from Sunday to Saturday of the next week based on the following. For SHAK this week, the lines would be at 104.82 and 97.79 based on last weeks numbers.
(Prior weekly Range x 0.775) - Prior Range = X
X / 2 = Y
Prior Weekly High - Y = New upper weekly horizontal line
Prior weekly Low + Y = New lower Weekly horizontal line

Last weeks range was 9.07. The high was 105.84 and the low 96.77. So..

[(9.07x0.775)-9.07=2.04
2.04/2=1.02
105.84-1.02=104.82
96.77+1.02=97.79
  • If we can figure this first one out, then the coding for the monthly lines will be easy. The multiplier for monthly is 0.784 and just referencing prior monthly ranges and high/lows. For SHAK, the lines would be at 97.82 and 75.52 based on last months numbers.
  • (Prior Monthly Range x 0.784) - Prior Range = X
    X / 2 = Y
    Prior Monthly High - Y = New upper Monthly horizontal line in pink
  • Prior Monthly Low + Y = New lower Monthly horizontal line in pink
  • For yearly, The multiplier for Yearly is 0.774 and just referencing prior yearly ranges and high/lows. For SHAK, the lines would be at 64.99 and 41.71 based on last years numbers.

  • (Prior Yearly Range x 0.774) - Prior Range = X
    X / 2 = Y
    Prior Yearly High - Y = New upper Yearly horizontal line in blue
  • Prior Yearly Low + Y = New lower Yearly horizontal line in blue
 
Last edited:
Solution
Hello,

I'm assuming you want to replicate someones "proprietary" indicator. I actually know who you're referring to lol. Well I'm more than happy to assist you with this. Copy and paste the code below into a new indicator.

Now, I know my math is sound but your values that you stated for the yearly don't match up. So I'm not sure if the multiplier you mentioned is correct or not.

Code:
# Weekly Monthly & Yearly Range Lines
# Developed by MrFib - Twitter @PSenas03
# Last updated: 9/22/2019

input timeFrame = {default WEEK, MONTH, YEAR};
input showOnlyToday = no;

def H = high(period = timeFrame)[1];
def L = low(period = timeFrame)[1];

# Calculating range
def multiplier; # multiplier is a variable that changes based on timeframe input
if...
Hello,

I'm assuming you want to replicate someones "proprietary" indicator. I actually know who you're referring to lol. Well I'm more than happy to assist you with this. Copy and paste the code below into a new indicator.

Now, I know my math is sound but your values that you stated for the yearly don't match up. So I'm not sure if the multiplier you mentioned is correct or not.

Code:
# Weekly Monthly & Yearly Range Lines
# Developed by MrFib - Twitter @PSenas03
# Last updated: 9/22/2019

input timeFrame = {default WEEK, MONTH, YEAR};
input showOnlyToday = no;

def H = high(period = timeFrame)[1];
def L = low(period = timeFrame)[1];

# Calculating range
def multiplier; # multiplier is a variable that changes based on timeframe input
if timeFrame == timeframe.WEEK
then {
    multiplier = 0.775;
}
else if timeframe == timeframe.MONTH
then {
    multiplier = 0.784;
}
else {
    multiplier = 0.774;
}

def range = H-L;
def X = range - range*multiplier;
def Y = X/2;
 
#resistance formula
def calc_R1 =  H - Y;

#support formula
def calc_S1 = L + Y;


plot R1;
plot S1;


if (showOnlyToday and !IsNaN(close(period = timeFrame)[-1])) or
(getAggregationPeriod() > if timeframe == timeframe.WEEK then AggregationPeriod.WEEK
                               else if timeframe == timeframe.MONTH
                               then AggregationPeriod.MONTH
                               else AggregationPeriod.YEAR)

then {

    R1 = Double.NaN;
    
    S1 = Double.NaN;
  
}
else {
    
  
    R1 = calc_R1;
    
    S1 = calc_S1;
}

R1.SetDefaultColor(color.yellow);
S1.SetDefaultColor(color.yellow);

R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Solution
Wow! You are the BEST my friend!! Thank you very much. So you inputted the values as is or did you correct the math? I just imported and still reviewing it.
 
I left the values as is. I was too lazy to do the math lol simple enough to figure out though. I wasn't sure if the pivot values were mistyped or the multiplier. I'll leave that for you to figure out. As for the indicator, I built it just for one range to overlay. If you want all 3 then just put it on the chart 3x and change the aggregation period for each one.
 
I didn't make the LIS yet, its simple enough though. I'll get to it when I have time. @abraham

@Shrum I reversed engineered an indicator made from a specific trade group. TBH I'm not sure how they use it. I would assume you would use it as pivot levels based on the weekly, monthly, and yearly range values.
 
Wow again @MrFib You certainly have the TOS coding skills!! Thank you very much. This is in addition to other indicators and used as a pivot levels based on the weekly, monthly, and yearly range values as you rightly pointed out. Incredible and talented members we have here.
 
Hi Again! Happy to hear from you. Actually I am not 100% sure. Based on your experience can you provide any suggestions? I see so many choices and options provided by different traders (looks like they all work fine for their "own" strategy). I was thinking in terms of FIB levels and Kelt ranges. Appreciate it.
 
Hello,

I'm assuming you want to replicate someones "proprietary" indicator. I actually know who you're referring to lol. Well I'm more than happy to assist you with this. Copy and paste the code below into a new indicator.

Now, I know my math is sound but your values that you stated for the yearly don't match up. So I'm not sure if the multiplier you mentioned is correct or not.

Code:
# Weekly Monthly & Yearly Range Lines
# Developed by MrFib - Twitter @PSenas03
# Last updated: 9/22/2019

input timeFrame = {default WEEK, MONTH, YEAR};
input showOnlyToday = no;

def H = high(period = timeFrame)[1];
def L = low(period = timeFrame)[1];

# Calculating range
def multiplier; # multiplier is a variable that changes based on timeframe input
if timeFrame == timeframe.WEEK
then {
    multiplier = 0.775;
}
else if timeframe == timeframe.MONTH
then {
    multiplier = 0.784;
}
else {
    multiplier = 0.774;
}

def range = H-L;
def X = range - range*multiplier;
def Y = X/2;
 
#resistance formula
def calc_R1 =  H - Y;

#support formula
def calc_S1 = L + Y;


plot R1;
plot S1;


if (showOnlyToday and !IsNaN(close(period = timeFrame)[-1])) or
(getAggregationPeriod() > if timeframe == timeframe.WEEK then AggregationPeriod.WEEK
                               else if timeframe == timeframe.MONTH
                               then AggregationPeriod.MONTH
                               else AggregationPeriod.YEAR)

then {

    R1 = Double.NaN;
   
    S1 = Double.NaN;
 
}
else {
   
 
    R1 = calc_R1;
   
    S1 = calc_S1;
}

R1.SetDefaultColor(color.yellow);
S1.SetDefaultColor(color.yellow);

R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
awesome how can this be done to have a label calculate in $ amount the range between th hi and low of the 5 min opening range.... as a label
 
I would like to create an indicator that can plot the following ranges in a mutli time frame capability: 1. Calculate the individual ranges of the last X periods (default=14); 2. Add the 14 ranges together and divide by 14 obtain the 14 day avg range; 3. Divide this 14 period avg. range by 2; 4. Add this result to the close (or gap open); 5. Subtract this result from the same close; So on a daily chart I would like to plot the daily, weekly, and monthly ranges simultaneously.
 
Last edited by a moderator:
I would like to create an indicator that can plot the following ranges in a mutli time frame capability: 1. Calculate the individual ranges of the last X periods (default=14); 2. Add the 14 ranges together and divide by 14 obtain the 14 day avg range; 3. Divide this 14 period avg. range by 2; 4. Add this result to the close (or gap open); 5. Subtract this result from the same close; So on a daily chart I would like to plot the daily, weekly, and monthly ranges simultaneously.
You might be able to modify this code to do what you want:
https://usethinkscript.com/threads/price-and-range-lines.609/#post-5011
 
that gets close but it doesnt calculate the 14 period average True Range as the True Range calculation . Thanks very much....its goes a long way to getting there.
 

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
186 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