Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

implement a function on NT

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

    implement a function on NT

    I'd like to implement a function as it is possible to do so on TS.

    Here is the code :
    FONCTION T3.AVERAGE.SERIES


    Inputs: Price(NumericSeries), Periods(NumericSimple);

    Variables: b(0), b2(0), b3(0), e1(Price), e2(Price), e3(Price),
    e4(Price), e5(Price), e6(Price), c1(0), c2(0), c3(0),
    c4(0), f1(0), f2(0), Hot(0.7);

    if Periods + 1 <> 0 then begin

    if CurrentBar <= 1 then begin

    b = Hot;
    b2 = b * b;
    b3 = b * b * b;
    c1 = -b3;
    c2 = 3 * b2 + 3 * b3;
    c3 = -6 * b2 - 3 * b - 3 * b3;
    c4 = 1 + 3 * b + b3 + 3 * b2;
    f1 = 2 / (Periods + 1);
    f2 = 1 - f1;

    end else begin

    e1 = f1 * Price + f2 * e1[1];
    e2 = f1 * e1 + f2 * e2[1];
    e3 = f1 * e2 + f2 * e3[1];
    e4 = f1 * e3 + f2 * e4[1];
    e5 = f1 * e4 + f2 * e5[1];
    e6 = f1 * e5 + f2 * e6[1];

    end;

    T3Average.series = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;

    end;


    the thing is I want to use this "function" in another ninjascript but as you can see "price" is a parameter.
    I don't know how to proceed.

    Can anyone help ?

    #2
    I forgot to mention that my "price" formula would be set on my other Ninjascript as follow :

    price.Set ((High[0]+Low[0]+Close[0])/3);
    Value1.Set( 2 * t3average.series(price, p1));
    Value2.Set( t3average.series(price, p2));
    Value3 = (t3average.series((Value1 - Value2), p3));

    Comment


      #3
      You need to create this as an indicator in NinjaTrader. Then you can use it as you would an indicator and pass in any input series you wish.
      RayNinjaTrader Customer Service

      Comment


        #4
        but how can I code this line :

        e1 = f1 * Price + f2 * e1[1];

        if I don't declare this variable, I cannot compile my code

        Comment


          #5
          Instead of using "Price" use our Typical series which is what you are looking for.

          More information - http://www.ninjatrader-support.com/H...6/Typical.html
          RayNinjaTrader Customer Service

          Comment


            #6
            this won't work because of this line :

            Value3 = (t3average.series((Value1 - Value2), p3));

            here price = Value1-Value2

            so "price" must stay a parameter on the first ninjascript in order to return the correct calculation

            I don't know if you understand.

            Comment


              #7
              Sure I understand.

              Then you have to create a DataSeries object to store the calculation of value1 - value2.

              See this reference sample - http://www.ninjatrader-support.com/v...ead.php?t=7299

              Here is some pseudo code based on what you provided:

              Value1.Set( 2 * t3average.series(Typical, p1));
              Value2.Set( t3average.series(Typical, p2));
              price.Set(Value1[0] - Value2[0]);
              Value3 = (t3average.series(price, p3));
              RayNinjaTrader Customer Service

              Comment


                #8
                Well, I think you misunderstood me.

                Let me be clear.

                I want to create an indicator that use this T3.average.series function I described below.

                Suppose that I do as you told me to :

                when NT make the calculation and follow the script, then it will go to the T3.average.series script and will come to this line of the code :

                e1 = f1 * Price + f2 * e1[1];

                on this first Ninjascript, Price is a parameter and not defined. If I defined it on the second Ninjascript, will it replace it by the typical price or anything else alone ?

                How should I deal with it on the first script ? just declare it as a dataseries and set no value ?

                am I clear ?

                Comment


                  #9
                  Yes you are clear.

                  Create an indicator for this function.

                  By default, you will use the property "Input" which refers to the data series passed into the indicator method.

                  The indicator method will look something like:

                  myIndicator(DataSeries input, int Periods)

                  then in your second script you would call:

                  myIndicator(Typical, PeriodsValue)

                  Take a look at the SMA indicator source to get an idea of how Input is used.
                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Hwop38, 05-04-2026, 07:02 PM
                  0 responses
                  160 views
                  0 likes
                  Last Post Hwop38
                  by Hwop38
                   
                  Started by CaptainJack, 04-24-2026, 11:07 PM
                  0 responses
                  308 views
                  0 likes
                  Last Post CaptainJack  
                  Started by Mindset, 04-21-2026, 06:46 AM
                  0 responses
                  245 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by M4ndoo, 04-20-2026, 05:21 PM
                  0 responses
                  349 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Started by M4ndoo, 04-19-2026, 05:54 PM
                  0 responses
                  179 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Working...
                  X