Profile Picture

Cant Access Custom Indicator

Posted By blousetrader 8 Years Ago
Message
Posted Saturday November 28 2009
I want to create my own custom indicators but cant get my head round how it works. I copied one of DoQ's - the HullMA and built the dll on Microsoft Visual Basic 2008 Express,
I the copied what was in the Release folder (not Common or Indicators though) into the plugins folder in RE. RE doesnt see it though - I was expecting it to sho up under the 'Other' group
What am I doing wrong?

Here's the code I compiled to dll

Imports System
Imports System.Collections.Generic
Imports System.Text

Imports RightEdge.Common
Imports RightEdge.Indicators



Id:="72E74C2E-DC28-11DE-8C6B-0D8555D89593", Name:="HullMA", Version:="1.0")> _
_
_
Public Class HullMA
Inherits SeriesCalculatorBaseWithValues
Private _Period As Integer = 20
Private WMADiffValues As List(Of Double)



_
Public Sub New(ByVal Period As Integer)
MyBase.New(1)
If Period <= 0 Then
Throw New ArgumentException("Period must be greater than zero")
End If
_Period = Period
WMADiffValues = New List(Of Double)()
End Sub


'   This method is where you calculate the indicator value for a given bar.
'   The index parameter to this method tells you which value you need to
'   calculate.
'   You can access the first input series with inputs[0], the second
'   input series with inputs[1], etc.
Protected Overloads Overrides Function CalcNewValue(ByVal index As Integer) As Double

If index < _Period - 1 Then
Return Double.NaN
End If

'A 4 bar weighted moving average with prices of
'1.2900, 1.2900, 1.2903, and 1.2904 would give a moving average of 1.2903
'using the calculation
'((4 * 1.2904) + (3 * 1.2903) + (2 * 1.2900) + (1 * 1.2900)) / (4 + 3 + 2+ 1) = 1.2903

'Full Period
Dim CurrentPeriod As Integer = _Period
Dim WMAPeriod As Double = 0.0R
Dim Denominator As Integer = 0
For i As Integer = index - CurrentPeriod + 1 To index
WMAPeriod += (inputs(0).LookBack(i) * (i - (index - CurrentPeriod + 1) + 1))
Denominator += (i - (index - CurrentPeriod + 1) + 1)
Next
WMAPeriod /= Denominator


'Half Period
CurrentPeriod = _Period / 2
Dim WMAHalfPeriod As Double = 0.0R
Denominator = 0
For i As Integer = index - CurrentPeriod + 1 To index
WMAHalfPeriod += (inputs(0).LookBack(i) * (i - (index - CurrentPeriod + 1) + 1))
Denominator += (i - (index - CurrentPeriod + 1) + 1)
Next
WMAHalfPeriod /= Denominator

'store result with appropriate formula
'HMA = waverage(2*waverage(close,period/2)-waverage(close,period), SquareRoot(Period))
WMADiffValues.Add((2 * WMAHalfPeriod) - WMAPeriod)


'SQRT Period
CurrentPeriod = CInt(System.Math.Sqrt(_Period))
If WMADiffValues.Count < CurrentPeriod Then
'not enough collected data
Return Double.NaN
End If
Dim index2 As Integer = WMADiffValues.Count - 1
Dim WMASQRTPeriod As Double = 0.0R
Denominator = 0
For i As Integer = index2 - CurrentPeriod + 1 To index2
WMASQRTPeriod += (WMADiffValues(i) * (i - (index2 - CurrentPeriod + 1) + 1))
Denominator += (i - (index2 - CurrentPeriod + 1) + 1)
Next
WMASQRTPeriod /= Denominator

'HMA = waverage(2*waverage(close,period/2)-waverage(close,period), SquareRoot(Period))
Return WMASQRTPeriod
End Function

Protected Overloads Overrides Sub Reset()
'   This method is called when the series needs to be recalculated.
'   If you save any state between calls to CalcNewValue(), you should
'   reset that state in this method.

WMADiffValues.Clear()
End Sub

End Class
Posted Saturday November 28 2009
Actually it works for Edition 2 but not for Edition 1 - how can I get it working for Edition 1 ?
Posted Saturday November 28 2009
You need to build it with a reference to the version 1 common.dll


Posted Sunday November 29 2009
I can't work out how to change the references correctly - I went to the properties and selected the references tab - removed indicators and common - then added from the version 1 plugin folder - it then wouldn't build.

Another problem I have is accessing it from within the code - works fine when I drop it onto a chart but it wont show up from the code - here's what I gave

Public Class MySymbolScript
   Inherits MySymbolScriptBase

   
   Private HullMA20 As HullMA.DoQ_Indicators.HullMA

   
   
   Public Overloads Overrides Sub Startup()
      ' Perform initialization here
    HullMA20 = New HullMA.DoQ_Indicators.HullMA(20)
    HullMA20.SetInputs(Close)

      
   End Sub

