C # I want to set the opening and closing price for a market order

Created at 20 Sep 2018, 11:54
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!
GE

generalovaelena2010

Joined 20.09.2018

C # I want to set the opening and closing price for a market order
20 Sep 2018, 11:54


Hello!

There is a function of opening market orders:

public TradeResult ExecuteMarketOrder (TradeType tradeType, Symbol symbol, double volume, string label, double? stopLossPips, double? takeProfitPips, double? marketRangePips, string comment, bool hasTrailingStop, StopTriggerMethod? stopLossTriggerMethod)

But in this parameters it is not possible to set the price at which the order should be opened. In similar functions on MQL4 / 5, there is such an opportunity. Is there an opportunity for C # to set the opening price for a market order? The parameter marketRangePips specifies price slippage. From what price is this slippage considered?

Similarly for the function: 

public TradeResult ClosePosition (Position position, double volume)

there is no way to set either the closing price and slippage. How can i solve these problems? Thank you!


@generalovaelena2010
Replies

PanagiotisCharalampous
20 Sep 2018, 12:10

Hi generalovaelena2010,

Thanks for posting in our forum. You cannot set price on market orders. Market orders are executed based on the current market price. If you want to trigger orders when a certain price lever is reached then you should check Limit Orders and Stop Orders.

Best Regards,

Panagiotis


@PanagiotisCharalampous

generalovaelena2010
20 Sep 2018, 14:45

Thanks for the answer! Can you tell  me  why it woks in this way? I wrote a robot and tried to trade. But I see that there are big slippage when opening and closing orders.


@generalovaelena2010

PanagiotisCharalampous
20 Sep 2018, 15:13

Hi generalovaelena2010,

This is how orders are executed in trading. You can read an introduction here.

Best Regards,

Panagiotis


@PanagiotisCharalampous

generalovaelena2010
20 Sep 2018, 15:31

Then why does Meta Trader 5 allow you to set the desired price for opening an order? This is very convenient when you can specify the desired price. If the actual price differs from the desired price more than slippage, then the order simply does not open. Why can not this be done in cTrader?


@generalovaelena2010

PanagiotisCharalampous
20 Sep 2018, 15:35

Hi generalovaelena2010,

You can do this using market range. However, instead of a price you can specify a number of pips that you accept the slippage to be. The price taken as reference is the Bid/Ask price at the moment of placing the order.

Best Regards,

Panagiotis


@PanagiotisCharalampous

generalovaelena2010
20 Sep 2018, 15:48

The problem is as follows. The condition for the opening of the Sell order is when the Bid price reaches the indicator line. Immediately thereafter, a request to open the order is sent. But in those fractions of a second that pass between checking the condition and sending the order, Bid's price has time to change. And slippage is considered from the price at the time of sending the request, and not from the price at the time the condition for the opening of the order is met. Between these prices there can be a big difference


@generalovaelena2010

PanagiotisCharalampous
20 Sep 2018, 16:04

Hi generalovaelena2010,

If you want exact price limit for your execution, why don't you use limit orders?

Best Regards,

Panagiotis


@PanagiotisCharalampous

generalovaelena2010
20 Sep 2018, 16:11

Yes, you can use a limit order. How to close the order at the right price?


@generalovaelena2010

PanagiotisCharalampous
20 Sep 2018, 16:14

Hi generalovaelena2010,

See below an example of placing a limit order at a price one pip ahead of the currect Ask price

PlaceLimitOrder(TradeType.Buy, Symbol, 1000, Symbol.Ask + Symbol.PipSize, "");

Best Regards,

Panagiotis


@PanagiotisCharalampous

generalovaelena2010
20 Sep 2018, 16:51

How to close a market order on exactly the price that I need?


@generalovaelena2010

PanagiotisCharalampous
20 Sep 2018, 16:57

Hi generalovaelena2010,

I guess you mean a position, not a market order. Orders are executed, positions are opened and closed. Positions cannot be closed at an exact price. They are always closed on market price. If there is enough liquidity, you will get the price you want, else there will be slippage. If you want to partially close positions only at the prices you want then you can consider a netting account and use limit orders of the opposite direction for partial closing.

Best Regards,

Panagiotis


@PanagiotisCharalampous