Need Help with a "top 10% range of the 2nd previous bar indicator plottedPlease

papio271

New member
Need Help with a "top 30% range of Weekly bar[2] if weekly bar [1] is an inside Bar and currant bar last/close is above the open then plot horizontal lines of the high and low of the top 30% range for the next 2 trading days beyond today's current bar thus showing me the range i need to watch.

And opposite if the current last is lower than its open - then showing the bottom 30% range of Bar[2] displayed in a horizontal line beyond the current trading bar. .

I would like the ability to show these weekly range horizontal lines on all time frames - if not to much to ask perhaps have input options to displays ranges for Monthly, Weekly, Daily, Hourly (basically the ability to plot any timeline one desires and plot that selection on all time frames and to choose how many time periods out some one wants to plot the horizontal line..... for example plot lines 2 periods after current bar or 5 periods after current bar.

I have been trading the STRAT and draw my horizontal lines manually. I think this would be a nice feature to have as a visual aid.

I am pasting my horrible attempt at scripting. (to perhaps give you some sort of idea...(yup its brutal...Stop Laughing...lol))
The formulas in the Def lines are what I perform and plot Manually. I do not wish to plot as a moving average that follows price but plot horizontal lines forward of current days trading bar.

FOR THE HIGH PLOT

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input plotforward = 1;

def highP = (high[1]);
def lowP = (high[1] - ((high[1] - low[1]) * .3));

plot newhorizontalLine = highP;
plot newhorizontalLine2 = lowP;


FOR THE LOW PLOT

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input plotforward = 1;

def highP = (low[1] + ((high[1] - low[1]) * .3));
def lowP = (low{1]);

plot newhorizontalLine = highP;
plot newhorizontalLine2 = lowP;

Thank You in Advance......STOP LAUGHING......LOL
 
Solution
here is my version of what you described in the first sentence.

# top/bottom 30% range of Weekly bar[2]
# if weekly bar [1] is an inside Bar
# and current bar close is above the open
# then plot horizontal line of the high ( green) , and 30% lower
# of the top 30% range
# for the next 2 trading days beyond today's current bar thus showing me the range i need to watch.

===EDIT:
if current bar close is below the open , then plot red lines, at the low of week[2] and a line 30% above it.


your code didn't match your words , so i went with your words. ( day instead of week , [1] instead of [2], ... )
instead of plotting lines for 2 days, they plot after the last bar to the right edge of the window.

if the last bar...
here is my version of what you described in the first sentence.

# top/bottom 30% range of Weekly bar[2]
# if weekly bar [1] is an inside Bar
# and current bar close is above the open
# then plot horizontal line of the high ( green) , and 30% lower
# of the top 30% range
# for the next 2 trading days beyond today's current bar thus showing me the range i need to watch.

===EDIT:
if current bar close is below the open , then plot red lines, at the low of week[2] and a line 30% above it.


your code didn't match your words , so i went with your words. ( day instead of week , [1] instead of [2], ... )
instead of plotting lines for 2 days, they plot after the last bar to the right edge of the window.

if the last bar is up, then the lines are green, if a down bar, then red.
i tested with
bypass_inside_test = yes
DG 2hr chart , green lines
DIS 2hr chart , red lines.

there are several inputs. the last 2 are for testing: show all weekly lines from 2 weeks ago, bypass the check for inside bar.

Ruby:
# top10per_prev_01

# https://usethinkscript.com/threads/need-help-with-a-top-10-range-of-the-2nd-previous-bar-indicator-plottedplease.7221/

# ================================
# -- i separated out the first sentence , and used it as a set of rules
#  top/bottom  30% range of Weekly bar[2]
#   if weekly bar [1] is an inside Bar
#    and current bar close is above the open
#     then plot horizontal lines of the high and low
#      of the top 30% range
#       for the next 2 trading days beyond today's current bar thus showing me the range i need to watch.
# ================================

def na = double.nan;
def bn = barnumber();

# last bar
def lastbar = !isnan(close[0]) and isnan(close[-1]);

#input showOnlyLastPeriod = no;
#input aggd = AggregationPeriod.DAY;

input range_percent = 30;
def per = (range_percent /100);


# ==== top/bottom  30% range of Weekly bar[2]
input aggw = AggregationPeriod.week;
input week_range_offset = 2;

def reftophi = high(period = aggw)[week_range_offset];
def refbotlo = low(period = aggw)[week_range_offset];

def reftoplo = reftophi - ((reftophi - refbotlo) * per);
def refbothi = refbotlo + ((reftophi - refbotlo) * per);

input show_weekly_test_lines = no;
plot a = if show_weekly_test_lines then reftophi else na;
plot b = if show_weekly_test_lines then reftoplo else na;
plot c = if show_weekly_test_lines then refbothi else na;
plot d = if show_weekly_test_lines then refbotlo else na;


# ==== if weekly bar[1] is an inside Bar  and  current bar close is above the open
def weekinside = 1;
def wkinside2 = ( (high(period = aggw)[weekinside] < high(period = aggw)[weekinside+1]) and (low(period = aggw)[weekinside] > low(period = aggw)[weekinside+1]) );

input bypass_inside_test = no;
def wkinside = if bypass_inside_test then 1 else wkinside2;


def barup = (close > open);
def bardwn = (close < open);

#    then plot horizontal lines of the high and low
#     of the top 30% range
#      for the next 2 trading days beyond today's current bar thus showing me the range i need to watch.

def topline2 = if (wkinside and barup) then reftophi else if (wkinside and bardwn) then refbothi else na;
def botline2 = if (wkinside and barup) then reftoplo else if (wkinside and bardwn) then refbotlo else na;

# create a ref for line color
def istop = if bn == 1 then na else if lastbar then (wkinside and barup) else istop[1];
def isbot = if bn == 1 then na else if lastbar then (wkinside and bardwn) else isbot[1];

# price levels
def topline = if bn == 1 then na else if lastbar then topline2 else topline[1];
def botline = if bn == 1 then na else if lastbar then botline2 else botline[1];

#addlabel(1, "topline=" + topline, color.cyan);
#addlabel(1, "botline=" + botline, color.cyan);

plot z1 = topline;
plot z2 = botline;

z1.DefineColor("top", color.green);
z1.DefineColor("bot", color.red);
z1.DefineColor("xx", color.black);
z1.AssignValueColor( if istop then z1.color("top") else if isbot then z1.color("bot") else z1.color("xx") );
z1.SetStyle(Curve.MEDIUM_DASH);

z2.DefineColor("top2", color.green);
z2.DefineColor("bot2", color.red);
z2.DefineColor("xx2", color.black);
z2.AssignValueColor( if istop then z2.color("top2") else if isbot then z2.color("bot2") else z2.color("xx2") );
z2.SetStyle(Curve.MEDIUM_DASH);
#
U5kRn5z.jpg
 
Last edited:
Solution

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