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 sjsj2732, Yesterday, 04:31 AM
            0 responses
            30 views
            0 likes
            Last Post sjsj2732  
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            286 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            282 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            132 views
            1 like
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            90 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Working...
            X