Horizontal line at midpoint of 1 min. bar for last 5 days

steve123

New member
Greetings coding wizards - your work is truly amazing and much appreciated! I am looking for a script to plot 5 horizontal lines on today's chart of the midpoint of a user-selected 1-min. bar during the the last 5 days. There would be 5 lines - one for each of the midpoints over the last 5 days. I am not able to script, just cobble bits and pieces together which sometimes work. Your work here is so valuable and appreciated!!!
 
Solution
Greetings coding wizards - your work is truly amazing and much appreciated! I am looking for a script to plot 5 horizontal lines on today's chart of the midpoint of a user-selected 1-min. bar during the the last 5 days. There would be 5 lines - one for each of the midpoints over the last 5 days. I am not able to script, just cobble bits and pieces together which sometimes work. Your work here is so valuable and appreciated!!!

this plots 5 lines, from 5 days, from a specified bar.
pick the bar by entering a number in hourminute format, HHMM (in EST)
the lines are from the middle of the candle body.
.. i made a 2nd formula that can be used, that calculates the middle of high to low.
can choose to plot lines only on current day...
Greetings coding wizards - your work is truly amazing and much appreciated! I am looking for a script to plot 5 horizontal lines on today's chart of the midpoint of a user-selected 1-min. bar during the the last 5 days. There would be 5 lines - one for each of the midpoints over the last 5 days. I am not able to script, just cobble bits and pieces together which sometimes work. Your work here is so valuable and appreciated!!!

this plots 5 lines, from 5 days, from a specified bar.
pick the bar by entering a number in hourminute format, HHMM (in EST)
the lines are from the middle of the candle body.
.. i made a 2nd formula that can be used, that calculates the middle of high to low.
can choose to plot lines only on current day or all 5 days
a label shows the time


Code:
#lines_5x_1bar_each_day
#https://usethinkscript.com/threads/horizontal-line-at-midpoint-of-1-min-bar-for-last-5-days.19394/
#Horizontal line at midpoint of 1 min. bar for last 5 days

# a script to plot 5 horizontal lines,
# on today's chart,
# of the midpoint of a user-selected 1-min. bar,
# during the the last 5 days.
#   There would be 5 lines - one for each of the midpoints over the last 5 days.


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

def d = GetDay();
def istoday = if GetLastDay() == d then 1 else 0;
def newday = if d != d[1] then 1 else 0;
def daycnt = if bn == 1 then 1 else if IsNaN(close) then 0 else if (!IsNaN(close) and newday) then daycnt[1] + 1 else daycnt[1];
def maxdays = HighestAll(daycnt);
def revdaycnt = maxdays - daycnt + 1;


# EST time  HHMM
input time = 1115;
def t1 = if SecondsFromTime(time)[1] < 0 and SecondsFromTime(time) >= 0 then 1 else 0;

def hr = floor(time / 100);
def mn = time - (hr * 100);
def start1minttl = (hr * 60) + mn;
def hrs = start1minttl/60;

addlabel(yes, (hr + ":" + mn), color.magenta);

def days_back = 5;

def mid = MidBodyVal();
#def mid = (high + low)/2;

def d1 = if bn == 1 or isnan(close) then 0 else if revdaycnt == 1 and t1 then mid else d1[1];
def d2 = if bn == 1 or isnan(close) then 0 else if revdaycnt == 2 and t1 then mid else d2[1];
def d3 = if bn == 1 or isnan(close) then 0 else if revdaycnt == 3 and t1 then mid else d3[1];
def d4 = if bn == 1 or isnan(close) then 0 else if revdaycnt == 4 and t1 then mid else d4[1];
def d5 = if bn == 1 or isnan(close) then 0 else if revdaycnt == 5 and t1 then mid else d5[1];

input today_only = yes;
def x = if !today_only then 1 else istoday;
def dayz = revdaycnt <= days_back and revdaycnt >= 1;

plot z1 = if x and d1 > 0 then d1 else na;
plot z2 = if x and d2 > 0 then d2 else na;
plot z3 = if x and d3 > 0 then d3 else na;
plot z4 = if x and d4 > 0 then d4 else na;
plot z5 = if x and d5 > 0 then d5 else na;

z1.SetDefaultColor(getColor(1));
z2.SetDefaultColor(getColor(2));
z3.SetDefaultColor(getColor(3));
z4.SetDefaultColor(getColor(4));
z5.SetDefaultColor(getColor(5));


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

def daystoomany = if days_back < 1 or days_back > maxdays then 1 else 0;
AddLabel(daystoomany, " ONLY " + maxdays + " DAYS ON CHART. enter a different number for days back", Color.CYAN);


input test1 = no;
AddChartBubble(test1, low,
newday + " new\n" +
daycnt + " cnt\n" +
revdaycnt + " rev\n" +
maxdays + " max\n" 
, (if dayz then Color.YELLOW else color.gray), no);


input test2_line = no;
addverticalline((test2_line and t1 and dayz), time, color.cyan);
#
 

Attachments

  • img1.JPG
    img1.JPG
    60 KB · Views: 54
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
475 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