Ability to look back last 30 days and post list on left side of screen.

tommytx

New member
VIP
I want put together a study using think script that will look back 30 days and post the 2:00 pm high and the closing high for each day.
For example at the top left of the screen in vertical fashion vice the usual horizontal fashion.
Would look like this at top left of screen

25 Jan 6010 6020 +5
26 Jan 6012 6010 -2
27 Jan 6060 6035 -25
28 Jan 6019 6019 0
29 Jan 6037 6047 +10
30 Jan 6067 6097 +37

This would print for current date back 30 days then calculate the difference and place it in a 3rd column with proper sign - or +
It would start with current day on top and continue day by day till it competes back 30 days from start.
It would work on what ever symbol you were using at the time

Could anyone help me set this thing up please....

Will not need these headers posted to the screen but it may clarify what I am trying to do
Date 2:pM 4:pM Diff
25 Jan 6010 6020 +5

I really want this data to print to a text file rather than on the desktop but
right now that is more than i want to chew... Once this works i may try to
add capability to print to text.

So bottom line to make sure its clear, I want to collect the closing of the 2:00 pm candle
and the 4:00 pm candle and log then as shown.

Thanks for any suggestions or help.

Thank you so much for offering help with this..
1. The error in diff for the one item is a typo. it was manually typed on screen.
2. I think it would be sufficient to use Day and maybe a one hour for candles as I only
need the closing value of the 1400 and 1600 candle.
3. Just the days of live trading would be all that is needed
So no need for any number of days just the days of trading live for each month.
So if the number of trading days is 20 or 30 it matters not.. just active days.

4. one hour candles should work as that would be reading back no more than 24 candles
as it should only need to read one month so my guess it would be best to have only a
month on page so it will only read the month on the screen. and would only print maybe
20 24 lines on the screen since each month will be different as long as it prints the
1400 and 1600 for each trading day of the month. And it only needs to run once.. not a loop
That would just be wasteful. Once I learn more about what I am doing i would like to dump into a text file on the hard drive and it could then be looked at anytime after it ran..

Thanks
James
 
Solution
I want put together a study using think script that will look back 30 days and post the 2:00 pm high and the closing high for each day.
For example at the top left of the screen in vertical fashion vice the usual horizontal fashion.
Would look like this at top left of screen

25 Jan 6010 6020 +5
26 Jan 6012 6010 -2
27 Jan 6060 6035 -25
28 Jan 6019 6019 0
29 Jan 6037 6047 +10
30 Jan 6067 6097 +37

This would print for current date back 30 days then calculate the difference and place it in a 3rd column with proper sign - or +
It would start with current day on top and continue day by day till it competes back 30 days from start.
It would work on what ever symbol you were using at the time

Could anyone help me set...
I want put together a study using think script that will look back 30 days and post the 2:00 pm high and the closing high for each day.
For example at the top left of the screen in vertical fashion vice the usual horizontal fashion.
Would look like this at top left of screen

25 Jan 6010 6020 +5
26 Jan 6012 6010 -2
27 Jan 6060 6035 -25
28 Jan 6019 6019 0
29 Jan 6037 6047 +10
30 Jan 6067 6097 +37

This would print for current date back 30 days then calculate the difference and place it in a 3rd column with proper sign - or +
It would start with current day on top and continue day by day till it competes back 30 days from start.
It would work on what ever symbol you were using at the time

Could anyone help me set this thing up please....

Will not need these headers posted to the screen but it may clarify what I am trying to do
Date 2:pM 4:pM Diff
25 Jan 6010 6020 +5

I really want this data to print to a text file rather than on the desktop but
right now that is more than i want to chew... Once this works i may try to
add capability to print to text.

So bottom line to make sure its clear, I want to collect the closing of the 2:00 pm candle
and the 4:00 pm candle and log then as shown.

Thanks for any suggestions or help.


this works for normal stocks on normal days. (since no mention was made of the desired data).
if someone wants this to work on futures data, which has a trading period that spans over midnight, changes will have to be made, that define a newday.

this shows a stack of 10 bubbles.
each bubble shows,
. a date
. price from some time. (defaults, 2pm and high)
. price from the last bar of the day (high)
. price difference of those 2 prices. if difference is pos, then label is green. if neg then red.


you said (pm high and) closing high, which doesn't make sense. do you mean high of the last bar of day?
then at the end, you say close, so i don't know what you want. i left it as high. it is user changable.


the bubbles are on the first day on the chart, based on a bar number. default = 2.
. input bubnum = 2;
change to a bigger number to move the bubbles to the right (a later day).

this starts with the current day at the top, and older dates below it.
if the time hasn't occured yet, the price will be 0.

this was tricky, because it reads data at many moments in time, but displays all of it during 1 moment in time.
you can't count on there being the same quantity of bars on every day , for every stock. so you can't use offsets.

i made a day counter to count the days on the chart.
it reads a price at 2 bars of each day.


if someone wants more than 10 bubbles, they can copy a few sets of formulas and change the number in variable names.

