Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting error when 3rd previous candle count is used for CLose or Open values

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

    Getting error when 3rd previous candle count is used for CLose or Open values

    Hello:
    I am not able to execute strategy as soon as I use Close[2] or Open[2] , last 3rd Candle values to compare with Open or Close of current candle or 2nd last candle 1.

    Here is the statement causing issues in the Log.


    if (Close[2] < Open[2] && Close[1] > Open[1] && Close[0] > Close[1] && Low[1] < Low[2])
    {
    Bull_123_Bar = true;
    }

    Here is the log I get.

    Strategy 'A1_M': Error on calling 'OnBarUpdate' method on bar 1: Object reference not set to an instance of an object.
    Strategy 'A1_M': Error on calling 'OnBarUpdate' method on bar 1: Object reference not set to an instance of an object.
    Strategy 'A1_M': Error on calling 'OnBarUpdate' method on bar 1: Object reference not set to an instance of an object.

    Please advise how do i make use of last 3 to 4 candles open and close data.

    Thanks,

    #2
    I increased the data series to load for 100 days and then I am able to run the strategy.
    Is that the fix ?

    Comment


      #3
      Hello mtamaku,

      If you are using a barsAgo index of 2, you will need to wait until there are 3 bars processed in OnBarUpdate().

      if (CurrentBar < 2)
      return;

      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kinfxhk, 07-13-2026, 10:18 AM
      0 responses
      59 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 09:50 AM
      0 responses
      41 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 07:21 AM
      0 responses
      46 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-11-2026, 02:11 AM
      0 responses
      37 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      157 views
      0 likes
      Last Post SalmaTrader  
      Working...
      X