NexusFi: Find Your Edge


Home Menu

 





Help with writing script for average daily price


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,387 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?
No book, only a stair: journaling fills where price move …
Cryptocurrency
EA
Platforms and Indicators
My Rant with AMP Futures
Trading Reviews and Vendors
Datafeed for Atas
Platforms and Indicators
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Mes vs MNQ
6 thanks
NexusFi site changelog and issues/problem reporting
5 thanks
BERN ALGOS algo trading journal
3 thanks
TopStep Trader disappointment
2 thanks
Johnnys Journal
2 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