Announcement

Collapse
No announcement yet.

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

              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.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Hwop38, 05-04-2026, 07:02 PM
                  0 responses
                  161 views
                  0 likes
                  Last Post Hwop38
                  by Hwop38
                   
                  Started by CaptainJack, 04-24-2026, 11:07 PM
                  0 responses
                  309 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