Posted 3/3/2010 10:14:46
|
|
|
|
|
|
Posted 3/3/2010 12:36:19
|
|
|
|
| The code looks pretty good, although I didn't look at it closely enough to verify that it's using the correct algorithm. Just add the following as an additional constructor: public KAMA(int periods, ISeries input) : this(periods) { SetInputs(input); } Thanks, Daniel
|
|
Posted 3/3/2010 13:37:44
|
|
|
|
|
|
Posted 3/8/2010 16:03:11
|
|
|
|
I tired converting that to VB - got it compiling but all values end up as NaN - anybody know what's wrong?
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports RightEdge.Common
Imports RightEdge.Indicators
' The Id attribute needs to be set to a unique code that will identify
' your indicator. A GUID is a good candidate.
' Indicators must be marked Serializable in order to be used in
' trading systems.
' Use the SeriesInputAttribute to specify how many inputs your
' indicator uses.
Name:="KAMA")> _
_
_
Public Class KAMA
Inherits SeriesCalculatorBaseWithValues
Private _periods As Integer
Private smooth As Double
Private efratio As Double
Private slowLength As Integer
Private fastLength As Integer
Shared fastend As Double
Shared slowend As Double
Private todaysMA As Double = 0.0R
Private signal As Double
Private noise As Double
Private _diff As Queue(Of Double)
' A class level variable to hold the previous day's KAMA calculation.
Private yesterdaysMA As Double = Double.NaN
_
Public Sub New(ByVal periods As Integer)
MyBase.New(1)
' Requires two inputs
If periods <= 0 Then
Throw New ArgumentException("Periods1 must be greater than zero")
End If
_periods = periods
_diff = New Queue(Of Double)(_periods + 1)
fastLength = 2
slowLength = 30
noise = 0
fastend = 2 / CDbl((fastLength + 1))
slowend = 2 / CDbl((slowLength + 1))
End Sub
' Called to calculate a new value for the indicator.
Protected Overloads Overrides Function CalcNewValue(ByVal index As Integer) As Double
' Ensures that we have enough values to calculate the request EMA for the specified period.
If inputs(0).Count = 1 Then
yesterdaysMA = inputs(0).Current
End If
If inputs(0).Count > 1 Then
_diff.Enqueue(Math.Abs(inputs(0).Current - inputs(0).LookBack(1)))
noise += Math.Abs(inputs(0).Current - inputs(0).LookBack(1))
End If
If inputs(0).Count > _periods + 1 Then
signal = Math.Abs(inputs(0).Current - inputs(0).LookBack(_periods))
noise -= _diff.Dequeue()
If noise <> 0.0R Then
efratio = signal / noise
Else
efratio = 1
End If
End If
If inputs(0).Count <= _periods Then
todaysMA = inputs(0).Current
End If
smooth = Math.Pow(efratio * (fastend - slowend) + slowend, 2)
todaysMA = yesterdaysMA + smooth * (inputs(0).Current - yesterdaysMA)
yesterdaysMA = todaysMA
Return todaysMA
End Function
' This function is called when there is a request to recalculate the entire
' series. Since each indicator maintains state, it will be reused and this
' is the opportunity to flush all internal buffers and collections.
Protected Overloads Overrides Sub Reset()
yesterdaysMA = Double.NaN
_diff.Clear()
End Sub
Public Sub New(ByVal periods As Integer, ByVal input As ISeries)
Me.New(periods)
SetInputs(input)
End Sub
End Class
|
|
Posted 3/10/2010 01:01:50
|
|
|
|
Did you try the C# version and did it work for you? If you create a plugin DLL (using Visual Studio) for the indicator, then you can use the C# indicator code, but still use VB for your system code.
Thanks,
Daniel
|
|
Posted 3/11/2010 15:46:08
|
|
|
|
Here is an updated version (bug removed) .
I also added two other constructors :
- a second one which allows the passing of the iSeries reference to the KAMA : "public KAMA(int periods, ISeries Input)"
- a third one which gives access to the lower and upper limits of the KAMA, in case someone wants to play with that "public KAMA(int periods, ISeries Input, int fastLength, int slowLength)".
Trying to build a DLL for Blousetrader. The DLL is building OK inside VS.
Now , before posting it, how can I try it inside RE ?
I checked the Reference->Add in the Help Topic, but this seems to refer to Visual Studio, doesn't it ?
So how can I add it to a project inside RE ?
Thanks,
Pierre
|
|
Posted 3/11/2010 15:51:47
|
|
|
|
You can also add references to RightEdge projects in much the same way as you do for a Visual Studio project. Right click on the references node in the project tree and click on Add Reference.
Thanks,
Daniel
|
|
Posted 3/11/2010 16:36:14
|
|
|
|
Quite obvious. Thank you Daniel.
Here is the DLL.
Pierre
|
|
Posted 3/12/2010 13:57:17
|
|
|
|
Cheers guys - thanks for your efforts - I still can't get it to work though - even the new version still produces all NaN when I drag it onto t he chart - havn't tried
it from within the code.
Does it work for you ?
|
|
Posted 3/12/2010 17:42:15
|
|
|
|
Sorry about that. Works A-OK within code (tried 3 constructors without a problem).
Not enough experience of RE to figure out why it doesn't show up in charts.
Will try again tomorrow.
Pierre
|
|
|
|