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

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:	87
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:	80
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:	86
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.
    Brandon H.NinjaTrader Customer Service

    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
        Brandon H.NinjaTrader Customer Service

        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 AaronKoRn, Today, 09:49 PM
          0 responses
          11 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Today, 08:42 PM
          0 responses
          10 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Today, 07:51 PM
          0 responses
          11 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,980 views
          3 likes
          Last Post jhudas88  
          Started by rbeckmann05, Today, 06:48 PM
          0 responses
          9 views
          0 likes
          Last Post rbeckmann05  
          Working...
          X