TakeProfitPrice

Created at 13 Jan 2014, 11:13
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!
NI

nirin

Joined 09.12.2013

TakeProfitPrice
13 Jan 2014, 11:13


Hi guys,

I have a robot which contains a takeprofit like this below, it worked with the old API but with the new one it does nothing:

        protected override void OnPositionOpened(Position openedPosition)
        {
            double? TakeProfitPrice = null;

            if (Positions.Count == 1)
            {
                position = openedPosition;

                if (position.TradeType == TradeType.Buy)

                    TakeProfitPrice = position.EntryPrice + TakeProfit * Symbol.TickSize;


                if (position.TradeType == TradeType.Sell)

                    TakeProfitPrice = position.EntryPrice - TakeProfit * Symbol.TickSize;

Thanks a lot for your help!


@nirin
Replies

Spotware
13 Jan 2014, 14:39

Using the methods of the new API will require different syntax altogether. 
Please see the examples here: /forum/whats-new/1937 
Also, you can download the Trading API Guide.

One way of implementing the above would be:

        protected override void OnStart()
        {
            ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 10000, "My Label", OnExecuted);
        }

        private void OnExecuted(TradeResult result)
        {
            double TakeProfitPrice;

            if (result.IsSuccessful && Positions.Count == 1)
            {
                var position = result.Position;

                if (position.TradeType == TradeType.Buy)
                    TakeProfitPrice = position.EntryPrice + TakeProfit * Symbol.TickSize;


                if (position.TradeType == TradeType.Sell)
                    TakeProfitPrice = position.EntryPrice - TakeProfit * Symbol.TickSize;

                //...

            }
            else
            {
                Print("Failed to create position");
            }
            //...

        }

 


@Spotware