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

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 jaybedreamin, Today, 05:56 PM
            0 responses
            2 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Working...
            X