Any help is much appreciated - if I can get this first one cracked I should be fine
Posted Sunday November 29 2009
blousetrader (11/29/2009)
I can't work out how to change the references correctly - I went to the properties and selected the references tab - removed indicators and common - then added from the version 1 plugin folder - it then wouldn't build.


What errors did you get when you say it wouldn't build?

Another problem I have is accessing it from within the code - works fine when I drop it onto a chart but it wont show up from the code


In your RightEdge project, you need to add a reference to your custom indicator DLL (right click on the references node in the project tree). If your indicator is in a namespace (it looks like yours may not be), you will also want a corresponding "Imports" statement at the top of your trading system code file.

Thanks,
Daniel
Posted Monday November 30 2009
------ Build started: Project: HullMA, Configuration: Release Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Diagnostics,System.Linq,System.Xml.Linq /optioncompare:Binary /optionexplicit+ /optionstrict:custom /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /optioninfer+ /rootnamespace:HullMA /doc:obj\Release\HullMA.xml /define:"CONFIG=\"Release\",TRACE=-1,_MyType=\"Windows\",PLATFORM=\"AnyCPU\"" /reference:"..\..\..\..\..\..\..\Program Files\Yye Software\RightEdge 2008 Edition 1\Plugins\Common.dll","..\..\..\..\..\..\..\Program Files\Yye Software\RightEdge 2008 Edition 1\Plugins\Indicators.dll","c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll","c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll",C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll,"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\HullMA.dll /resource:obj\Release\HullMA.Resources.resources /target:library HullMA.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb"
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
There were 0 Errors/Warnings/Messages

Here's the code - I ran it though a C# to vb convertor

Imports System
Imports System.Collections.Generic
Imports System.Text

Imports RightEdge.Common
Imports RightEdge.Indicators


Namespace DoQ_Indicators

Id:="{72E74C2E-DC28-11DE-8C6B-0D8555D89593}", Name:="HullMA", Version:="1.0")> _
_
_
Public Class HullMA
Inherits SeriesCalculatorBaseWithValues
Private _Period As Integer = 20
Private WMADiffValues As List(Of Double)



_
Public Sub New(ByVal Period As Integer)
MyBase.New(1)
If Period <= 0 Then
Throw New ArgumentException("Period must be greater than zero")
End If
_Period = Period
WMADiffValues = New List(Of Double)()
End Sub


'   This method is where you calculate the indicator value for a given bar.
'   The index parameter to this method tells you which value you need to
'   calculate.
'   You can access the first input series with inputs[0], the second
'   input series with inputs[1], etc.
Protected Overloads Overrides Function CalcNewValue(ByVal index As Integer) As Double

If index < _Period - 1 Then
Return Double.NaN
End If

'A 4 bar weighted moving average with prices of
'1.2900, 1.2900, 1.2903, and 1.2904 would give a moving average of 1.2903
'using the calculation
'((4 * 1.2904) + (3 * 1.2903) + (2 * 1.2900) + (1 * 1.2900)) / (4 + 3 + 2+ 1) = 1.2903

'Full Period
Dim CurrentPeriod As Integer = _Period
Dim WMAPeriod As Double = 0.0R
Dim Denominator As Integer = 0
For i As Integer = index - CurrentPeriod + 1 To index
WMAPeriod += (inputs(0).LookBack(i) * (i - (index - CurrentPeriod + 1) + 1))
Denominator += (i - (index - CurrentPeriod + 1) + 1)
Next
WMAPeriod /= Denominator


'Half Period
CurrentPeriod = _Period / 2
Dim WMAHalfPeriod As Double = 0.0R
Denominator = 0
For i As Integer = index - CurrentPeriod + 1 To index
WMAHalfPeriod += (inputs(0).LookBack(i) * (i - (index - CurrentPeriod + 1) + 1))
Denominator += (i - (index - CurrentPeriod + 1) + 1)
Next
WMAHalfPeriod /= Denominator

'store result with appropriate formula
'HMA = waverage(2*waverage(close,period/2)-waverage(close,period), SquareRoot(Period))
WMADiffValues.Add((2 * WMAHalfPeriod) - WMAPeriod)


'SQRT Period
CurrentPeriod = CInt(System.Math.Sqrt(_Period))
If WMADiffValues.Count < CurrentPeriod Then
'not enough collected data
Return Double.NaN
End If
Dim index2 As Integer = WMADiffValues.Count - 1
Dim WMASQRTPeriod As Double = 0.0R
Denominator = 0
For i As Integer = index2 - CurrentPeriod + 1 To index2
WMASQRTPeriod += (WMADiffValues(i) * (i - (index2 - CurrentPeriod + 1) + 1))
Denominator += (i - (index2 - CurrentPeriod + 1) + 1)
Next
WMASQRTPeriod /= Denominator

'HMA = waverage(2*waverage(close,period/2)-waverage(close,period), SquareRoot(Period))
Return WMASQRTPeriod
End Function

