• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EMA and T3 error

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

    EMA and T3 error

    Hello

    I am coding a strategy that uses a crossover of two T3 moving averages and the strategy stops and throws the error message in the output window: "Error: Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object."

    At the same time, the Log shows: "Indicator EMA: Error on calling OnBarUpdate method on bar xxxx: You are trying to access an index with a value that is invalid since it is out of range. I E accessing a series [barsAgo] with an value of 5, when there are only 4 bars on the chart". This error usually comes up twice for the EMA and once for the T3, with the same message.

    The next error in the log is an identical message with the one in the strategy output window, as above.

    When I run the strategy in Debug mode, Visual Studio stops first at the EMA error, then when I click Continue, it stops at the T3 error, then if I click Continue again, it runs normal to the end of the test period. Needles to say, I don't really understand what the messages in the Visual Studio prompts mean

    I'm using Market Replay Data with Playback connection, but it does the same with the live market data connection.

    So far, it seems that this is happening only when I include in the triggering logic the condition,

    Code:
    (CrossAbove(T31b2, T32b2, 1)
    but I can.t figure it out why, or, if I made a mistake setting up the T3, how come it runs after that?

    This is my T3 code

    Code:
    public class ATM2 : Strategy
        {    
           private T3 T31b0;
            private T3 T32b0;
            private T3 T31b2;
            private T3 T32b2;
    ....
               else if (State == State.Configure)                
                    {
                        AddDataSeries(Data.BarsPeriodType.Tick, 1);
                        AddDataSeries(Data.BarsPeriodType.Minute, 5);
                    }
    
                else if (State == State.DataLoaded)
                {
    ....
                    T31b2                = T3(Closes[2], 5, 3, 0.7);
                    T32b2                = T3(Closes[2], 8, 3, 0.7);
                    T31b0            = T3(Closes[0], 5, 3, 0.7);
                    T32b0            = T3(Closes[0], 8, 3, 0.7);
                    T31b0.Plots[0].Brush = Brushes.Transparent;    
                    T32b0.Plots[0].Brush = Brushes.Transparent;                    
                    AddChartIndicator(T31b0);
                    AddChartIndicator(T32b0);
    Attached Files

    #2
    Hi itrader46, thanks for your post.

    From the screenshot it looks like you need to check for at least "Period" amount of bars before processing the EMA. So check for :

    if(CurrentBars[0] < "EMA Period")
    return;

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      That's what it looks like, but the strategy starts 5am and the error appears around 9am... plenty of bars, I would have thought!

      Comment


        #4
        Hi itrader46,
        NinjaTrader does not have preloadbar functionality.
        https://ninjatrader.com/support/foru...8-preload-bars
        Please add your vote, if you would like to see this being changed.
        NT-Roland

        Comment


          #5
          This keeps happening! As you can see from the output window prints, it works fine, then at some point it realises: 'Hold on! I don't have enough bars here!... Error'. I thought the code below would prevent just that from happening?!?

          Code:
                      if (CurrentBars[0] < BarsRequiredToTrade
                      || CurrentBars[2] < BarsRequiredToTrade)
                          return;    
          .....
          
                     if (T31b2 == null || T32b2 == null)
                      {
                          T31b2 = T3(BarsArray[2], 5, 3 ,0.7);
                          T32b2 = T3(BarsArray[2], 8, 3 ,0.7);
                      }
          Output prints:

          Enabling NinjaScript strategy 'ATM2/178977517' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=True CancelExitsOnStrategyDisable=True Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes
          ++++++++++
          Long condition at: 56.64 - Current Ask: 56.64 - S = 1 - Open: 56.6 - Current Bar: 5067 @ 11/11/2019 14:38:00
          Long ATM triggered at: 56.64 - Open: 56.6 - Current Bar: 5067 - Long order bar: 5067 - 11/11/2019 14:38:00
          ##########
          XX>>-- Long condition false price: 56.63 - Trigger Long Price: 56.64 - Current Bar: 5067 - 11/11/2019 14:38:00
          Long ATM cancel cond 1 price: 56.61 - Trigger Long Price: 56.64 - Open: 56.6 - Current Bar: 5067 - 11/11/2019 14:38:00
          >>> Long Order ID Reset Price: 56.61 - Open: 56.6 - Current Bar: 5067 - 11/11/2019 14:38:00
          >>## Long ATM ID Reset Price: 56.61 - Open: 56.6 - Current Bar: 5067 - 11/11/2019 14:38:00
          ++++++++++
          Long condition at: 56.59 - Current Ask: 56.59 - S = 1 - Open: 56.53 - Current Bar: 5071 @ 11/11/2019 14:42:00
          Long ATM triggered at: 56.59 - Open: 56.53 - Current Bar: 5071 - Long order bar: 5071 - 11/11/2019 14:42:00
          ##########
          Cond False Long Reset - Current Ask: 56.59 - Current Bar: 5071
          XX>>-- Long condition false price: 56.58 - Trigger Long Price: 56.59 - Current Bar: 5072 - 11/11/2019 14:43:00
          Long ATM cancel cond 4 price: 56.58 - Trigger Long Price: 56.59 - Long order bar: 5071 - Open: 56.58 - Current Bar: 5072 - 11/11/2019 14:43:00
          >>> Long Order ID Reset Price: 56.58 - Open: 56.58 - Current Bar: 5072 - 11/11/2019 14:43:00
          >>## Long ATM ID Reset Price: 56.59 - Open: 56.58 - Current Bar: 5072 - 11/11/2019 14:43:00
          ++++++++++
          Long condition at: 56.61 - Current Ask: 56.61 - S = 1 - Open: 56.6 - Current Bar: 5073 @ 11/11/2019 14:44:00
          'GetAtmStrategyEntryOrderStatus' method error: Order ID 'e13d2df6241f42f8930e0810c5e1bd2b' does not exist
          'GetAtmStrategyEntryOrderStatus' method error: Order ID 'e13d2df6241f42f8930e0810c5e1bd2b' does not exist
          'GetAtmStrategyEntryOrderStatus' method error: Order ID 'e13d2df6241f42f8930e0810c5e1bd2b' does not exist
          'GetAtmStrategyEntryOrderStatus' method error: Order ID 'e13d2df6241f42f8930e0810c5e1bd2b' does not exist
          'GetAtmStrategyEntryOrderStatus' method error: Order ID 'e13d2df6241f42f8930e0810c5e1bd2b' does not exist
          Long ATM triggered at: 56.61 - Open: 56.6 - Current Bar: 5073 - Long order bar: 5073 - 11/11/2019 14:44:00
          ##########
          Cond False Long Reset - Current Ask: 56.61 - Current Bar: 5073
          XX>>-- Long condition false price: 56.6 - Trigger Long Price: 56.61 - Current Bar: 5073 - 11/11/2019 14:44:00
          Cond False Long Reset - Current Ask: 56.62 - Current Bar: 5073
          >>> Long Order ID Reset Price: 56.64 - Open: 56.6 - Current Bar: 5073 - 11/11/2019 14:44:00
          >>## Long ATM ID Reset Price: 56.84 - Open: 56.8 - Current Bar: 5078 - 11/11/2019 14:49:00
          Strategy 'ATM2': Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object.
          Disabling NinjaScript strategy 'ATM2/178977517'
          11/11/2019 14:53:00 CancelAllOrders: BarsInProgress=0
          05/11/2019 23:00:00 CancelAllOrders: BarsInProgress=1
          05/11/2019 23:05:00 CancelAllOrders: BarsInProgress=2

          Comment


            #6
            Hello itrader46,

            You are receiving the following error which is disabling your strategy:

            Strategy 'ATM2': Error on calling 'EventHandlerBarsUpdate' method: Object reference not set to an instance of an object.

            This would mean that you are referencing an object that is null. This is not the same thing as an index out of range error which would be seen if you are referencing some BarsAgo value before the script processes that many bars.

            I suggest debugging the code in your EventHandlerBarsUpdate method by adding prints so you can find out which specific line is creating the "Object reference not set to an instance of an object" error. (The output is hinting that this error is being thrown in your EventHandlerBarsUpdate method.)

            Debugging tips - https://ninjatrader.com/support/help...script_cod.htm

            Checking for null references - https://ninjatrader.com/support/help...references.htm

            Please let us know if you have any additional questions.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by pstrusi, Today, 09:06 AM
            0 responses
            1 view
            0 likes
            Last Post pstrusi
            by pstrusi
             
            Started by vpzdcv, Today, 02:31 AM
            0 responses
            8 views
            0 likes
            Last Post vpzdcv
            by vpzdcv
             
            Started by YevhenShynkarenko, Today, 01:22 AM
            1 response
            18 views
            0 likes
            Last Post YevhenShynkarenko  
            Started by ttodua, Today, 12:52 AM
            0 responses
            7 views
            0 likes
            Last Post ttodua
            by ttodua
             
            Started by ttodua, Today, 12:50 AM
            0 responses
            6 views
            0 likes
            Last Post ttodua
            by ttodua
             
            Working...
            X