How can i caode an array only with "sell" or "buy" active orders?

Created at 02 Aug 2017, 01:04
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!
IV

ivan-rifo

Joined 06.07.2017

How can i caode an array only with "sell" or "buy" active orders?
02 Aug 2017, 01:04


Hello Everyone,

 

I would really appreciate your help with, how to code and array with only "sell" or "buy" active orders and if is possible to compare this array with a second array which contents a different quantity of elements.

 

Thank you very much for your attention

IR 


@ivan-rifo
Replies

Spotware
02 Aug 2017, 09:29

Dear ivan-rifo,

See below a code sample on how split your active orders into two lists of Buy and Sell orders.

            var listSellOrders = new List<PendingOrder>();
            var listBuyOrders = new List<PendingOrder>();
            foreach (var order in PendingOrders)
            {
                if (order.TradeType == TradeType.Sell)
                    listSellOrders.Add(order);
                else
                    listBuyOrders.Add(order);
            }

In order to use the List class you need to reference  System.Collections.Generic namespace. See below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Collections.Generic;

Regarding the comparison, which attribute of the two lists would you like to compare?

Best Regards,

cTrader Team


@Spotware