Accessing List objects

Created at 07 Jul 2023, 10:39
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
GI

Giorgi_1

Joined 23.06.2023

Accessing List objects
07 Jul 2023, 10:39


Hi All, 

Hopefully this is just a quick and easy one! I've created a list, and i've added some elements to it. I was hoping i'd be able to run a for loop to access each individual entry, but my output is just a single "0", followed by a further single, "1".

            var highbars = MarketData.GetBars(TimeFrame.Daily, SymbolName);
            var plist = new List<DataSeries>(); 
            
            plist.Add(highbars.HighPrices);
            
            for(int i=0; i<=plist.Count(); i++)
                {
                
                   Print(i); 
                    
                }

I wanted to output each of the values of the list. Could anyone point me in the right direction? 

Thank you


@Giorgi_1
Replies

Best.Algo.Trader
07 Jul 2023, 10:48

With plist.Add(highbars.HighPrices) you just add the whole list of high prices as one single element of your own list.

And actually you don't need a new list. HighPrices is already one. Just try this code below:

var highbars = MarketData.GetBars(TimeFrame.Daily, SymbolName);
            
foreach(double price in highbars.HighPrices)
{
    Print(price);
}

 


@Best.Algo.Trader

Giorgi_1
07 Jul 2023, 10:54

RE:

Kaspricci said:

With plist.Add(highbars.HighPrices) you just add the whole list of high prices as one single element of your own list.

And actually you don't need a new list. HighPrices is already one. Just try this code below:

var highbars = MarketData.GetBars(TimeFrame.Daily, SymbolName);
            
foreach(double price in highbars.HighPrices)
{
    Print(price);
}

 

Ah ok, i understand. I've added the list, not the elements of the list. 

Thank you for clarifying :)

Do you know if there's a function or selection i can use to remove duplicates from a list? 


@Giorgi_1