Labels and a New Method to Create Orders

Created at 13 Feb 2013, 10:37
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!
admin's avatar

admin

Joined 30.09.2011

Labels and a New Method to Create Orders
13 Feb 2013, 10:37


MarketOrderRequest

Creates a market order request that can be used as a parameter in the Trade.Send() method, in order to send a market order request to the server. It is similar to Trade.CreateBuyMarketOrder and Trade.CreateSellMarketOrder with the addition that there are more parameters that can be specified such as Label, Slippage and SL/TP in pips. The Label is typically used as a user identifier of the order created by a specific robot.

Required Parameters

Type

Parameter Name

Description

TradeType

tradeType

Buy or Sell

int

volume

Trade monetary amount


Optional Parameters

Type

Parameter Name

Description

string

 

Label

Label can be used to identify the position or order created with this order request

int

SlippagePips

SlippagePips can be used to set the range (in pips) from the current rate for which the order can be filled. When range is specified, actual executed price cannot vary from the current price for more than specified value

int

StopLossPips

StopLossPips may be used to set the stop loss in pips

int

TakeProfitPips

TakeProfitPips may be used to set the take profit in pips


Example 1:

var request = new MarketOrderRequest(TradeType.Buy, 10000);
Trade.Send(request);

Example 2:

var request = new MarketOrderRequest(TradeType.Sell, 10000)
                    {
                        Label = " Robot1",
                        SlippagePips = 2,
                        StopLossPips = 10,
                        TakeProfitPips = 20
                    };
Trade.Send(request); 

Example 3:

var request = new MarketOrderRequest(TradeType.Buy, 1000)
                    {
                        Label = "58999"
                    };
Trade.Send(request); 


LimitOrderRequest and StopOrderRequest

LimitOrderRequest and StopOrderRequest create limit and stop order requests respectively, which can be used as parameters in the Trade.Send() method, in order to send a limit/stop order request to the server. Just as in Trade.CreateSellLimitOrder/CreateBuyLimitOrder and Trade.CreateSellStopOrder/CreateBuyStopOrder with the addition that Label can be assigned. The Label is typically used as an identifier of the order created by a specific robot. 


Required Parameters

Type

Parameter Name

Description

TradeType

tradeType

Buy or Sell

int

volume

Trade monetary amount

double

targetPrice

The price the order should filled at


Optional Parameters

Type

Parameter Name

Description

string

 

Label

Label can be used to identify the position or order created with this order request

double?

StopLoss

StopLoss may be used to set the stop loss in price

double?

TakeProfit

TakeProfit may be used to set the take profit in price

DateTime?

Expiration

The date and time the order should expire


Example 1:

var request = new LimitOrderRequest(TradeType.Sell, 1000, targetPrice);
Trade.Send(request);

Example 2:

var request = new StopOrderRequest(TradeType.Sell, 1000, targetPrice)
                        {
                            Expiration = DateTime.Now.AddMinutes(30),
                            Label = "Robot32",
                            StopLoss = stopLoss,
                            TakeProfit = takeProfit
                        };
Trade.Send(request);

@admin
Replies

admin
13 Feb 2013, 10:43

Position.Label and PendingOrder.Label

Label

A Label is an identifying string, associated with an order or position. One can specify a label using the new request-based API for creating orders; in that case the created order will have the specified label. When the order is filled, the resulting position will also have the same label.

Example 1:

protected override void OnBar()
{
       var request = new MarketOrderRequest(TradeType.Buy, 10000)
                            {
                                Label = "MarketOrderLabel"                                 
                            };
       Trade.Send(request);
}
protected override void OnPositionOpened(Position openedPosition)
{
       Print("Position Label is {0}", openedPosition.Label);
}

Example 2:

protected override void OnStart()
{
    double targetPrice = Symbol.Ask + 10 * Symbol.PipSize;
    var request = new StopOrderRequest(TradeType.Buy, 10000, targetPrice)
                        {
                            Label = "1234"
                        };

    Trade.Send(request);
}

protected override void OnPendingOrderCreated(PendingOrder newOrder)
{
    Print("Order Label is {0}", newOrder.Label);
}

