Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Function of the #region Helpers as argument of a function in OnBarUpdate

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

    Function of the #region Helpers as argument of a function in OnBarUpdate

    Hello! I am failing since a certain time already to sle a problem related to a unction of the region Helpers as argument of a function in protected override void OnBarUpdate.
    I am having the following error message:
    Error on calling "OnBarUpdate" method on bar 500: Object reference not set to an instace of an object.
    In the region parameters, I have:
    HTML Code:
      private double [][] Val1 = new double[2][];
    In OnBarUpdate:
    HTML Code:
     if(CurrentBar < 500) return;
     double mov = EMA(Close, 14)[0];
     double myEMA = CostFunc(mov, 15, 0,618);
    In the region Helpers I have:
    HTML Code:
    #region Helpers
    double CostFunc(double myPrice, int period, double y)
    {
      Val1[1]]0] = y*2
      Val1[2]]0] = 7y*5
      return(Val1[1][0] + Val1{[2]]0]);
    }
    I made sure with the condition " if(CurrentBar < 500) return;" that I will not reach 500 bars with my array. How is it possible that the error occured on bars 500?
    Why is the function of the region Helpers creating problem in "OnBarUpdate"?

    I would apprecaite any help.

    Thanks in advance.
    Last edited by Stanfillirenfro; 10-18-2022, 05:37 AM.

    #2
    Hello Stanfillirenfro,

    Thank you for your inquiry.

    Are you trying to use a multidimensional array for Val1? If so, I suspect there is an issue with the declaration of the array containing empty square brackets. In C#, multidimensional arrays are declared with one set of square brackets that contains commas depending on how many dimensions are being used. Here is a publicly available link from the Microsoft website with more information:
    Store multiple variables of the same type in an array data structure in C#. Declare an array by specifying a type or specify Object to store any type.


    Also, double-check all of your brackets and ensure they are opening/closing properly. In the following lines, it appears that the bracket before the zero is potentially facing the wrong direction:

    Val1[1]]0] = y*2
    Val1[2]]0] = 7y*5
    return(Val1[1][0] + Val1{[2]]0]);

    Please let us know if we may be of further assistance.​

    Comment


      #3
      Many thanks NinjaTrader_Emily for your reply.

      I was using here a JAGGED ARRAY which is also used in C#. Checking the documentation you sent me I have realized that I was not initializing each element of the array. I think the problem should be there.
      I have checked the brackets too. Thanks!
      I have to reimplement the code again and I will revert to you very soon.

      Many thanks again.

      Comment

      Latest Posts

      Collapse

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