Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
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.
|
|
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
|
|
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.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Yes, you have it exactly right.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/6/2014 Posts: 34
|
Thank you so much Bruce, you've made my life so much more easier.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |