Average from open till now

Lookdown

New member
Hello experts, I'm new to thinkscript. I'd like to create an indicator to plot the average price from market open 0930 till now. However I only see moving averages in the library. Is there a way to do so? I tried to explore with function secondsFromTime and iteration fold+while but didn't figure out. Any suggestions will be greatly apprecated!
 
Hello experts, I'm new to thinkscript. I'd like to create an indicator to plot the average price from market open 0930 till now. However I only see moving averages in the library. Is there a way to do so? I tried to explore with function secondsFromTime and iteration fold+while but didn't figure out. Any suggestions will be greatly apprecated!

you could add up close prices during a day.
and add up the bars during a day.
then divide them to get an average

Code:
#day_avg
#https://usethinkscript.com/threads/average-from-open-till-now.18062/

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

input start = 0930;
input end = 1600;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;
def day_start = (secondsfromTime(start) == 0);
def day_end = (secondsfromTime(end) == 0);

# add up close prices during a day
# cnt the bars during a day
def day_total;
def day_cnt;
if bn == 1 then {
  day_total = 0;
  day_cnt = 0;
} else if day_start then {
  day_total = close;
  day_cnt = 1;
} else if daytime then {
  day_total = day_total[1] + close;
  day_cnt = day_cnt[1] + 1;
} else {
  day_total = day_total[1];
  day_cnt = day_cnt[1];
}

def avg = (day_total / day_cnt);
# skip day last bar, so line doesn't cross from day to day
def daytime2 = if daytime and getday() == getday()[-1] then 1 else 0;

plot a = if daytime2 then avg else double.nan;
a.SetDefaultColor(Color.white);
a.setlineweight(1);
a.hidebubble();
#
 

Attachments

  • img1.JPG
    img1.JPG
    70.2 KB · Views: 40

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hello experts, I'm new to thinkscript. I'd like to create an indicator to plot the average price from market open 0930 till now. However I only see moving averages in the library. Is there a way to do so? I tried to explore with function secondsFromTime and iteration fold+while but didn't figure out. Any suggestions will be greatly apprecated!
here is another way, with volume
https://usethinkscript.com/threads/...running-average-from-there.14685/#post-121102
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
313 Online
Create Post

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