NexusFi: Find Your Edge


Home Menu

 





Average and Max Distance from EMA


Discussion in ThinkOrSwim

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




 
Search this Thread
  #1 (permalink)
konl
jerusalem israel
 
Posts: 5 since Jul 2017
Thanks Given: 0
Thanks Received: 0

I stuck with a problem and would appreciate getting a direction -
Want to plot (EMA8 + average price distance from EMA8 last year).
The same goes for (EMA8 + maximum distance from the EMA last year)
The main problem I encountered was to find the average distance in the past year and the maximum distance.
Again, I apologize for the digging but it's pretty stuck here


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
CFTC Requests Tag 50 Trader Identity Data From CME and I …
Traders Hideout
Iran Fired a Missile at Israel Last Night. The $8M June …
Prediction Markets & Event Contracts
Six Days to Kickoff: World Cup Prediction Markets Hit $1 …
Prediction Markets & Event Contracts
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
205 thanks
Sober Journey With S&P
21 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
Thanks Mike. Godspeed.
7 thanks
  #2 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 210


konl View Post
I stuck with a problem and would appreciate getting a direction -
Want to plot (EMA8 + average price distance from EMA8 last year).
The same goes for (EMA8 + maximum distance from the EMA last year)
The main problem I encountered was to find the average distance in the past year and the maximum distance.
Again, I apologize for the digging but it's pretty stuck here

You'd have to custom code this, I think. I don't recall anyone mentioning something that would do that for you 'out of the box'.

For the maximum distance, assuming you don't care whether price is above or below the EMA, you'd want to take the value of each and subtract them, then get the absolute value, Math.Abs(), store that in a variable and replace the value any time the current value is greater than what's already stored in the variable.

Something like this:
Diff = Math.Abs(EMA8 - Price)
if (Diff > Variable)
Variable = Diff

Then run that over the past year's historical price bars. The end value for Variable ought to be the maximum distance price was from the EMA over the year. Then you'll need to plot the value.

The average distance, again assuming you don't care which is higher, would be something like:
NewVariable = SMA(Diff)[365]
Meaning, plot some variable making it equal to a simple moving average of the absolute value of the difference between the EMA and price, making the period of the moving average = 1 year.

I'm not a master programmer and just sort of threw this together, so I might be making some dumb mistakes, but I think coding similar to this, conceptually, will get you what you want.


Follow me on X Reply With Quote
  #3 (permalink)
konl
jerusalem israel
 
Posts: 5 since Jul 2017
Thanks Given: 0
Thanks Received: 0



DavidBodhi View Post
You'd have to custom code this, I think. I don't recall anyone mentioning something that would do that for you 'out of the box'.

For the maximum distance, assuming you don't care whether price is above or below the EMA, you'd want to take the value of each and subtract them, then get the absolute value, Math.Abs(), store that in a variable and replace the value any time the current value is greater than what's already stored in the variable.

Something like this:
Diff = Math.Abs(EMA8 - Price)
if (Diff > Variable)
Variable = Diff

Then run that over the past year's historical price bars. The end value for Variable ought to be the maximum distance price was from the EMA over the year. Then you'll need to plot the value.

The average distance, again assuming you don't care which is higher, would be something like:
NewVariable = SMA(Diff)[365]
Meaning, plot some variable making it equal to a simple moving average of the absolute value of the difference between the EMA and price, making the period of the moving average = 1 year.

I'm not a master programmer and just sort of threw this together, so I might be making some dumb mistakes, but I think coding similar to this, conceptually, will get you what you want.

Thank you for replay


Reply With Quote
  #4 (permalink)
 jeffro 
San Diego, CA/United States
 
Experience: Intermediate
Platform: TOS
Trading: ES, CL, 6A
Posts: 17 since Apr 2015
Thanks Given: 2
Thanks Received: 12

You'd need to define at what scale, time or tick over the past year. But this can be done.


Reply With Quote




Last Updated on July 10, 2018


© 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