Modify Stop loss price and Modify Take profit price

Created at 07 Apr 2020, 22: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!
WI

WienAT

Joined 07.04.2020

Modify Stop loss price and Modify Take profit price
07 Apr 2020, 22:37


Dear all,

I am testing one bot and there is one thing that is not really clear to me:

I open position with following command: 

ExecuteMarketOrder(TradeType.Buy, position.SymbolName, volume, "Buy");

Since there is no option that I execute trade with already setted SL price and TP price (i do not want to set number of pips for TP and SL) I am doing following:

                            Positions[Positions.Count - 1].ModifyStopLossPrice(entrypositionprice);
                            Positions[Positions.Count - 1].ModifyTakeProfitPrice(takeprofitprice);

In this case both SL price and TP price are correctly moved. I see also in debugger Visual Studio:

But if I check my console in Ctrader i see following:

What could be wrong?

 

Regards


@WienAT
Replies

firemyst
04 Sep 2020, 09:07 ( Updated at: 21 Dec 2023, 09:22 )

RE:

WienAT said:

Dear all,

I am testing one bot and there is one thing that is not really clear to me:

I open position with following command: 

ExecuteMarketOrder(TradeType.Buy, position.SymbolName, volume, "Buy");

Since there is no option that I execute trade with already setted SL price and TP price (i do not want to set number of pips for TP and SL) I am doing following:

                            Positions[Positions.Count - 1].ModifyStopLossPrice(entrypositionprice);
                            Positions[Positions.Count - 1].ModifyTakeProfitPrice(takeprofitprice);

In this case both SL price and TP price are correctly moved. I see also in debugger Visual Studio:

But if I check my console in Ctrader i see following:

What could be wrong?

 

Regards

What could be wrong if you could have multiple positions open, which I can see from your bottom screen capture you do.

How do you know what position is in "Positions[Positions.Count - 1]"?

When you increase a position size, or open a new position, the position of your "Buy" position could change in the Positions object.

So you need to check the name of the position at "Positions[Positions.Count - 1]" or you need to search the Positions object for your specific label "Buy".

Example:

Position myPosition = Positions.Find("Buy", Symbol.Name);

 

 


@firemyst