NexusFi: Find Your Edge


Home Menu

 





Help with writing script for average daily price


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,316 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?
Four New E-mini Futures Launch June 29 -- Russell 3000, …
Emini and Emicro Index
Iran and Israel Stand Down: What $9M in Peace Contracts …
Prediction Markets & Event Contracts
Irans Answer Due Today: Peace Surges to 33.5%, Invasion …
Prediction Markets & Event Contracts
Hormuz Completely Closed: US Strikes Day 2, Iran Shoots …
Traders Hideout
Post-Summit Scorecard: $36M in May 15 Bets Settle Near-Z …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 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