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

String values do not update on Calculate.onBarChange

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

    String values do not update on Calculate.onBarChange

    Hello! I am failing to have my value updated when the bar changes. I have written the code in
    HTML Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
                base.OnRender(chartControl, chartScale);​
    }
    Here is a piece of my code:

    HTML Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
                base.OnRender(chartControl, chartScale);​
    
               UpBuff[0] = (VOL()[0];
    
              string myVal = "myVOLUME : "+UpBuff[0].ToString()+"";
    
              SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory,
                        myVal, textFormat1, ChartPanel.X + ChartPanel.W, textFormat1.FontSize);​
              .
              .
              .
    When the bar closes, the value plotted on the panel does not update. The value appears once when I attach the indicator on the chart and NO UPDATE.

    Could someone please points out what is wrong?

    Many thanks in advance!

    #2
    Hello Stanfillirenfro,

    If you want to have the string update with OnBarUpdate you need to put the code to change the string inside OnBarUpdate. OnRender is a rendering outlet which is called for specific reasons, that is not paired with OnBarUpdate.

    Using bars ago in OnRender is also not valid, there is no concept of bars ago inside OnRender.

    string myVal would need to be defined as a private variable in the class and then you would update that from OnBarUpdate.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Many thanks NinjaTrader_Jesse for your help.

      I have declared myVal as private in the section #Variables.

      After ploting the indicator on the chart, I have the histogram, but NOT The text. I am NOT in OnRender() anymore, but in protected override void OnBarUpdate()

      HTML Code:
      Draw.Text(this, myVal, false, "2", 0, 1, 0, BuyColor, myFont, TextAlignment.Left, null, Brushes.Transparent, 50);
      I wanted the text NOT ONLY left to be aligned, but to start let's say 6 pixels from the left border.

      Could you please advise me how to deal with this issue?

      Thanks in advance!

      Comment


        #4
        Hello Stanfillirenfro,

        Draw.Text requires using a price, you are drawing it at a price of 0 and because you have autoscale set to false it wont be displayed. You can still use OnRender you just need to use OnBarUpdate to update the string value where bars ago can be used. Draw.Text relates to bars and not the panel, if you wanted to use a drawing object you would have to use Draw.TextFixed to have it in one of the corners of the chart. You can otherwise continue using OnRender to draw it at a specific x/y in the chart.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Many thanks NinjaTrader_Jessefor your reply.

          I would really want to draw this text using OnRender. I am wondering how to flip from OnBarUpdate to OnRender with a value. I did that previously, but I have received an error message that myVal, updated in OnBarUpdate, is not recognized in OnRender.

          Whar should I modify in my #post1 to fix the problem?

          Thanks in advance!

          Comment


            #6
            Hello Stanfillirenfro,

            You just need to move the string setting logic you had into OnBarUpdate and make a private variable for the string. You can then use that string in OnRender. Here is a simple example of what that would look like:

            Code:
            private string myString;
            
            protected override void OnBarUpdate()
            {
                myString = VOL()[0].ToString();
            }
            
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
                 // your rendering code that uses myString
            }
            Last edited by NinjaTrader_Jesse; 01-03-2024, 04:19 PM.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks NinjaTrader_Jesse for your help.

              I made the modifications as you have specified above, but this number is not updating unless I check/uncheck the box of "visible.

              I have also used: Calculate.OnEachBar and Calculate.OnBarClose. the number is appearing exactly according to the coordinates, but it is not updating.

              Since it is to late here, I will proceed again tomorrow and I will revert to you again.

              Many thanks again!

              Comment


                #8
                Hello Stanfillirenfro,

                Onrender is only called for certain events like when a bar is updated. This will only work in realtime so if you are testing while the market is not active then no updates will occur. To have the value constantly updated you would need to use OnEachTick so the string can be reset for each tick, it would otherwise only change a value when a bar closes in realtime.

                If you are still using myVal from your post you need to move that into OnbarUpdate and make the string like the sample I made, your string needs to be set from OnBarUpdate if you wanted to use a bars ago for the value you are getting.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Many thanks again NinjaTrader_Jesse for your help.

                  Thanks to your help, I have the code working on all timeframes EXCEPT on tick charts (2000, 1000 ... tick charts). On other time frames, the values are updated without any problem. But on tick charts, there is NO UPDATE. Weird!!!

                  Could you please point out what is wrong with tick charts? I have: CalculateOnEachTick

                  Thanks in advance!

                  Comment


                    #10
                    Hello Stanfillirenfro,

                    From only that detail I would not be sure why its not working on those chart types. Have you tried using a Print in your OnBarUpdate code to verify a new string is being set and to observe the rate OnBarUpdate is being called?

                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      The problem is fixed NinjaTrader_Jesse! It was a if() condition in which I have placed some variables that were not suppose to be there.

                      Many thanks again for your valuable help.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by fx.practic, 10-15-2013, 12:53 AM
                      5 responses
                      5,404 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Started by Shai Samuel, 07-02-2022, 02:46 PM
                      4 responses
                      95 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Started by DJ888, Yesterday, 10:57 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by MacDad, 02-25-2024, 11:48 PM
                      7 responses
                      159 views
                      0 likes
                      Last Post loganjarosz123  
                      Started by Belfortbucks, Yesterday, 09:29 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post Belfortbucks  
                      Working...
                      X