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

code error

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

    code error

    Hi,
    I can not write this simple code:


    private double a = 0;
    private double sig = 0;
    private int gg = 5;
    ....

    a = Median[0] - SMA(SMA(Median(), gg)[0], 2*gg)[0] ;

    sig = SMA(A,2*gg);


    if ( a > sig )
    GoLong();


    if (sig < a)
    GoShort();

    It gives me an error on the allocation of the argument of Sma
    that must be "data id" tipe.

    how can I solve the problem?
    Tanks

    #2
    Hello picita,

    SMA can accept a data series as input, not a double value.

    This tutorial can help you create your own custom data series.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I'll watch it very carefully.

      Comment


        #4
        I would like to calculate for each bar, the following expression without
        have the error of incorrect allocation of a type IdData with a double.

        a = (Median[0]-SMA(SMA(Median[0],gg),gg*2));
        Sig = SMA(a,gg*2);
        //gg is a variable input with default = 5

        I tried to write the following code that is in the help of NT:

        #region Variables
        private DataSeries myDataSeries; // Declare a DataSeries variable
        #endregion

        protected override void Initialize()
        {
        myDataSeries = new DataSeries(this);
        }
        protected override void OnBarUpdate()
        {
        myDataSeries.Set(Close[0] - Open[0]);
        Plot0.Set(SMA(SMAPeriod)[0] + myDataSeries[0]);
        }

        in this case gives me the following error

        impossible to apply the operator -

        I do not know how to get out.

        Comment


          #5
          Hello Picita,

          I successfully compiled the code you submitted from the help guide.

          Anything that you pass into SMA as an input needs to be a DataSeries - > Median, a, and Sig

          When you apply indexing [0] to a data series, it becomes a double.

          Try first simple and then complexity. Work from the tutorial to create one data series and then pass this data series into SMA.


          Example:

          #region Variables
          private DataSeries myDataSeries; // Declare a DataSeries variable
          #endregion

          protected override void Initialize()
          {
          myDataSeries = new DataSeries(this);
          }
          protected override void OnBarUpdate()
          {
          myDataSeries.Set(Close[0] - Open[0]);
          Plot0.Set(SMA(myDataSeries, 14)[0]);

          }
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Ok
            the code from help guide is right
            but if I which to plot this (or calculate):

            a = Median[0] - SMA(SMA(Median(), gg)[0], 2*gg)[0] ;
            sig = SMA(a,2*gg);
            plot0.set(sig);

            how many and which steps I have to do to convert double type in IData types?

            is a bit complicated
            or no?



            Originally posted by NinjaTrader_RyanM View Post
            Hello Picita,

            I successfully compiled the code you submitted from the help guide.

            Anything that you pass into SMA as an input needs to be a DataSeries - > Median, a, and Sig

            When you apply indexing [0] to a data series, it becomes a double.

            Try first simple and then complexity. Work from the tutorial to create one data series and then pass this data series into SMA.


            Example:

            #region Variables
            private DataSeries myDataSeries; // Declare a DataSeries variable
            #endregion

            protected override void Initialize()
            {
            myDataSeries = new DataSeries(this);
            }
            protected override void OnBarUpdate()
            {
            myDataSeries.Set(Close[0] - Open[0]);
            Plot0.Set(SMA(myDataSeries, 14)[0]);

            }

            Comment


              #7
              Picita, the SMA takes only dataseries as input, you cannot pass a double value in - have you given Ryan's example a try?

              We also have a dedicated reference sample for working with DateSeries objects - http://www.ninjatrader.com/support/f...ead.php?t=7299
              BertrandNinjaTrader Customer Service

              Comment


                #8
                sorry
                but if I have to create a Dataseries Object with SMA argument?
                is it possible?
                that's what I do


                Comment


                  #9
                  Picita, the a and the sig from the code you posted are double variables in your code, you would need to create them as DataSeries instead and then use the .Set method to populate them with your custom values, so you could then pass those series to the SMA method.

                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by mgco4you, Today, 09:46 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post mgco4you  
                  Started by Rapine Heihei, Today, 08:19 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by Rapine Heihei, Today, 08:25 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post Rapine Heihei  
                  Started by f.saeidi, Today, 08:01 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by Rapine Heihei, Today, 07:51 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post Rapine Heihei  
                  Working...
                  X