for testing,
. i used a 30day 30min chart time
. i added bubbles to display a price, for every desired time


Code:
#look_back_xdays_2pm

#https://usethinkscript.com/threads/ability-to-look-back-last-30-days-and-post-list-on-left-side-of-screen.20449/#post-150169
# look back 30 days and post the 2:00 pm high and the closing high for each day.
# For example at the top left of the screen in vertical fashion vice the usual horizontal fashion.
# Would look like this at top left of screen
#25 Jan 6010 6020 +5
#26 Jan 6012 6010 -2
#27 Jan 6060 6035 -25
#28 Jan 6019 6019 0
#29 Jan 6037 6047 +10
#30 Jan 6067 6097 +37



def na = double.nan;
def bn = barnumber();
def d = getday();
def newday = d != d[1];
# couts days in expan area
#def daycnt = if bn == 1 then 1 else if newday then daycnt[1]+1 else daycnt[1];
# counts only days with bars
def daycnt = if bn == 1 then 1 else if newday and !isnan(close) then daycnt[1]+1 else daycnt[1];
def maxday = highestall(daycnt);
def revdaycnt = if isnan(close) then 0 else (maxday-daycnt+1);

#----------------------------
# date_mo_day_yr_mobius
# from tos chat - mobius
def data = getYYYYMMDD();
def year = Round(data/10000, 0);
def month = Round((data % 10000) / 100, 0);
def day = (data % 100);
#addLabel(1, "date: " + month + "/" + day + "/" + AsPrice(year), color.white);
#----------------------------



#----------------------------
input start = 0930;
input time1 = 1400;
input end = 1600;
#def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
#def startbar = (secondsfromTime(start) == 0);
def t1 = (secondsfromTime(time1) == 0);
#def t2 = (secondsfromTime(end) == 0);
#time_lines1_nearest
# nearest bar
#def firstbar = SecondsFromTime(start)[1] < 0 and SecondsFromTime(start) >= 0;


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

#https://usethinkscript.com/threads/finding-the-first-and-last-bar-of-the-day-in-thinkorswim.526/
def Offset = 0;
#input day_first_last_bars = yes;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if
    (beforeStart[1+offset] == 1 and beforeStart[offset] == 0) or
    (isRollover[offset] and beforeStart[offset] == 0)
    then 1
    else 0;
def lastBarOfDay = if
    (afterEnd[-1-offset] == 1 and afterEnd[offset] == 0) or
    (isRollover[-1-offset] and firstBarOfDay[-1-offset])
    then 1
    else 0;
#AddChartBubble(day_first_last_bars and firstBarOfDay, high, "First", Color.GREEN, yes);
#AddChartBubble(day_first_last_bars and lastBarOfDay and lastBarOfDay[1] == 0, high, "Last", Color.GREEN, yes);
def t2 = lastbarofday;

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

input price1 = high;
def p = round(price1,2);
def t1pr01x = if bn == 1 then 0 else if t1 then p else t1pr01x[1];
def t2pr01x = if bn == 1 then 0 else if t2 then p else t2pr01x[1];

input test1 = yes;
addchartbubble(test1 and t1, low,
t1pr01x
, color.yellow, no);

addchartbubble(test1 and t2, low,
#"day " + daycnt + "\n" +
#"day " + revdaycnt + "\n" +
t2pr01x
, color.cyan, no);


input test2 = no;
addchartbubble(test2 and newday, 50,
"day " + daycnt + "\n" +
"day " + revdaycnt + "\n" 
, color.cyan, yes);


#----------------------------
def hihi = highestall(high);
plot zhi = hihi;
#def lolo = lowestall(low);
#plot zlo = lolo;

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

def cntx = revdaycnt;
def t1pr01 = highestall(if cntx == 1 and t1 then p else 0);
def t2pr01 = highestall(if cntx == 1 and t2 then p else 0);
def t1pr02 = highestall(if cntx == 2 and t1 then p else 0);
def t2pr02 = highestall(if cntx == 2 and t2 then p else 0);
def t1pr03 = highestall(if cntx == 3 and t1 then p else 0);
def t2pr03 = highestall(if cntx == 3 and t2 then p else 0);
def t1pr04 = highestall(if cntx == 4 and t1 then p else 0);
def t2pr04 = highestall(if cntx == 4 and t2 then p else 0);
def t1pr05 = highestall(if cntx == 5 and t1 then p else 0);
def t2pr05 = highestall(if cntx == 5 and t2 then p else 0);

def t1pr06 = highestall(if cntx == 6 and t1 then p else 0);
def t2pr06 = highestall(if cntx == 6 and t2 then p else 0);
def t1pr07 = highestall(if cntx == 7 and t1 then p else 0);
def t2pr07 = highestall(if cntx == 7 and t2 then p else 0);
def t1pr08 = highestall(if cntx == 8 and t1 then p else 0);
def t2pr08 = highestall(if cntx == 8 and t2 then p else 0);
def t1pr09 = highestall(if cntx == 9 and t1 then p else 0);
def t2pr09 = highestall(if cntx == 9 and t2 then p else 0);
def t1pr10 = highestall(if cntx == 10 and t1 then p else 0);
def t2pr10 = highestall(if cntx == 10 and t2 then p else 0);

