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

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 Pattontje, Yesterday, 02:10 PM
                  2 responses
                  15 views
                  0 likes
                  Last Post Pattontje  
                  Started by flybuzz, 04-21-2024, 04:07 PM
                  17 responses
                  229 views
                  0 likes
                  Last Post TradingLoss  
                  Started by agclub, 04-21-2024, 08:57 PM
                  3 responses
                  17 views
                  0 likes
                  Last Post TradingLoss  
                  Started by TradingLoss, 04-21-2024, 04:32 PM
                  4 responses
                  44 views
                  2 likes
                  Last Post TradingLoss  
                  Started by cre8able, 04-17-2024, 04:16 PM
                  6 responses
                  57 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X