Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to fix this problem ?

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

    How to fix this problem ?

    I coded a simple indicator. This indicator is supposed to plot a histogram bar when the previous candle is an up candle. It compiles without problem. However, it just doesn't plot anything. After attaching it to the chart, the indicator window shows blank. The code is very simple, the OnBarUpdate() section only consists of one line. How to fix it ? The source code under OnBarUpdate() is as following:

    protected override void OnBarUpdate()
    {
    Value[0]=(Close[1]>Open[1] ? 1:0);
    }

    The complete source code file is as attached.

    Thank you in advance for anyone that can help. MyCustomIndicator1.cs

    #2
    Hello Pooh123,

    On the first bar, there is no bar 1 bar ago. When CurrentBar is 0, Close[1] is an invalid index.

    Are you getting any errors in the Log tab of the Control Center?

    If you print the value of Value[0] does anything print?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Yes, you were right. I tried adding the following code and it worked:

      if (CurrentBar < 1 ) return;


      It solved the problem.

      Thank you,
      Pooh

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      156 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      90 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      140 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X