# to display more data copy t1pr10 and t2pr10 formulas

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

def diff1 = t2pr01-t1pr01;
def diff2 = t2pr02-t1pr02;
def diff3 = t2pr03-t1pr03;
def diff4 = t2pr04-t1pr04;
def diff5 = t2pr05-t1pr05;

def diff6 = t2pr06-t1pr06;
def diff7 = t2pr07-t1pr07;
def diff8 = t2pr08-t1pr08;
def diff9 = t2pr09-t1pr09;
def diff10 = t2pr10-t1pr10;


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

def d1m = highestall(if cntx == 1 then month else 0);
def d1d = highestall(if cntx == 1 then day else 0);
def d2m = highestall(if cntx == 2 then month else 0);
def d2d = highestall(if cntx == 2 then day else 0);
def d3m = highestall(if cntx == 3 then month else 0);
def d3d = highestall(if cntx == 3 then day else 0);
def d4m = highestall(if cntx == 4 then month else 0);
def d4d = highestall(if cntx == 4 then day else 0);
def d5m = highestall(if cntx == 5 then month else 0);
def d5d = highestall(if cntx == 5 then day else 0);

def d6m = highestall(if cntx == 6 then month else 0);
def d6d = highestall(if cntx == 6 then day else 0);
def d7m = highestall(if cntx == 7 then month else 0);
def d7d = highestall(if cntx == 7 then day else 0);
def d8m = highestall(if cntx == 8 then month else 0);
def d8d = highestall(if cntx == 8 then day else 0);
def d9m = highestall(if cntx == 9 then month else 0);
def d9d = highestall(if cntx == 9 then day else 0);
def d10m = highestall(if cntx == 10 then month else 0);
def d10d = highestall(if cntx == 10 then day else 0);

# to display more data copy d10m and d10d formulas


#----------------------------
#input sp = "  ";
input sp = "|";
input bub = yes;
input bubnum = 2;
addchartbubble(bub and bn == bubnum, hihi, (d1m+"/"+d1d+sp+t1pr01+sp+t2pr01+sp+diff1), (if diff1 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d2m+"/"+d2d+sp+t1pr02+sp+t2pr02+sp+diff2), (if diff2 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d3m+"/"+d3d+sp+t1pr03+sp+t2pr03+sp+diff3), (if diff3 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d4m+"/"+d4d+sp+t1pr04+sp+t2pr04+sp+diff4), (if diff4 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d5m+"/"+d5d+sp+t1pr05+sp+t2pr05+sp+diff5), (if diff5 > 0 then color.green else color.red), no);

addchartbubble(bub and bn == bubnum, hihi, (d6m+"/"+d6d+sp+t1pr06+sp+t2pr06+sp+diff6), (if diff6 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d7m+"/"+d7d+sp+t1pr07+sp+t2pr07+sp+diff7), (if diff7 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d8m+"/"+d8d+sp+t1pr08+sp+t2pr08+sp+diff8), (if diff8 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d9m+"/"+d9d+sp+t1pr09+sp+t2pr09+sp+diff9), (if diff9 > 0 then color.green else color.red), no);
addchartbubble(bub and bn == bubnum, hihi, (d10m+"/"+d10d+sp+t1pr10+sp+t2pr10+sp+diff10), (if diff10 > 0 then color.green else color.red), no);

# to display more data copy the last bubble code line

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

Attachments

  • 00c-img1.JPG
    00c-img1.JPG
    144.6 KB · Views: 14
Solution
I want put together a study using think script that will look back 30 days and post the 2:00 pm high and the closing high for each day.
For example at the top left of the screen in vertical fashion vice the usual horizontal fashion.
Would look like this at top left of screen

25 Jan 6010 6020 +5
26 Jan 6012 6010 -2
27 Jan 6060 6035 -25
28 Jan 6019 6019 0
29 Jan 6037 6047 +10
30 Jan 6067 6097 +37

This would print for current date back 30 days then calculate the difference and place it in a 3rd column with proper sign - or +
It would start with current day on top and continue day by day till it competes back 30 days from start.
It would work on what ever symbol you were using at the time

Could anyone help me set this thing up please....

Will not need these headers posted to the screen but it may clarify what I am trying to do
Date 2:pM 4:pM Diff
25 Jan 6010 6020 +5

I really want this data to print to a text file rather than on the desktop but
right now that is more than i want to chew... Once this works i may try to
add capability to print to text.

So bottom line to make sure its clear, I want to collect the closing of the 2:00 pm candle
and the 4:00 pm candle and log then as shown.

Thanks for any suggestions or help.

here is info on collecting data in excel
https://usethinkscript.com/threads/...excel-using-the-rtd-function.5709/#post-76614
 
Last edited:

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