Create List of Pending Orders

Created at 22 Oct 2013, 21:08
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!
jhtrader's avatar

jhtrader

Joined 15.10.2013 Blocked

Create List of Pending Orders
22 Oct 2013, 21:08


Hi,

I would like to create a list of pending orders and add the last pending order.. similar to the list of open positions

Can you please explain how in the case of opened positions the position variable is allowed but the following code generates an error.  Do I have to create a routine onPendingOrderOpen() or can I just add it when a ConditionalBuy() is successful...

Thanks

 

        private readonly List<PendingOrder> _PendingPositions = new List<PendingOrder>();

 

        ///
        /// Create Conditional Buy Order
        ///
        private void ConditionalBuy()
        {

            LastOrderSuccessful = true;
            //Buy ONCE at each trigger level when the Buy price is under the trigger price
            Trade.CreateBuyStopOrder(Symbol, Volume, ContingentOrderPrice, nullnull);

            if (LastOrderSuccessful)
            {
                Print("CO() ***** CONDITIONAL ORDER SUCCESSFUL!! *****");
                //Add to Pending Order List
                _PendingPositions.Add(PendingOrder order);


            }

        }

 

 

 


Replies

Spotware
23 Oct 2013, 12:08

It has to be added in the OnPendingOrderCreated method. 
cAlgo uses asynchronous operation. So, after it sends the request for a pending order with Trade.CreateBuyStopOrder to the server, the order will not have been created when the execution reaches the next statements  if (LastOrderSuccessful)...            

protected override void OnPendingOrderCreated(PendingOrder newOrder)
{
    _PendingPositions.Add(newOrder);
}

See:
/api/robot/onpendingordercreated-26ec

One more note on C# syntax:
This is not a proper call to a method: _PendingPositions.Add(PendingOrder order);
The above statement will produce a compiler error.
It has to be _PendingPositions.Add(order); 

When you declare methods you need to specify the parameter types:

This is a method declaration:

protected void myMethod(PendingOrder newOrder)
{
    _PendingPositions.Add(newOrder);
}

When you call methods you omit the parameter types. Only the variable name is necessary in the parameter list:
This is a method call:

PendingOrder order = Account.PendingOrders[0]; 
myMethod(order); // This is a method call
myMethod(PendingOrder  order); // This is wrong syntax

See also:
http://msdn.microsoft.com/en-us/library/ms173114.aspx
http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx


@Spotware

Indiv
17 Aug 2015, 02:31

Synchronious or list of pending STOP/LIMIT Buy/Sell orders

Hi

 

Can I have a complete code of creating pending orders based on some pips parameter...

For ex.

EURUSD - Pending order creation start with

1.03712

1.03722

1.03733

1.03744......

 

Appreciate your help.

 

Thanks


@Indiv

Spotware
17 Aug 2015, 21:27

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware