• Memorial Day Sale! Claim the biggest discount of the year with $50 off VIP using code MEM50. Sign up here.

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

halcyonguy

Well-known member
VIP
Lifetime
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

Similar threads

Top