Time Anchored Line showing for Last 5 Days

jack1

New member
Hi All ! Mobius posted this Anchored Line at Time indicator in the Lounge in the past ; but it shows the current day only. Is it possible to have this Line at Time show on eash of the previous 5 days or whatever number selected. I appreciate any help. Thanks. # Ruby: # Time Anchored Plot To Current Close with Slope
# Mobius
# V02.01.07.2016
# Simplified Code form V01.2011 version
input BeginTime = 1030;
input X_value = close;
input Display_Label = yes;
def Active = if SecondsTillTime(BeginTime) == 0 and
SecondsFromTime(BeginTime) == 0 and
GetDay() == GetLastDay()
then 1
else 0;
def X = if Active
then X_value
else X[1];
plot Line = if Active
then X
else if IsNaN(close[-1])
then close
else Double.NaN;
Line.EnableApproximation();
Line.SetStyle(Curve.FIRM);
Line.SetDefaultColor(Color.CYAN);
def z = if Active
then X
else if IsNaN(close[-1])
then HighestAll(X)
else Double.NaN;
def FirstBar = if Active
then BarNumber()
else Double.NaN;
plot zero = if BarNumber() == HighestAll(FirstBar)
then X
else if BarNumber() > HighestAll(FirstBar)
then X
else Double.NaN;
zero.SetDefaultColor(Color.CYAN);
# End Code Anchored Line
 
Solution
Hi All ! Mobius posted this Anchored Line at Time indicator in the Lounge in the past ; but it shows the current day only. Is it possible to have this Line at Time show on eash of the previous 5 days or whatever number selected. I appreciate any help. Thanks. hal_2pts hal_last hal_slope # Ruby...
Hi All ! Mobius posted this Anchored Line at Time indicator in the Lounge in the past ; but it shows the current day only. Is it possible to have this Line at Time show on eash of the previous 5 days or whatever number selected. I appreciate any help. Thanks. hal_2pts hal_last hal_slope # Ruby: # Time Anchored Plot To Current Close with Slope
# Mobius
# V02.01.07.2016
# Simplified Code form V01.2011 version
input BeginTime = 1030;
input X_value = close;
input Display_Label = yes;
def Active = if SecondsTillTime(BeginTime) == 0 and
SecondsFromTime(BeginTime) == 0 and
GetDay() == GetLastDay()
then 1
else 0;
def X = if Active
then X_value
else X[1];
plot Line = if Active
then X
else if IsNaN(close[-1])
then close
else Double.NaN;
Line.EnableApproximation();
Line.SetStyle(Curve.FIRM);
Line.SetDefaultColor(Color.CYAN);
def z = if Active
then X
else if IsNaN(close[-1])
then HighestAll(X)
else Double.NaN;
def FirstBar = if Active
then BarNumber()
else Double.NaN;
plot zero = if BarNumber() == HighestAll(FirstBar)
then X
else if BarNumber() > HighestAll(FirstBar)
then X
else Double.NaN;
zero.SetDefaultColor(Color.CYAN);
# End Code Anchored Line


this will draw diagonal lines, on each day, from a start time to an end time.

it finds the last bar of the day.
if the end time is 1600, then it subtracts the chart agg minutes to find the last bar of the day, normal trading hours.
(1600 , 4pm, is the start of after hours. if after hours are turned off, looking for a bar at 4pm will not be found)

link to other similar at end of this post.

Code:
# Anchored_Line_mobius_01_mod

#https://usethinkscript.com/threads/time-anchored-line-showing-for-last-5-days.13887/
#Time Anchored Line showing for Last 5 Days

# Mobius
# V02.01.07.2016
# Simplified Code form V01.2011 version
#
# modified by halcyonguy to draw lines on each day

def bn = barnumber();
def na = double.nan;
def diffday = if getday() != getday()[1] then 1 else 0;

input BeginTime = 1030;
input endtime = 1600;

addlabel((begintime > endtime), " ---------   ERROR , BEGIN TIME IS AFTER END TIME.  CHANGE START AND END TIMES   --------- ", COLOR.CYAN);

#input X_value = close;
#input Display_Label = yes;
#def Active = if SecondsTillTime(BeginTime) == 0 and SecondsFromTime(BeginTime) == 0 and GetDay() == GetLastDay() then 1 else 0;
#def X = if Active then X_value else X[1];


def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#addlabel(yes, chartmin + " min", color.yellow);

#def isaggfactor = if ((SecondsFromTime(BeginTime)/60) % chartmin == 0) then 1 else 0;
def endtimeadj = if endtime == 1600 then 1560 - chartmin else endtime;

def start3 = if SecondsTillTime(BeginTime) == 0 and SecondsFromTime(BeginTime) == 0 then 1 else 0;
def end3 = if SecondsTillTime(endtimeadj) == 0 and SecondsFromTime(endtimeadj) == 0 then 1 else 0;


# each day, look for start and end bars, read bn
# read close from srtart and end bars
# calc slope between the 2 bars
def startoff;
def endoff;
def startbn;
def endbn;
def startpr;
def endpr;
if bn == 1 or diffday then {
  startoff = (fold i = 0 to 400
    with p
    while getvalue(getday(),-i) == getday() and !getvalue(start3, -i)
    do p + 1);
  endoff = (fold j = 0 to 400
    with q
    while getvalue(getday(),-j) == getday() and !getvalue(end3, -j)
    do q + 1);

  startbn = bn + startoff;
  endbn = bn + endoff;
  startpr = getvalue(close, -startoff);
  endpr = getvalue(close, -endoff);
} else {
  startoff = startoff[1];
  endoff = endoff[1];
  startbn = startbn[1];
  endbn = endbn[1];
  startpr = startpr[1];
  endpr = endpr[1];
}

def prz = (endpr - startpr);
def barz = (endbn - startbn);
def barslope = prz/barz;

def diag = if bn == startbn then startpr
  else if (bn >= startbn and bn <= endbn) then diag[1] + barslope
  else na;

# diagonal line, start to end, each day
plot z1 = diag;
z1.SetDefaultColor(Color.CYAN);


# orig diagonal line
#plot Line = if Active then X
#  else if IsNaN(close[-1]) then close
#  else Double.NaN;
#Line.EnableApproximation();
#Line.SetStyle(Curve.FIRM);
#Line.SetDefaultColor(Color.CYAN);

#def z = if Active then X
#  else if IsNaN(close[-1]) then HighestAll(X)
#  else Double.NaN;

#def FirstBar = if Active then BarNumber()
#  else Double.NaN;

# horz line
#plot zero = if BarNumber() == HighestAll(FirstBar) then X
#  else if BarNumber() > HighestAll(FirstBar) then X
#  else Double.NaN;
#zero.SetDefaultColor(Color.white);

# End Code Anchored Line


#------------------------
# test stuff

input test_vertical_lines = no;
addverticalline(test_vertical_lines and start3, "-", color.green);
addverticalline(test_vertical_lines and end3, "-", color.red);


input test_bubble = no;
addchartbubble(test_bubble, low*0.997,
 bn + "\n" +
 startoff + "\n" +
 startbn + "\n" +
 startpr + "\n" +
 "\n" +
 endoff + "\n" +
 endbn + "\n" +
 endpr + "\n" +
 "\n" +
 prz + "\n" +
 barz + " bz\n" +
 barslope + " slop"
, (if startbn == bn or endbn == bn then color.yellow else color.gray), no);
#

2hicvpk.jpg




another post with similar studies
https://usethinkscript.com/threads/how-to-plot-a-line-between-2-points.6945/
 
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
329 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