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 GodAtum, Today, 09:52 AM
                8 responses
                15 views
                0 likes
                Last Post GodAtum
                by GodAtum
                 
                Started by WHICKED, 06-27-2023, 12:07 PM
                83 responses
                864 views
                1 like
                Last Post NinjaTrader_ChelseaB  
                Started by Rxxar, Today, 09:56 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by catinabag, Today, 08:56 AM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by flonkle, Today, 01:19 AM
                3 responses
                25 views
                0 likes
                Last Post flonkle
                by flonkle
                 
                Working...
                X