Position.ModifyStopLossPips and ErrorCode.InvalidStopLossAndTakeProfit

Created at 06 Sep 2020, 10:46
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!
CT

ctid2033788

Joined 21.06.2020

Position.ModifyStopLossPips and ErrorCode.InvalidStopLossAndTakeProfit
06 Sep 2020, 10:46


1. When I call the Position.ModifyStopLossPips(stopLossPips), the stop loss for the Position should be updated to the value passed into the method but it is not?

Currently, If I pass in -2 for a buy position, the stop loss is set to 2 pips above Entry Price.

If I pass in 2 for a buy position, the stop loss is set to 2 pips below Entry Price.

This seems to be backwards.

 

Also

2. If I pass in 2 for a sell position, the call returns a TradeResult object that has a failure with the message InvalidStopLossAndTakeProfit.

What would be causing that?


@ctid2033788
Replies

firemyst
07 Sep 2020, 05:41

RE:

ctid2033788 said:

1. When I call the Position.ModifyStopLossPips(stopLossPips), the stop loss for the Position should be updated to the value passed into the method but it is not?

Currently, If I pass in -2 for a buy position, the stop loss is set to 2 pips above Entry Price.

If I pass in 2 for a buy position, the stop loss is set to 2 pips below Entry Price.

This seems to be backwards.

 

Also

2. If I pass in 2 for a sell position, the call returns a TradeResult object that has a failure with the message InvalidStopLossAndTakeProfit.

What would be causing that?

1) It might not be updated for any number of reasons. For example, what if the SL is moved to be within the symbol's spread? What if you're trying to move the SL by a very small or invalid amount?

-2 vs 2 might seem backwards, but that's how it works.

 

2) Again, where are you placing your SL in relation to the current bid/ask price? Or from it's last location? Have you noted what the old value was, what the old value is you want to move it to, and looked at the charts to see if it is valid? If you're in a sell, are you trying to move the SL below the bid price? If you're in a buy, are you trying to move the SL above the ask price?

You need to post code if you still can't figure it out.


@firemyst