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 |

macd; my RealCode must be wrong, indicater looks wrong. Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jrf-wood
Posted : Thursday, August 26, 2010 10:34:35 PM
Registered User
Joined: 7/19/2010
Posts: 23

my macd RealCode does not plot like yours. I must be doing somthing wrong?
My code is from; "a quick tutorial in macd, by g. and m. apple" found on
"www.signalert.com%20TUTORIAL.PDF"

Please find my RealCode below. It is normalzed w/ n26. It does not look like your macd;
"macd simple,12,simple,26 (simple,moving 9). I have tried w/ and w/ out smoothing constants etc.
can not get it to look like yours!  There is smothing wrong w/ my understanding of RealCode.


'|*** Indicator:pmacdsl  ((no signal line plot))
Static n26 As Integer = 26
Static n12 As Integer = 12
Static n9 As Integer = 9
Static s1 As Single = 2 / (n12 + 1)
Static s2 As Single = 2 / (n26 + 1)
Static s3 As Single = 2 / (n9 + 1)
Dim avg26 As Single
Dim avg12 As Single
Dim avg9 As Single
Dim pa1 As Single
Dim pa2 As Single
Dim pa3 As Single
Dim dl As Single

If currentindex < n26 Then
 Me.setindexinvalid
else
 avg12 = price.AVG(n12, 1)
 avg26 = price.AVG(n26, 1)
 'avg9 = price.AVG(n9, 1)
 pa1 = avg12 + s1 * (price.Close - avg12)
 pa2 = avg26 + s2 * (price.Close - avg26)
 'pa3 = avg9 + s3 * (price.Close - avg9)

 dl = (pa1 - pa2)
 plot = DL / PA2
End If

'|*** Indicator:pmacdsl     ((signal only))
'|******************************************************************
Static n26 As Integer = 26
Static n12 As Integer = 12
Static n9 As Integer = 9
Static s1 As Single = 2 / (n12 + 1)
Static s2 As Single = 2 / (n26 + 1)
Static s3 As Single = 2 / (n9 + 1)
Dim avg26 As Single
Dim avg12 As Single
Dim avg9 As Single
Dim pa1 As Single
Dim pa2 As Single
Dim pa3 As Single
Dim dl As Single

If currentindex < n26 Then
 Me.setindexinvalid
else
 'avg12 = price.AVG(n12, 1)
 avg26 = price.AVG(n26, 1)
 avg9 = price.AVG(n9, 1)
 'pa1 = avg12 + s1 * (price.Close - avg12)
 pa2 = avg26 + s2 * (price.Close - avg26)
 pa3 = avg9 + s3 * (price.Close - avg9)

 'dl = (pa1 - pa2) / PA2
 plot = (PA3 / PA2)
End If

 

 

 

 

 

 

 

 

Bruce_L
Posted : Friday, August 27, 2010 10:10:02 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I'm not sure where the misunderstandings might be (I could be misunderstanding the algorithm), but the s1, s2 and s3 in your RealCode would appear to be weights used for attempting to manually calculate and Plot an Exponential MACD that has been normalized by dividing by the Long Moving Average (you would need to divide the MACD by the Moving Average as well to get the Plots to line up relatively closely). Some slight alterations to your RealCode would result in:

'|*** Indicator:pmacdsl  ((no signal line plot))
Static n(2) As Integer
Static first As Integer
Static s(2) As Single
Static pa(2) As Single
If isFirstBar Then
    n(0) = 12
    n(1) = 26
    first = Math.Max(n(0), n(1))
    n(2) = 9
    For i As Integer = 0 To 2
        s(i) = 2 / (n(i) + 1)
    Next
End If
If CurrentIndex >= n(0) Then
    pa(0) = pa(0) + s(0) * (Price.Close - pa(0))
Else If CurrentIndex = n(0) - 1 Then
    pa(0) = Price.AVGC(n(0))
End If
If CurrentIndex >= n(1) Then
    pa(1) = pa(1) + s(1) * (Price.Close - pa(1))
Else If CurrentIndex = n(1) - 1 Then
    pa(1) = Price.AVGC(n(1))
End If
If CurrentIndex >= first Then
    Dim dl As Single = (pa(0) - pa(1)) / pa(1)
    'pa(2) = pa(2) + s(2) * (dl - pa(2))
    Plot = dl
    'Plot = pa(2)
Else If CurrentIndex = first - 1 Then
    Dim dl As Single = (pa(0) - pa(1)) / pa(1)
    'pa(2) = dl
    Plot = dl
Else
    Plot = Single.NaN
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Trader905
Posted : Monday, November 19, 2012 1:59:03 PM
Registered User
Joined: 11/16/2012
Posts: 6

Thank you sir!

Bruce_L
Posted : Monday, November 19, 2012 2:27:35 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.