I want to return the price value of the previous day's close on the last minute of the 1 minute aggregation.
is there a tutorial or reference that I can read to understand how to do this? or simple line of code that I can learn from? any examples already done on this?
def firstBar = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBar = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollover[-1] and firstBar[-1]) then 1 else 0;
plot x1 = lastbar; # this shows a boolean value either on or off, one or zero.
plot x2 = close lastbar; #this gives a syntax error. I want to plot the close of the last bar. the label correctly shows the...
I want to return the price value of the previous day's close on the last minute of the 1 minute aggregation.
is there a tutorial or reference that I can read to understand how to do this? or simple line of code that I can learn from? any examples already done on this?
I have created the following script which is time consuming for the user, each day to input the previous day's close price from the close of the last minute candle
I want to replace the input price line with some code that retrieves the previous day's close (last minute candle). it is important that the aggregation period remains on the one minute chart.
so replace input ClosePrice1 = 1.11; with the code that looks at the previous day's last minute close price. seems simple enough. so that the user doesn't have to day by day have to reset it.
declare lower;
input getTicker1 = "";
input ClosePrice1 = 1.11; # please replace this line of code with something that automatically retrieves the previous day's close of the last one minute candle
I have created the following script which is time consuming for the user, each day to input the previous day's close price from the close of the last minute candle
I want to replace the input price line with some code that retrieves the previous day's close (last minute candle). it is important that the aggregation period remains on the one minute chart.
so replace input ClosePrice1 = 1.11; with the code that looks at the previous day's last minute close price. seems simple enough. so that the user doesn't have to day by day have to reset it.
declare lower;
input getTicker1 = "";
input ClosePrice1 = 1.11; # please replace this line of code with something that automatically retrieves the previous day's close of the last one minute candle
I spend at least 10 hours dissecting that code from the last time I asked and this was answered with this link.
I really can't find any way of getting this to work.
that code is getting a label. what I need is for it to plot a line
I can't figure out the syntax
def firstBar = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBar = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollover[-1] and firstBar[-1]) then 1 else 0;
plot x1 = lastbar; # this shows a boolean value either on or off, one or zero.
plot x2 = close lastbar; #this gives a syntax error. I want to plot the close of the last bar. the label correctly shows the last bar close. but not when I try to plot it.
def firstBar = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBar = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollover[-1] and firstBar[-1]) then 1 else 0;
plot x1 = lastbar; # this shows a boolean value either on or off, one or zero.
plot x2 = close lastbar; #this gives a syntax error. I want to plot the close of the last bar. the label correctly shows the last bar close. but not when I try to plot it.
that code line fails because , close lastbar , isn't a valid formula .
here is a modified version of your code. i added a bubble to display ,
the close of the last bar of the day
and the day close and previous day close
sometimes they match, sometimes they don't. maybe someone else can explain why
on the last bar of the day, this formula updates the variable to be the close of the last bar, and keeps it until the next last bar.
def lastclose = if lastbar then close else lastclose[1];
Code:
# prevdaylastclose
#https://usethinkscript.com/threads/last-bar-close.11779/
#My last line has a syntax error. can someone help?
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBar = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBar = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollover[-1] and firstBar[-1]) then 1 else 0;
def lastclose = if lastbar then close else lastclose[1];
#-----------------------
def agg = aggregationPeriod.day;
def close_agg = close(period = agg);
def prevdayclose = close_agg[1];
#------------------------
AddChartBubble( 1
, (if lastbar then high*1.01 else low*0.99),
lastclose + " last bar\n" +
"\n" +
close_agg + " day close\n" +
prevdayclose + " prev day close\n"
, (if lastbar then Color.yellow else color.gray)
, (if lastbar then yes else no));
AddChartBubble( 0 and lastBar, close,
"Last Bar",
Color.GREEN, no);
#plot x1 = lastbar;
# this shows a boolean value either on or off, one or zero.
#plot x2 = close lastbar;
#this gives a syntax error. I want to plot the close of the last bar. the label correctly shows the last bar close. but not when I try to plot it.
#
I have created the following script which is time consuming for the user, each day to input the previous day's close price from the close of the last minute candle
I want to replace the input price line with some code that retrieves the previous day's close (last minute candle). it is important that the aggregation period remains on the one minute chart.
so replace input ClosePrice1 = 1.11; with the code that looks at the previous day's last minute close price. seems simple enough. so that the user doesn't have to day by day have to reset it.
declare lower;
input getTicker1 = "";
input ClosePrice1 = 1.11; # please replace this line of code with something that automatically retrieves the previous day's close of the last one minute candle
Yes I think that works and now I can simply subtract the lastclose value to the current close to get a change of day. i want to learn from this excellent example.
that code line fails because , close lastbar , isn't a valid formula .
here is a modified version of your code. i added a bubble to display ,
the close of the last bar of the day
and the day close and previous day close
sometimes they match, sometimes they don't. maybe someone else can explain why
on the last bar of the day, this formula updates the variable to be the close of the last bar, and keeps it until the next last bar.
def lastclose = if lastbar then close else lastclose[1];
Code:
# prevdaylastclose
#https://usethinkscript.com/threads/last-bar-close.11779/
#My last line has a syntax error. can someone help?
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBar = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBar = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollover[-1] and firstBar[-1]) then 1 else 0;
def lastclose = if lastbar then close else lastclose[1];
#-----------------------
def agg = aggregationPeriod.day;
def close_agg = close(period = agg);
def prevdayclose = close_agg[1];
#------------------------
AddChartBubble( 1
, (if lastbar then high*1.01 else low*0.99),
lastclose + " last bar\n" +
"\n" +
close_agg + " day close\n" +
prevdayclose + " prev day close\n"
, (if lastbar then Color.yellow else color.gray)
, (if lastbar then yes else no));
AddChartBubble( 0 and lastBar, close,
"Last Bar",
Color.GREEN, no);
#plot x1 = lastbar;
# this shows a boolean value either on or off, one or zero.
#plot x2 = close lastbar;
#this gives a syntax error. I want to plot the close of the last bar. the label correctly shows the last bar close. but not when I try to plot it.
#
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.
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.