Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error:Object reference not set to an instance of an object.

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

    Error:Object reference not set to an instance of an object.

    First of all , I would like to thank the awesome support guys, as I know you are very prompt and clear in your responses. Keep up the good work guys.
    I have a piece of code It is giving an Error: Error on calling 'OnBarUpdate' method for strategy 'CDCandle/0a84bcadcad749288376ff725280a69d': Object reference not set to an instance of an object.

    protected override void Initialize()
    {

    CalculateOnBarClose = true;
    Add(PeriodType.Minute,30);
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if(CDMA(BarsArray[1],true, GomCDCalculationModeType.BidAsk, GomCDChartType.CumulativeChart, Color.Bisque, "Alert2.wav", false, 14, 3, 0.7, Color.Honeydew, "Alert1.wav", 1000000, 1).DeltaOpen[0] == null
    || CDMA(true, GomCDCalculationModeType.BidAsk, GomCDChartType.CumulativeChart, Color.Bisque, "Alert2.wav", false, 14, 3, 0.7, Color.Honeydew, "Alert1.wav", 1000000, 1).DeltaClose[0] == null
    ||Close[0] == null
    || Opens[1][0]== null
    )

    {
    return;
    }

    else
    {
    // Condition set 1
    if (CDMA(true, GomCDCalculationModeType.BidAsk, GomCDChartType.CumulativeChart, Color.Bisque, "Alert2.wav", false, 14, 3, 0.7, Color.Honeydew, "Alert1.wav", 1000000, 1).DeltaClose[0] > CDMA(BarsArray[1],true, GomCDCalculationModeType.BidAsk, GomCDChartType.CumulativeChart, Color.Bisque, "Alert2.wav", false, 14, 3, 0.7, Color.Honeydew, "Alert1.wav", 1000000, 1).DeltaOpen[0]
    && Close[0] > Opens[1][0]
    )
    {
    EnterLong(DefaultQuantity, "");
    }
    }

    Can you please tell what is wrong with the code, I beleive I might have missed some null exception. But, can't find where

    #2
    Hello VarunDivakar,

    Thanks for your note.

    You should use a check that there are enough bars for both series before calling a bar in that series.

    For example:
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    return;

    This requires that both Barsinprogress 0 has at least 1 bar and BarsInProgress 1 has 1 at least 1 bar.

    Please let me know if this does not resolve the error.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thank you for such a fast response. Now, I am faced with another error :

      Enabling NinjaScript strategy 'CDCandle/d0c2db4f4ad44970b53cea27861f8708' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes

      Comment


        #4
        Hello VarunDivakar,

        This message means that the strategy was enabled and is providing information about the state of the strategy.

        Do you have an error that I may assist with?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi, the strategy keeps getting unchecked and stops working as soon as check it in the strategy tab.

          Comment


            #6
            Hello VarunDivakar,

            Has the selected account been changed?

            Are there any other error messages in the Log tab of the Control Center (in yellow)?
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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