Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarWidth and BarDistance doesn't apply until chart is scrolled

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

    BarWidth and BarDistance doesn't apply until chart is scrolled

    I am trying to adjust the BarWidth and BarDistance from an indictor. I use the following code to apply these changes in OnRender() function only once.

    Code:
    chartControl.BarWidth = barWidth;
    chartControl.Properties.BarDistance = barDistance;​
    This is the chart before applying the indictor.
    Click image for larger version

Name:	1.png
Views:	137
Size:	700.9 KB
ID:	1268181

    This is how it looks after the indicator is applied.
    Click image for larger version

Name:	2.png
Views:	131
Size:	739.6 KB
ID:	1268182

    And, this is how it looks after scrolling the chart. Candles don't even need to move. Just a user interaction on the chart is enough.
    Click image for larger version

Name:	3.png
Views:	142
Size:	205.5 KB
ID:	1268183

    How can I adjust the indicator code to render the chart correctly after the indicator is added?

    #2
    Hello barbaros,

    Thanks for your post.

    What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)

    ​How are exactly are you defining chartControl.BarWidth and chartControl.Properties.BarDistance in your script?

    Could you provide a very simple test script that demonstrates the issue and the exact steps used to reproduce the behavior using the very simple test script?

    I look forward to assisting further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi NinjaTrader_BrandonH. I am using NT 8.1.1.7.

      You can easily replicate this if you put the small snippet I shared with some values in the `onBarUpdate` function.

      I noticed something interesting today. When the market opened and a price movement occurred on the chart, it fixes itself automatically. So, here are the steps when there are executions in the market.

      1. Create a new chart
      2. Add the indicator
      3. Observe the bar width and spacing not applied
      4. When price changes, chart fixes itself

      I tried to use `ForceRefresh()` function with no luck.

      Comment


        #4
        Hello barbaros,

        Thanks for your notes.

        I added the code you shared in post # 1 to the OnBarUpdate() section of an indicator. Then, I added the test indicator to the chart window and I am seeing the BarWidth and BarDistance change when the indicator is applied to the chart.

        See this demonstration video: https://brandonh-ninjatrader.tinytak...MV8yMjA1MzUxOA

        I also tested the attached script while not connected to a live data feed connection and I am seeing the BarWidth and BarDistance change when the indicator is applied to the chart.

        Demonstration video: https://brandonh-ninjatrader.tinytak...MF8yMjA1MzU3Mg

        Attached you will find a copy of the indicator used to test this.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Hi NinjaTrader_BrandonH. This did the trick. I was using it in OnRender() with the passed in chartControl paramter but you used the global object in OnBarUpdate(). It seems to work as expected now. Thanks for the help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          636 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          568 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X