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

Passing a BarsArray as a function parameter

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

    Passing a BarsArray as a function parameter

    How can I pass a specific BarsArray to a function? Here is what I am trying:

    Code:
            public void test(double[] myBarsArray){
    
                Print(myBarsArray[1].Count);
    
    
            }

    #2
    Hello swcooke,

    Thank you for your post.

    Are you getting an error when you try to compile this?

    A BarsArray object would be of the type NinjaTrader.Data.Bars - not a double. Try this:

    Code:
            public void test(NinjaTrader.Data.Bars[] myBarsArray){
                   Print(myBarsArray[1].Count);
            }
    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      I am getting an error. Here is my revised code and the error:

      Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public class MyCustomIndicator : Indicator
          {
              public void test(NinjaTrader.Data.Bars[] myBarsArray){
                  Print(myBarsArray[1].Count);
              }
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "MyCustomIndicator";
                      Calculate                                    = Calculate.OnBarClose;
                      IsOverlay                                    = false;
                      DisplayInDataBox                            = true;
                      DrawOnPricePanel                            = true;
                      DrawHorizontalGridLines                        = true;
                      DrawVerticalGridLines                        = true;
                      PaintPriceMarkers                            = true;
                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive                    = true;
                  }
                  else if (State == State.Configure)
                  {
                      AddDataSeries("AAPL", new BarsPeriod {BarsPeriodType = BarsPeriodType.Day, Value = 1}, 30, "US Equities RTH", true);
                  }
                  else if (State == State.DataLoaded)
                  {
                      test(BarsArray[1]);
                  }            
              }
          }
      }
      Error:
      Code:
       [TABLE]
      [TR]
      NinjaScript File 			Error 			Code 			Line 			Column 		[/TR]
      [TR]
      [TD]MyCustomIndicator.cs[/TD]
       			[TD]The best overloaded method match for 'NinjaTrader.NinjaScript.Indicators.MyCustomIndicator.test(NinjaTrader.Data.Bars[])' has some invalid arguments[/TD]
       			[TD]CS1502[/TD]
       			[TD]56[/TD]
       			[TD]5[/TD]
       		[/TR]
      [/TABLE]
      [TABLE]
      [TR]
      NinjaScript File 			Error 			Code 			Line 			Column 		[/TR]
      [TR]
      [TD]MyCustomIndicator.cs[/TD]
       			[TD]Argument 1: cannot convert from 'NinjaTrader.Data.Bars' to 'NinjaTrader.Data.Bars[]'[/TD]
       			[TD]CS1503[/TD]
       			[TD]56[/TD]
       			[TD]10[/TD]
       		[/TR]
      [/TABLE]

      Comment


        #4
        Hello swcooke,

        Thank you for your reply.

        You're not passing the entire array to test().

        Try this:

        Code:
                    else if (State == State.DataLoaded) 
                     {                 test(BarsArray);             }
        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by swcooke View Post
          How can I pass a specific BarsArray to a function? Here is what I am trying:

          Code:
           public void test(double[] myBarsArray){
          
          Print(myBarsArray[1].Count);
          
          
          }
          You may be making things harder than necessary.

          My suggestion:
          Don't pass the array. BarsArray is already global.
          Pass the index instead.

          Code:
          public void test(int index)
          {
              Print(BarsArray[index].Count);
          }
          then just call test(1) where '1' is index of the BarsArray you wish to print the Count of.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jclose, Today, 09:37 PM
          0 responses
          4 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,413 views
          0 likes
          Last Post Traderontheroad  
          Started by firefoxforum12, Today, 08:53 PM
          0 responses
          10 views
          0 likes
          Last Post firefoxforum12  
          Started by stafe, Today, 08:34 PM
          0 responses
          10 views
          0 likes
          Last Post stafe
          by stafe
           
          Started by sastrades, 01-31-2024, 10:19 PM
          11 responses
          169 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X