Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code problems

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

    #16
    Thank you Ray, that helped. Now I have only 1 error reported on this line. The error message reads "cannot apply indexing with [] to an expression of type double"...the little red error indicator is under the part where it reads "VarSto[1]"...any ideas?

    Thanks again.

    Comment


      #17
      The error caused by the "scalar" has been cleared, however how do I insert the code to compile correctly so as to use the previous period value?

      Could I define a value equal to VarSto[1] and simply insert that variable where needed in the script? Thanks again.

      Comment


        #18
        If you want to store the previous value of a variable you can just do something like

        Code:
        prevVarSto = VarSto;
        Do this before you change the value of VarSto.
        Josh P.NinjaTrader Customer Service

        Comment


          #19
          Or, if you wanted to store more than one bar back, so you can reference several bars back, you could create another dataseries...

          Code:
          #region Variables
              private double VarSto = 0;
              private DataSeries myDataSeries2;
              private DataSeries VarStoSeries;
          #endregion
          
          protected override void Initialize()
          {
            ...
            myDataSeries2 = new DataSeries(this);
            VarStoSeries  = new DataSeries(this);
            ...
          }
          
          protected override void OnBarUpdate()
          {
            if (CurrentBar < 3) return;           // Make sure there are enough bars.
          
            if(CurrentBar < (Pr + (Pr * 1.5))){VarSto = StK;}
            else
            {
              myDataSeries2.Set(((1 - MyConst) * (VarStoSeries[3])) + (MyConst * Close));
              VarSto = SMA(myDataSeries2, 2)[0];
            }
            VarStoSeries.Set( VarSto );
          }
          Get the idea?

          Comment


            #20
            Yes, thank you I believe I understand it. So that would be the typical method employed to store previous data values in NT then?

            Comment


              #21
              Correct. You can either use DataSeries objects to store an array of values or if you only need the previous you can just pass the value on to a second variable.
              Josh P.NinjaTrader Customer Service

              Comment


                #22
                thank you

                oh Yes, thank you I believe I understand it. So that would be the typical method employed to store previous data values in NT then?

                Comment


                  #23
                  As Josh has pointed out, you can use either technique, depending on how far back you want to access.

                  Keep in mind that using a DataSeies will use much, much more memory than just allocating a double, but the DataSeries will give you more possible functionality for the extra memory cost.

                  Don't use a screwdriver if what you really need is a chisel.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by pdennis, Today, 07:43 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by NinjaTrader_Brandon, Today, 07:49 AM
                  0 responses
                  9 views
                  0 likes
                  Last Post NinjaTrader_Brandon  
                  Started by b16_aln, Today, 05:15 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by Negustrader, Today, 01:01 AM
                  1 response
                  17 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by soon123, Yesterday, 10:50 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Working...
                  X