Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Porting Kalman Filter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Porting Kalman Filter

    this is a tradestation function code,is some experienced of C# able to do its porting?
    Code:
    {Function = Kalman Filter}
    {Use gain between 500 to 1000 for starters...}
    Inputs: price(NumericSeries), gain(Numeric);
    Vars: Pred(price), Smooth(0), Velo(0), DeltaK(0), stderr(0),
             error(0), sumerr(0) ; 
     
    if currentbar > 1 then
    begin
        
    
        DeltaK = price - Pred;
        Smooth = Pred + DeltaK* SquareRoot((gain / 10000) * 2) ;
        Velo= Velo + ((gain / 10000) * Deltak) ;
        Pred = Smooth + Velo ;
    
        KF=Pred;
    end;
    Last edited by Mauro60; 09-17-2007, 06:43 AM.

    #2
    Kalman Filter Conversion

    I don't know Trade Station, so I'm not sure I got this right.

    But I converted it....

    Code:
      private int            gain        = 500;
            
      double pred;
      double velo = 0;
    
      protected override void Initialize()
      {
          Add(new Plot(Color.Orange, "Kalman"));
    
          Overlay                = true;
          PriceTypeSupported    = true;
      }
    
      protected override void OnBarUpdate()
      {
          if (CurrentBar == 0) pred = Close[0]; // Initialize on first bar.
                
          double DeltaK = Close[0] - pred;
          double smooth = pred + DeltaK * Math.Sqrt(( gain / 10000) * 2);
          velo = velo + ((gain / 10000) * DeltaK);
          pred = smooth + velo;
                
          Values[0].Set( pred );
      }
    It seems to be touchy about the value of "gain", either plotting just a horizontal line if too small, or nothing at all if too big.

    Let me know if this is what its supposed to do (see attachments).

    Best regards,

    KBJ
    Attached Files

    Comment


      #3
      Thanks a lot of for the answer, I have made a small change to the variable GAIN,as soon I can I will compare to Tradestation's KF
      Attached Files
      Last edited by Mauro60; 09-17-2007, 03:39 AM.

      Comment


        #4
        Kalman Filter

        This post was from a while ago. I wanted to see if anyone else had a Kalman Filter indicator that they are using. Any help would be appreciated.

        Thanks.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        150 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        6 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post tkaboris  
        Working...
        X