Profile Picture

Building Custom Indicator

Posted By blousetrader 8 Years Ago
Message
Posted Monday October 19 2009
I'd started building some code for a custom indicator but ran into problems as a userseries cannot be used as input to an indicator.
Here's what I had so far but where do I go from here? Appreciate any help..

Public Class MySymbolScript
   Inherits MySymbolScriptBase
   
   
   Private Constant100 As ConstantSeries
   Private Constant2 As ConstantSeries
   Private Constant1 As ConstantSeries
   
   Private TH As UserSeries
   Private TL As UserSeries
   Private TR As SubtractSeries
      
   Private PlusDM As UserSeries
   Private PlusDIDen As WildersSmoothing
   Private PlusDINum As WildersSmoothing
   Private PlusDIDiv As DivideSeries
   Private PlusDI As MultiplySeries
   Private MinusDM As UserSeries
   Private MinusDIDen As WildersSmoothing
   Private MinusDINum As WildersSmoothing
   Private MinusDIDiv As DivideSeries
   Private MinusDI As MultiplySeries
   
   Private DIDifInput As SubtractSeries
   Private DIDif As AbsoluteValue
   Private DISum As AddSeries
   
   Private ADXFinalVarInp As DivideSeries
   Private ADXFinalVar As WildersSmoothing
   Private ADXFinal As MultiplySeries
   Private ADXFinalShift As Shift
   Private ADXRAdd As AddSeries
   Private ADXRCustom As DivideSeries
   Private _ADX As UserSeries
   
   Private EMAIndex As UserSeries
   Private HighVAl As Highest
   Private LowVAl As Lowest
   Private Diff As SubtractSeries
   Private MyConst As UserSeries
   Private VarMASeriesSub As SubtractSeries
   Private VarMASeriesMult1 As MultiplySeries
   Private VarMASeriesMult2 As MultiplySeries
   Private VarMASeries As AddSeries
   Private SMASeries As SMA
   Private VarMA As UserSeries
   Private VarMAShift As Shift
      
   'Private ADX8 As ADX   
   'Private baseEMA4 As VariableMA
   
   
   
   Public Overloads Overrides Sub Startup()
      ' Perform initialization here
      Dim ADXPr As Integer = 8
      
      TH = New UserSeries()
      TL = New UserSeries()
      TR = New SubtractSeries
      TR.SetInputs(TH,TL)
      
      PlusDM = New UserSeries
      MinusDM = New UserSeries
      
      Constant100 = New ConstantSeries(100)
      Constant2 = New ConstantSeries(2)
      Constant1 = New ConstantSeries(1)
      
      PlusDIDen = New WildersSmoothing(ADXPr,Tr)
      PlusDINum = New WildersSmoothing(ADXPr,PlusDM)
      PlusDIDiv = New DivideSeries
      PlusDIDiv.SetInputs(PlusDINum,PlusDIDen)
      PlusDI = New MultiplySeries
      PlusDI.SetInputs(Constant100,PlusDIDiv)
      
      MinusDIDen = New WildersSmoothing(ADXPr,Tr)
      MinusDINum = New WildersSmoothing(ADXPr,MinusDM)
      MinusDIDiv = New DivideSeries
      MinusDIDiv.SetInputs(MinusDINum,MinusDIDen)
      MinusDI = New MultiplySeries
      MinusDI.SetInputs(Constant100,MinusDIDiv)
      
      DIDifInput = New SubtractSeries
      DIDifInput.SetInputs(PlusDI,MinusDI)
      DIDif = New AbsoluteValue
      DIDif.SetInputs(DIDifInput)
      DISum = New AddSeries
      DISum.SetInputs(PlusDI,MinusDI)
      
      ADXFinalVarInp = New DivideSeries
      ADXFinalVarInp.SetInputs(DIDif,DISum)
      ADXFInalVar = New WildersSmoothing(ADXPr,ADXFinalVarInp)
      ADXFinal = New MultiplySeries
      ADXFinalShift = New Shift(7)
      ADXFinal.SetInputs(Constant100,ADXFinalVar)
      
      ADXRAdd = New AddSeries
      ADXRAdd.SetInputs(ADXFinal,ADXFinalShift)
      ADXRCustom = New DivideSeries
      ADXRCustom.SetInputs(ADXRAdd,Constant2)
      _ADX = New UserSeries
      
      EMAIndex = New UserSeries
    HighVal = New Highest(ADXPr,_ADX)
    LowVal = New Lowest(ADXPr,_ADX)
    Diff = New SubtractSeries
      Diff.SetInputs(HighVal,LowVal)
    MyConst = New UserSeries
      
      VarMASeriesSub = New SubtractSeries
      VarMASeriesSub.SetInputs(Constant1,MyConst)
      VarMASeriesMult1 = New MultiplySeries
      VarMASeriesMult1.SetInputs(VarMASeriesSub,VarMAShift)
      VarMASeriesMult2 = New MultiplySeries
      VarMASeriesMult2.SetInputs(MyConst,Close)
    VarMASeries = New AddSeries
      VarMASeries.SetInputs(VarMASeriesMult1,VarMASeriesMult2)
      SMASeries = New SMA(2,VarMASeries)
      VarMA = New UserSeries
      VarMAShift = New Shift(1)

      VarMA.ChartSettings.Color = Color.Black
      VarMA.ChartSettings.LineSize = 2


   End Sub

   Public Overloads Overrides Sub NewBar()
      ' Put your trading code here
      Dim ADXType As Integer = 2 '2 is EMA, 0 is Simple MA
      Dim VarMAPr As Integer = 4
      Dim ADXPr As Integer = 8

      
      'Build UserSeries here
      TH = IIf(Close.LookBack(1) > High.Current,Close.LookBack(1),High.Current)
      TL = IIf(Close.LookBack(1) < Low.Current,Close.LookBack(1),Low.Current)
      
      PlusDM = IIf(High.Current > High.LookBack(1) And low.Current >= low.LookBack(1),high.Current-high.LookBack(1), _
       IIf(High.Current > High.LookBack(1) And low.Current < low.LookBack(1) And high.Current - high.LookBack(1) > low.LookBack(1) - low.Current,high.Current-high.LookBack(1),0))
               
MinusDM = IIf(Low.Current < Low.LookBack(1) And High.Current <= High.LookBack(1),Low.LookBack(1) - Low.Current, _
       IIf(high.Current > high.LookBack(1) And low.Current < low.LookBack(1) And high.Current - high.LookBack(1) < low.LookBack(1) - low.Current,Low.LookBack(1) - Low.Current,0))               
               
      'ADXRCustom = (ADXFinal.Current + ADXFinal.LookBack(7))/2
      _ADX = IIf(ADXType = 0,ADXFinal.Current,ADXRCustom.Current)   
      
      EMAIndex = IIf(VarMAPr > 0,(2/(1+VarMAPr)),0.2)
      MyConst = IIf(Diff.Current > 0,(_ADX.Current - LowVal.Current)/Diff.Current,EMAIndex.Current)
      MyConst = IIf(MyConst.Current > EMAIndex.Current,EMAIndex.Current,MyConst.Current)
      'VarMASeries = ((1-MyConst.Current) * VarMA.LookBack(1)) + (MyConst.Current * Close.Current)
      VarMA = IIf(Bars.Count < (ADXPr + (ADXPr*1.5)),Close.Current,SMASeries.Current)
               
            


   End Sub


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems