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

Intinger values can not be called in OnRender()

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

    Intinger values can not be called in OnRender()

    Hello!
    I have cerated a section region helpers in which I hve some calculations using Series<int>. Iwanted to call these values in OnRender() for drawing purpuses.
    I have use the print function in the region helpers ass well as in OnRender() to vue if there is any mistake. The print function pups up the values from the region helpers which are different from zero, but those from OnRender() have the value zero.
    Here is the snapshot of the code:
    HTML Code:
     #region Variables
       private Series<int> strength;
    
       if (State == State.DataLoaded)
       {
         strength = new Series<int>(this);
       }
    #endregion
       #region Helpers
         strength[count] = temp_strength[i];
         Print("strength" + " Size " + ":  " + strength[count]);
      #endregion
    
      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      {
        for(int idx = 0; idx < count; idx++)
        {
          int valStrength = strength.GetValueAt(idx);
          Print("ValStrength" + " Size " + ":  " + ValStrength);
        }
      }
    I would highly appreciate if someone could point out where I am mistaking.

    Best regards,
    Last edited by Stanfillirenfro; 04-22-2024, 09:23 AM.

    #2
    Hello Stanfillirenfro,

    Thank you for your post.

    Where is the Helpers region in relation to the rest of the code? When are the strength values being assigned? Is possible they are being assigned after you are trying to get the value in OnRender?

    Are the values returning null, or 0?

    I look forward to assisting further.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Many thanks NinjaTrader_Gaby for your reply.

      Where is the Helpers region in relation to the rest of the code?
      The region Helpers comes directly after OnBarUpdate() and directly before OnRender().

      When are the strength values being assigned?
      They are assigned in the region Helpers.
      Is possible they are being assigned after you are trying to get the value in OnRender?
      No! It is the reason why I have OnRender() after region Helpers.
      Are the values returning null, or 0?
      The values are returning 0.

      Thanks in advance!

      Comment


        #4
        Hello Stanfillirenfro,

        Is this Helpers region just outside of any method? This would mean this code is likely only being executed once. It's not going to be assigning an updated value to the series on every pass of OnBarUpdate() or OnRender() if it is outside of any methods.

        It would be better to assign the series a value from a method like OnBarUpdate(). Please see this example script demonstrating.
        Attached Files
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Many thanks NinjaTrader_Gaby for your reply.

          In the example you have posted, the Series are assigned in OnBarUpdate().
          In my case, I am assigning my Series in region Helpers.

          Is there a way to assign values in region Helpers and to used them in OnRender()?

          Comment


            #6
            Hello,

            Thank you for your response.

            All logic must be inside a method. What method is your Helpers region located in? Is it inside OnStateChange and if so, is it inside a State.DataLoaded condition? If not, could you please specify where or provide a more complete example of your code so we can take a look?

            Thank you in advance.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              Many hanks NinjaTrader_Gaby for your reply.

              HTML Code:
              protected override void OnBarUpdate()
              {
                 myZones();
              }
              
              #region Helpers       void myZones()
              {
                for(i = 0; i < temp_count; i++)
                {
                  strength[temp_count] = temp_strength[i];
                }
              }    #endregion
              Last edited by Stanfillirenfro; 04-22-2024, 01:49 PM.

              Comment


                #8
                Hello,

                If you are calling myZones() from OnBarUpdate(), it is possible to get the series values from OnRender().

                Please see the attached sample script demonstrating. If you are unable to get this to work in your own script, you will need to debug using prints.

                This guide goes over how to use prints to debug: https://support.ninjatrader.com/s/ar...nd-TraceOrders

                Please let us know if you have any further questions.
                Attached Files
                Gaby V.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ETFVoyageur, Today, 04:00 PM
                0 responses
                5 views
                0 likes
                Last Post ETFVoyageur  
                Started by AaronKTradingForum, Today, 03:44 PM
                1 response
                8 views
                0 likes
                Last Post AaronKTradingForum  
                Started by Felix Reichert, 04-26-2024, 02:12 PM
                11 responses
                77 views
                0 likes
                Last Post Felix Reichert  
                Started by junkone, 04-28-2024, 02:19 PM
                7 responses
                83 views
                1 like
                Last Post junkone
                by junkone
                 
                Started by pechtri, 06-22-2023, 02:31 AM
                11 responses
                138 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Working...
                X