NexusFi: Find Your Edge


Home Menu

 





Help with writing script for average daily price


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,225 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
amiriny
new york, ny
 
Posts: 1 since Apr 2013
Thanks Given: 0
Thanks Received: 0

Hello, this is my first post here so would like to thank you in advance for sharing your knowledge.

Im trying to write a code that will plot the average daily price, starting at 9:30 am ET on the /ES 5 min chart for example.

The logic is as follows:

After the second bar is closed (at 9:40 am), the average will be AVG_1=(close+close[1])/2.
As the 3rd bar closes (at 9:45), the average will be AVG_2=(close+close[1]+close[1])/3 or AVG2=(AVG_1+close)/2...and so on
until the market closes. Restart the calculation on the next day at 9:30.

It's the same logic as VWAP, but no volume only price
.

Thanks again for your assistance.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Rubios Good News Within Hours and the 30-Day Math: Why H …
Prediction Markets & Event Contracts
May 26 Deadline Dies at 7.5% as US Strikes Iran During C …
Prediction Markets & Event Contracts
CPI Eve: Fed Hike Odds Hold at 52% for the First Time, I …
Prediction Markets & Event Contracts
Trump Truth Social Fires Hormuz From 10% to 59% -- Arsen …
Prediction Markets & Event Contracts
Bond Market Rout -- Worst Week Since Russias 2022 Invasi …
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
2026 Fire Horse
5 thanks
  #2 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43

I think this is what you're looking for...

 
Code
def firstBar = SecondsFromTime(930) == 0;
def isOpen = SecondsFromTime(930) >= 0;
def priceTotal = if firstBar then close else if isOpen then priceTotal[1] + close else 0;
def priceCount = if firstBar then 1 else if isOpen then priceCount[1] + 1 else 0;
plot averagePrice = priceTotal / priceCount;


Reply With Quote




Last Updated on October 14, 2020


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts