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 Gauss filter

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

    Porting Gauss filter

    this is a tradestation function code,have I tried to write the code for Ninja but not plot nothing.

    Code:
    {Gaussian Filter}
    {Ported to EasyLanguage by: atavachron}
    {Original author: DrKoch}
    Inputs: Price(NumericSeries), Period(NumericSimple), poles(NumericSimple);
    
    variables: aa(0), b(0), w(0), x(0), y(0), y1(0), y2(0), y3(0), y4(0),
    a_1(0), a_12(0), a_13(0), a_14(0), a2(0), a3(0), a4(0), Pi(3.141592654),
    sqrtOf2(1.414213562);
    
    {If number of poles is < 0 or > 4 then return 0.}
    {Number of filter poles must be between 1 and 4, inclusive}
    If (poles >= 1) and (poles <= 4) then
    begin
    {initialization - performed only for first bar}
    if CurrentBar = 1 then
    begin
    w = 2 * Pi / Period; {omega}
    w = 180 * w / Pi; {in degrees}
    
    b = (1 - cosine(w)) / (power(sqrtOf2, 2.0/poles) - 1.0);
    
    aa = -b + squareroot(b*b + 2*b);
    a_1 = 1.0 - aa;
    a_12 = a_1 * a_1;
    a_13 = a_1 * a_1 * a_1;
    a_14 = a_12 * a_12;
    a2 = aa * aa;
    a3 = aa * aa * aa;
    a4 = a2 * a2;
    
    y1 = Price;
    y2 = y1;
    y3 = y2;
    y4 = y3;
    end;
    
    {Calculate your indicator value here}
    x = Price;
    
    if (poles = 1) then
    y = aa * x + a_1 * y1
    else if (poles = 2) then
    y = a2 * x + 2 * a_1 * y1 - a_12 * y2
    else if (poles = 3) then
    y = a3 * x + 3 * a_1 * y1 - 3 * a_12 * y2 + a_13 * y3
    else if (poles = 4) then
    y = a4 * x + 4 * a_1 * y1 - 6 * a_12 * y2 + 4 * a_13 * y3 - a_14 * y4;
    
    y4 = y3; {delayed by four bars}
    y3 = y2; {delayed by three bars}
    y2 = y1; {delayed by two bars}
    y1 = y; {delayed by one bar}
    
    Gauss = y;
    end
    else
    Gauss = 0.0;
    I attach file CS MaGauss
    Attached Files

    #2
    Please check your log tab of for any error messages when applying the indicator to a chart and let us know what it is.
    RayNinjaTrader Customer Service

    Comment


      #3
      thanks for the answer,any error signalled on the Log Tab

      Comment


        #4
        may someone could help me porting this indicator? I made some piece of code...help please

        Comment


          #5
          Originally posted by Mauro60 View Post
          this is a tradestation function code,have I tried to write the code for Ninja but not plot nothing.

          Code:
          {Gaussian Filter}
          {Ported to EasyLanguage by: atavachron}
          {Original author: DrKoch}
          Inputs: Price(NumericSeries), Period(NumericSimple), poles(NumericSimple);
          
          variables: aa(0), b(0), w(0), x(0), y(0), y1(0), y2(0), y3(0), y4(0),
          a_1(0), a_12(0), a_13(0), a_14(0), a2(0), a3(0), a4(0), Pi(3.141592654),
          sqrtOf2(1.414213562);
          
          {If number of poles is < 0 or > 4 then return 0.}
          {Number of filter poles must be between 1 and 4, inclusive}
          If (poles >= 1) and (poles <= 4) then
          begin
          {initialization - performed only for first bar}
          if CurrentBar = 1 then
          begin
          w = 2 * Pi / Period; {omega}
          w = 180 * w / Pi; {in degrees}
          
          b = (1 - cosine(w)) / (power(sqrtOf2, 2.0/poles) - 1.0);
          
          aa = -b + squareroot(b*b + 2*b);
          a_1 = 1.0 - aa;
          a_12 = a_1 * a_1;
          a_13 = a_1 * a_1 * a_1;
          a_14 = a_12 * a_12;
          a2 = aa * aa;
          a3 = aa * aa * aa;
          a4 = a2 * a2;
          
          y1 = Price;
          y2 = y1;
          y3 = y2;
          y4 = y3;
          end;
          
          {Calculate your indicator value here}
          x = Price;
          
          if (poles = 1) then
          y = aa * x + a_1 * y1
          else if (poles = 2) then
          y = a2 * x + 2 * a_1 * y1 - a_12 * y2
          else if (poles = 3) then
          y = a3 * x + 3 * a_1 * y1 - 3 * a_12 * y2 + a_13 * y3
          else if (poles = 4) then
          y = a4 * x + 4 * a_1 * y1 - 6 * a_12 * y2 + 4 * a_13 * y3 - a_14 * y4;
          
          y4 = y3; {delayed by four bars}
          y3 = y2; {delayed by three bars}
          y2 = y1; {delayed by two bars}
          y1 = y; {delayed by one bar}
          
          Gauss = y;
          end
          else
          Gauss = 0.0;
          I attach file CS MaGauss

          may someone could help me porting this indicator? I made some piece of code...help please

          Comment


            #6
            I believe I have it working (see attachment)...but my research on the internet didn't find any documents that covered the topic of "Gauss Moving Average".

            Let me know how it works for you!

            Ben
            Attached Files

            Comment


              #7
              Thank you very much try hours, the code of the post is the version Tradestation

              Comment


                #8
                for an unknown reason the indicator is not plotting when you set poles to 3 or 4.

                if someone could check the code and tell me what's wrong I would really appreciate

                Comment


                  #9
                  when you use 3 / 4 poles the divisor goes to zero.

                  change this line
                  b = (1 - Math.Cos(w)) / (Math.Pow(sqrtOf2, Math.Abs((2 / poles)) - 1));

                  mrlogik
                  mrlogik
                  NinjaTrader Ecosystem Vendor - Purelogik Trading

                  Comment


                    #10
                    Thank you, I control with the version of Tradestation

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by TraderBCL, Today, 04:38 AM
                    2 responses
                    8 views
                    0 likes
                    Last Post TraderBCL  
                    Started by martin70, 03-24-2023, 04:58 AM
                    14 responses
                    105 views
                    0 likes
                    Last Post martin70  
                    Started by Radano, 06-10-2021, 01:40 AM
                    19 responses
                    606 views
                    0 likes
                    Last Post Radano
                    by Radano
                     
                    Started by KenneGaray, Today, 03:48 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post KenneGaray  
                    Started by thanajo, 05-04-2021, 02:11 AM
                    4 responses
                    471 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Working...
                    X