10 Day Lookback Marker

Charlie.mp3

New member
Hi,
Can someone help me with some code for ToS on a 10 day look back marker? The 10 day isn't necessarily key, I just want a simple script that puts a dot or an arrow on top of a candle 10 days from the current candle in the past. This sounds awfully simple but I can't code to save my life.

I'd appreciate any help on this.

Thanks
Charlie.
 
Solution
Hi,
Can someone help me with some code for ToS on a 10 day look back marker? The 10 day isn't necessarily key, I just want a simple script that puts a dot or an arrow on top of a candle 10 days from the current candle in the past. This sounds awfully simple but I can't code to save my life.

I'd appreciate any help on this.

Thanks
Charlie.


i know this post is old, but i had the code in my head from another project, and i thought it might be of use.

enter a number for days back to look at.
whatever the current bar of day is, that same bar, on the desired day, will be identified with an arrow and a rectangle outline.

2 labels, list the day offset and the desired bar of day number.
if there aren't enough days on the chart, a...
Hi,
Can someone help me with some code for ToS on a 10 day look back marker? The 10 day isn't necessarily key, I just want a simple script that puts a dot or an arrow on top of a candle 10 days from the current candle in the past. This sounds awfully simple but I can't code to save my life.

I'd appreciate any help on this.

Thanks
Charlie.


i know this post is old, but i had the code in my head from another project, and i thought it might be of use.

enter a number for days back to look at.
whatever the current bar of day is, that same bar, on the desired day, will be identified with an arrow and a rectangle outline.

2 labels, list the day offset and the desired bar of day number.
if there aren't enough days on the chart, a cyan label message appears.

Ruby:
# days_back_00

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

input days_back = 10;

def lastbarbn = highestall((if !isnan(close) then bn else 0)) ;
def lastbar = if bn == lastbarbn then 1 else 0;

def dow = GetDayOfWeek(getyyyymmdd());
def newday = dow[1] <> dow;

# ---------------------------------------
# desired day on chart

# forward day count
def daycnt = if bn == 1 then 0
  else if newday then daycnt[1] + 1
  else daycnt[1];

# max day number
def max_daycnt = highestall((if lastbar then daycnt else 0)) ;

# reverse day count
def revdaycnt = max_daycnt - daycnt + 1;

# ---------------------------------------
# chk if desired < maxdays
def dayback_ok = ( days_back < max_daycnt);

# desired day in the past
def dayx = if days_back == revdaycnt then 1 else 0;

addlabel(!dayback_ok, ">>>> chart doesn't have " + days_back + " days <<<<", color.cyan);
addlabel(1, "days back " +  days_back + " / " + max_daycnt , color.yellow);

# ---------------------------------------
# desired bar of day (the current bar)

def barcnt = if bn == 1 then 0
  else if newday then 1
  else barcnt[1] + 1;

# bar count on last bar, the current bar
def desired_barcnt = highestall((if lastbar then barcnt else 0));

# max bar count
def max_barcnt = highestall(barcnt);

# desired bar in the past ( will trigger 1/day)
def barx = if barcnt == desired_barcnt then 1 else 0;

addlabel(1, "bar of day " + desired_barcnt + " / " + max_barcnt , color.yellow);

# ---------------------------------------
# desired bar in the past day
def bar_z = (dayx and barx);
# ---------------------------------------

input show_arrow_above_bar = yes;

def vert = 1.004;
plot bz = if (show_arrow_above_bar and bar_z) then (high * vert) else na;
bz.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bz.SetDefaultColor(Color.cyan);
bz.setlineweight(3);
bz.hidebubble();

# ---------------------------------------
# show a hollow candle surrounding the desired bar

input show_outline_around_bar = yes;
def soab = show_outline_around_bar;

def o = if (soab and bar_z) then open else na;
def h = if (soab and bar_z) then high else na;
def l = if (soab and bar_z) then low else na;
def c = if (soab and bar_z) then close else na;

def v = 0.01;
def o1 = (c * (1 + v));
def c1 = (o * (1 - v));
def h1 = (c * (1 + v));
def l1 = (o * (1 - v));

AddChart(growColor = Color.cyan, fallColor = Color.BLUE, neutralColor = Color.BLUE, high = h1, low = l1, open = c1, close = o1, type = ChartType.CANDLE);

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

input show_day_counts = yes;
addchartbubble(show_day_counts and newday, high*1.008, "F " + daycnt + "\nR " + revdaycnt, color.yellow, yes);

# ---------------------------------------
input show_test_bubble = no;
addchartbubble(show_test_bubble, low*0.99, bn 
+ "\nN" + newday 
+ "\nC" + daycnt
+ "\nD" + daycnt
+ "\nX" +  max_daycnt 
+ "\nR" + revdaycnt
+ "\n" + dayx
+ "\n" + barx
, (if bar_z then color.pink else if newday then color.cyan else if dayx then color.yellow else color.gray), no);

# ---------------------------------------
# addchart ref page
# https://usethinkscript.com/threads/candle-fill-color.6691/#post-70687
# post#9
#


cyan rectangle around desired bar
cyan arrow above desired bar
yellow bubble above 1st bar of day, day counts
test data bubbles,
..pink - desired bar in day (same as current bar)
..cyan - first bar of day
..yellow - desired day
tlVtUjz.jpg


day count
reverse day count
bar count
addcahrt
 
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
400 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