Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

array of most recent bars for all instruments?

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

    array of most recent bars for all instruments?

    I have a function in one of my scripts that takes for arguments the most recent close for all bars on the chart. So, if for instance I have 3 instruments, the function call would look like:
    Code:
    MyFunction(Closes[0][0], Closes[1][0], Closes[2][0])
    However, sometimes there will be more bars on a chart, sometimes less. Therefore I can't hard code the function arguments as above. Instead I'd like to pass a 1-dimensional array into the function, with each element representing the current close for each instrument.
    Code:
    MyFunction(my_array_of_current_bar_closes)
    Is there an easy way to represent this array, or would I have to create it. Something like Closes[:][0]?

    #2
    Hello,

    Thank you for the question.

    In this case, you could pass the whole Closes collection to the method and allow the method to separate the data as needed. You could also pass any type of object you want such as an array. I composed a small sample of both ways below.


    Code:
    protected override void OnBarUpdate()
    {
            MyFunction(Closes);
    	double[] myArr = new [] {Closes[0][0], Closes[1][0], Closes[2][0]};
    	MyFunction(myArr);
    }
    
    void MyFunction(PriceSeries[] closes)
    {
        if (closes.Length == 3)
        {
            Print(string.Format("Found 2 series: {0} - {1} - {2}", closes[0],closes[1]));
        } else if (closes.Length == 4) 
        {
    		Print(string.Format("Found 3 series: {0} - {1} - {2}", closes[0],closes[1], closes[2]));
        }
    }
    
    void MyFunction(double[] closes)
    {
       foreach(double close in closes)
       {
    		Print(close);   
       }
    }


    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    661 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    376 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    110 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
    580 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X