protected override void OnTick()
{
    foreach (var position in Account.Positions)
    {
        if (position.Label == "1234" && position.GrossProfit < 0)
        {
            Trade.Close(position);
        }
    }
}

 


@admin

Uche
14 Feb 2013, 16:20

There is an error message that says "namespace could not be found" for the StopOrderRequest.

How can this be solved?


@Uche

Uche
14 Feb 2013, 16:37

Also, is there a way to count the number of active positions/orders with same label?

 

 


@Uche

admin
14 Feb 2013, 16:54

This will be available in the next release.

The namespace is cAlgo.API.Requests;


@admin

admin
14 Feb 2013, 16:59

RE:
Uche said:

Also, is there a way to count the number of active positions/orders with same label?

 

 

For positions in the account:

var count = Account.Positions.Count(position => position.Label == "1234");

For pending orders in the account:

var count = Account.PendingOrders.Count(order => order.Label == "1234");




@admin

Uche
19 Feb 2013, 15:51


Hello admin,

I get an error message when I use the code below.Why?

var count_pos = Account.Positions.Count(position => position.Label == "1256");
var count_pen = Account.PendingOrders.Count(order => order.Label == "1256");



@Uche

Uche
20 Feb 2013, 17:33

Label count

Is there a solution for the problem in my previous post.

 

Thanks


@Uche

cAlgo_Fanatic
20 Feb 2013, 18:02

please use this namespace:

using System.Linq;


@cAlgo_Fanatic

Uche
20 Feb 2013, 19:16

Works now.

 

Thanks


@Uche

phamvanthanh
06 Mar 2013, 10:52

Hi admin,

anyway to control slippages for pending orders which have become market orders?

 


@phamvanthanh

cAlgo_Fanatic
06 Mar 2013, 11:33

Currently no. Market range can be implemented for Stop Order Requests in the future. Limit Orders don't have any slippage.


@cAlgo_Fanatic

amiscell
03 Feb 2014, 16:25

RE:

cAlgo_Fanatic said:

Currently no. Market range can be implemented for Stop Order Requests in the future. Limit Orders don't have any slippage.

Is slippage on stop orders this still in the plans?


@amiscell

AlexanderRC
17 Mar 2014, 13:13

RE: RE:

amiscell said:

cAlgo_Fanatic said:

Currently no. Market range can be implemented for Stop Order Requests in the future. Limit Orders don't have any slippage.

Is slippage on stop orders this still in the plans?

Repeating the question. Any plans for this?


@AlexanderRC

Spotware
17 Mar 2014, 14:05

Yes, we have market range for stop orders feature in our road map.


@Spotware

tekASH
17 Mar 2014, 20:35

Hello Admin

today while opening cTrader I was asked to download updates of 12.5 mb...usually, after installign updates it shows what's new....but this it didnt. What novelties are installed lately?

note: I had installed February updates prior to this one.


@tekASH

Spotware
18 Mar 2014, 09:14

RE:

tekASH said:

Hello Admin

today while opening cTrader I was asked to download updates of 12.5 mb...usually, after installign updates it shows what's new....but this it didnt. What novelties are installed lately?

note: I had installed February updates prior to this one.

cTrader had to to be updated, because we extended cAlgo.API. History collection was added.
cTrader was optimized and several minor issues were fixed in last release.


@Spotware

Martin
14 Oct 2014, 16:21

RE:

Spotware said:

Yes, we have market range for stop orders feature in our road map.

Is this already implemented?


@Martin

Spotware
14 Oct 2014, 17:41

RE: RE:

Martin said:

Spotware said:

Yes, we have market range for stop orders feature in our road map.

Is this already implemented?

No, it is not implemented yet


@Spotware

Martin
14 Oct 2014, 19:10

RE: RE: RE:

Spotware said:

Martin said:

Spotware said:

Yes, we have market range for stop orders feature in our road map.

Is this already implemented?

No, it is not implemented yet

You have any ideas when will it be implemented?


@Martin

Spotware
15 Oct 2014, 09:21

RE: RE: RE: RE:

We cannot provide a time estimate for release at the moment.


@Spotware

ezoforx
06 Apr 2015, 20:42

Please dont make it forever.. We are waiting for so long..


@ezoforx