Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

exponential moving average Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
ansinzhou
Posted : Tuesday, October 21, 2014 1:27:46 PM
Registered User
Joined: 10/6/2014
Posts: 34

Hi bruce, 

 Thank you for bearing with me as I am new to realcoding. 

 I'm trying to find the three day exponential moving average for a variable (Var2)  I created

 How would I find the realcode for that? 

 Dim Var2 As Single
 Var2 = price.Close * volume.Close
 
Thank you.
Bruce_L
Posted : Tuesday, October 21, 2014 1:44:34 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

There is no built in syntax for this.

The built in way to do this would be to just output Var2 as its own indicator. You could then drag and drop that indicator (or a moving average of that indicator) into your RealCode to reference it.

If you really want to do this entirely in RealCode, you could do something like the following.

Dim Var2 As Single
Var2 = Price.Close * Volume.Value
Static EMA As Single
Static sumWeight As Single
Static termRatio As Single
If isFirstBar Then
	EMA = Var2
	termRatio = 2 / 4
	sumWeight = termRatio + 1
Else
	Dim Weight As Single = 1 / sumWeight
	EMA = EMA * (1 - Weight) + Weight * Var2
	sumWeight = sumWeight * termRatio + 1
End If


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
ansinzhou
Posted : Tuesday, October 21, 2014 1:57:35 PM
Registered User
Joined: 10/6/2014
Posts: 34

Hi Burce, 

I outputed Var2 as its own indicator. and would I refrence it by using coding like this? 

 '# Var2 = chart.Var2
 
Dim Var3 As Single
Var3 = Var2.XAVG(3)
 
Thank you. 
Bruce_L
Posted : Tuesday, October 21, 2014 2:02:06 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Yes, you have it exactly right.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
ansinzhou
Posted : Tuesday, October 21, 2014 2:04:35 PM
Registered User
Joined: 10/6/2014
Posts: 34

Thank you so much Bruce, you've made my life so much more easier.  

Bruce_L
Posted : Tuesday, October 21, 2014 2:08:43 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

You're welcome.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.