Protected Overloads Overrides Sub Reset()
'   This method is called when the series needs to be recalculated.
'   If you save any state between calls to CalcNewValue(), you should
'   reset that state in this method.

WMADiffValues.Clear()
End Sub

End Class


End Namespace
Posted Sunday December 06 2009
Below is the code for the Hull Moving Average converted to work with RE2008.  It is still in C#, but when you compile it to a DLL, it should work fine with systems written in VB.NET.  If you prefer, a C# to VB converter would probably work fine on it.

Thanks,
Daniel

using System;

using System.Collections.Generic;

using System.Text;

 

using RightEdge.Common;

using RightEdge.Indicators;

 

namespace DoQ_Indicators

{

      [

      YYEIndicatorAttribute

         (

            System.Drawing.KnownColor.Blue,

            YYEIndicatorAttribute.EIndicatorGroup.Other,

            Author = "DoQ",

            CompanyName = "www.TradeEngineer.com",

            DefaultDrawingPane = "Price Pane",

            Description = "Hull moving Average",

            GroupName = "DoQ-Indicators",

            HelpText = "",

            Id = "2a272648-0661-4886-b4c6-7149f9ceb44d",

            Name = "HullMA",

            Version = "1.0"

         )

      ]

      [Serializable]

      [SeriesInputAttribute("Input", 1, Value = BarElement.Close)]

      public class HullMA : SeriesCalculatorBaseWithValues

      {

            private int _Period = 20;

            private List<double> WMADiffValues;

 

            [ConstructorArgument(Name = "Period",

                                           Type = ConstructorArgumentType.Integer,

                                           Value = "20",

                                           Order = 1)]

            public HullMA(int Period, int series)

                  : base(1)

            {

                  if (Period <= 0)

                  {

                        throw new ArgumentException("Period must be greater than zero");

                  }

                  _Period = Period;

                  WMADiffValues = new List<double>();

            }

 

            private double WeightedMovingAverage(int lookBack, int periods, ISeries series)

            {

                  //A 4 bar weighted moving average with prices of

                  //1.2900, 1.2900, 1.2903, and 1.2904 would give a moving average of 1.2903

                  //using the calculation

                  //((4 * 1.2904) + (3 * 1.2903) + (2 * 1.2900) + (1 * 1.2900)) / (4 + 3 + 2+ 1) = 1.2903

 

                  double Numerator = 0.0;

                  int Denominator = 0;

                  for (int i = 0; i < periods; i++)

                  {

                        Numerator += (series.LookBack(i + lookBack) * (periods - i));

                        Denominator += (periods - i);

                  }

                  return Numerator / Denominator;

            }

 

 

            //    This method is where you calculate the indicator value for a given bar.

            protected override double CalcNewValue(int lookBack)

            {

                  int index = inputs[0].Count - lookBack - 1;

 

                  if (index < _Period - 1)

                  {

                        return double.NaN;

                  }

 

                  //Full Period

                  double WMAPeriod = WeightedMovingAverage(lookBack, _Period, inputs[0]);

 

                  //Half Period

                  double WMAHalfPeriod = WeightedMovingAverage(lookBack, _Period / 2, inputs[0]);

 

                  //store result with appropriate formula

                  //HMA = waverage(2*waverage(close,period/2)-waverage(close,period), SquareRoot(Period))

                  WMADiffValues.Add((2 * WMAHalfPeriod) - WMAPeriod);

 

 

                  //SQRT Period

                  int CurrentPeriod = (int)System.Math.Sqrt(_Period);

                  if (WMADiffValues.Count < CurrentPeriod)//not enough collected data

                  {

                        return double.NaN;

                  }

                  int index2 = WMADiffValues.Count - 1;

                  double WMASQRTPeriod = 0.0;

                  double Denominator = 0;

                  for (int i = index2 - CurrentPeriod + 1; i <= index2; i++)

                  {

                        WMASQRTPeriod += (WMADiffValues[i] * (i - (index2 - CurrentPeriod + 1) + 1));

                        Denominator += (i - (index2 - CurrentPeriod + 1) + 1);

                  }

                  WMASQRTPeriod /= Denominator;

 

                  return WMASQRTPeriod;

                  //HMA = waverage(2*waverage(close,period/2)-waverage(close,period), SquareRoot(Period))

            }

 

            protected override void Reset()

            {

                  //    This method is called when the series needs to be recalculated.

                  //    If you save any state between calls to CalcNewValue(), you should

                  //    reset that state in this method.

 

                  WMADiffValues.Clear();

            }

 

      }

}

Posted Tuesday January 19 2010
Great stuff - thanks a lot
Posted Saturday May 15 2010
Daniel - the HullMA code you posted won't work for me when I use it at a higher frequency in a multi-frequency system - ie I'm running the ssytem
on 5m bars and trying to calc a 10min HullMA - its always gives nan.
Posted Sunday May 16 2010
My first guess is that you may be using the 5-minute close series as the input instead of the 10-minute close. If that's not it, can you post the code you are using to set up your indicators?

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems