Modify Position Error
Modify Position Error
02 Feb 2017, 14:34
Hello,
I am having issues when trying to modify TP and SL after a market order has been filled. This is the code I am using. As you can see form the journal the algo keeps on requesting to modify the position... Also by looking at the journal the algo is modifying the same position PID58918377 over and over again.
Any help would be much appreciated.
private void OnPositionOpened(PositionOpenedEventArgs args)
{
var position = args.Position;
if (position.TradeType == TradeType.Buy)
{
var stopLoss = position.EntryPrice - Symbol.PipSize * sellSL;
var takeProfit = position.EntryPrice + Symbol.PipSize * TPBuy;
ModifyPosition(position, stopLoss, takeProfit);
Print("Position Modified:Entry: {0}, TP: {1}, SL: {2}", position.EntryPrice, position.StopLoss, position.TakeProfit);
}
else if (position.TradeType == TradeType.Sell)
{
var stopLoss = position.EntryPrice + Symbol.PipSize * buySL;
var takeProfit = position.EntryPrice - Symbol.PipSize * TPSell;
ModifyPosition(position, stopLoss, takeProfit);
Print("Position Modified:Entry: {0}, TP: {1}, SL: {2}", position.EntryPrice, position.StopLoss, position.TakeProfit);
}
}
and the journal
2017.02.01 21:55:00.037 | Limit order to Buy £ 109k GBPCAD (Price: 1.65152, SL: 1.64022, TP: 1.65292) is sent to server
2017.02.01 21:55:00.177 | Limit order to Sell NZD 335k NZDUSD (Price: 0.72793, SL: 0.73073, TP: 0.72753) is sent to server
2017.02.01 21:55:00.255 | Limit order to Sell € 96k EURGBP (Price: 0.85085, SL: 0.85865, TP: 0.84985) is sent to server
2017.02.01 21:55:00.365 | Request to close position PID58875227 is sent to server
2017.02.01 21:55:00.427 | Limit order to Buy £ 122k GBPAUD (Price: 1.66848, SL: 1.65828, TP: 1.66968) is sent to server
2017.02.01 21:55:00.599 | Limit order to Buy £ 76k GBPNZD (Price: 1.73876, SL: 1.72176, TP: 1.74076) is sent to server
2017.02.01 21:55:00.740 | → Limit order OID91768478 to Buy £ 109k GBPCAD (Price: 1.65152, SL: 1.64022, TP: 1.65292) is ACCEPTED (01/02/2017 21:55:00.166 UTC+0)
2017.02.01 21:55:00.771 | → Limit order OID91768479 to Sell NZD 335k NZDUSD (Price: 0.72793, SL: 0.73073, TP: 0.72753) is ACCEPTED (01/02/2017 21:55:00.274 UTC+0)
2017.02.01 21:55:00.818 | → Limit order OID91768480 to Sell € 96k EURGBP (Price: 0.85085, SL: 0.85865, TP: 0.84985) is ACCEPTED (01/02/2017 21:55:00.369 UTC+0)
2017.02.01 21:55:00.865 | → Request to close position PID58875227 is ACCEPTED, order OID91768481 created (01/02/2017 21:55:00.449 UTC+0)
2017.02.01 21:55:00.896 | → Limit order OID91768482 to Buy £ 122k GBPAUD (Price: 1.66848, SL: 1.65828, TP: 1.66968) is ACCEPTED (01/02/2017 21:55:00.521 UTC+0)
2017.02.01 21:55:01.115 | → Order OID91768481 is FILLED at 1.47941, position PID58875227 closed (01/02/2017 21:55:00.540 UTC+0)
2017.02.01 21:55:01.365 | Request to close position PID58875226 is sent to server
2017.02.01 21:55:01.505 | → Limit order OID91768483 to Buy £ 76k GBPNZD (Price: 1.73876, SL: 1.72176, TP: 1.74076) is ACCEPTED (01/02/2017 21:55:00.707 UTC+0)
2017.02.01 21:55:01.584 | → Request to close position PID58875226 is ACCEPTED, order OID91768486 created (01/02/2017 21:55:01.457 UTC+0)
2017.02.01 21:55:01.974 | → Order OID91768486 is FILLED at 1.07684, position PID58875226 closed (01/02/2017 21:55:01.514 UTC+0)
2017.02.01 21:56:23.585 | → Limit order to SELL NZD 335k NZDUSD OID91768479 is FILLED at 0.72795, position PID58918377 (01/02/2017 21:56:23.467 UTC+0)
2017.02.01 21:56:23.663 | Request to amend position PID58918377 (SL: 0.72981, TP: 0.72764) is sent to server
2017.02.01 21:56:23.741 | Request to amend position PID58918377 (SL: 0.73574, TP: 0.72698) is sent to server
2017.02.01 21:56:23.803 | Request to amend position PID58918377 (SL: 0.73311, TP: 0.72728) is sent to server
2017.02.01 21:56:23.881 | Request to amend position PID58918377 (SL: 1.27065, TP: 0.65765) is sent to server
2017.02.01 21:56:23.928 | Request to amend position PID58918377 (SL: 1.00155, TP: 0.68755) is sent to server
2017.02.01 21:56:24.006 | Request to amend position PID58918377 (SL: 0.73078, TP: 0.72754) is sent to server
2017.02.01 21:56:24.069 | Request to amend position PID58918377 (SL: 1.40205, TP: 0.64305) is sent to server
2017.02.01 21:56:24.147 | Request to amend position PID58918377 (SL: 0.73000, TP: 0.72762) is sent to server
2017.02.01 21:56:24.210 | Request to amend position PID58918377 (SL: 0.72898, TP: 0.72774) is sent to server
2017.02.01 21:56:24.272 | Request to amend position PID58918377 (SL: 0.73443, TP: 0.72713) is sent to server
2017.02.01 21:56:24.335 | Request to amend position PID58918377 (SL: 0.94215, TP: 0.69415) is sent to server
2017.02.01 21:56:24.397 | Request to amend position PID58918377 (SL: 1.07445, TP: 0.67945) is sent to server
2017.02.01 21:56:24.444 | Request to amend position PID58918377 (SL: 0.73392, TP: 0.72719) is sent to server
2017.02.01 21:56:24.506 | Request to amend position PID58918377 (SL: 0.73651, TP: 0.72690) is sent to server
2017.02.01 21:56:24.569 | Request to amend position PID58918377 (SL: 0.73035, TP: 0.72758) is sent to server
2017.02.01 21:56:24.631 | Request to amend position PID58918377 (SL: 0.73181, TP: 0.72742) is sent to server
2017.02.01 21:56:24.694 | Request to amend position PID58918377 (SL: 0.73072, TP: 0.72754) is sent to server
2017.02.01 21:56:24.756 | Request to amend position PID58918377 (SL: 0.73137, TP: 0.72747) is sent to server
2017.02.01 21:56:24.819 | Request to amend position PID58918377 (SL: 0.73486, TP: 0.72708) is sent to server
2017.02.01 21:56:24.881 | Request to amend position PID58918377 (SL: 1.48485, TP: 0.63385) is sent to server
2017.02.01 21:56:25.006 | → Request to amend position PID58918377 (SL: 0.72981, TP: 0.72764) is REJECTED with error ""
2017.02.01 21:56:25.022 | → Request to amend position PID58918377 (SL: 0.73574, TP: 0.72698) is REJECTED with error ""
2017.02.01 21:56:25.038 | → Request to amend position PID58918377 (SL: 0.73311, TP: 0.72728) is REJECTED with error ""
2017.02.01 21:56:25.069 | → Request to amend position PID58918377 (SL: 1.27065, TP: 0.65765) is REJECTED with error ""
2017.02.01 21:56:25.085 | → Request to amend position PID58918377 (SL: 1.00155, TP: 0.68755) is REJECTED with error ""
2017.02.01 21:56:25.100 | → Request to amend position PID58918377 (SL: 0.73078, TP: 0.72754) is REJECTED with error ""
2017.02.01 21:56:25.116 | → Request to amend position PID58918377 (SL: 1.40205, TP: 0.64305) is REJECTED with error ""
2017.02.01 21:56:25.131 | → Request to amend position PID58918377 (SL: 0.73000, TP: 0.72762) is REJECTED with error ""
2017.02.01 21:56:25.163 | → Request to amend position PID58918377 (SL: 0.72898, TP: 0.72774) is REJECTED with error ""
2017.02.01 21:56:25.163 | → Request to amend position PID58918377 (SL: 0.73443, TP: 0.72713) is REJECTED with error ""
2017.02.01 21:56:25.194 | → Request to amend position PID58918377 (SL: 0.94215, TP: 0.69415) is REJECTED with error ""
2017.02.01 21:56:25.210 | → Request to amend position PID58918377 (SL: 1.07445, TP: 0.67945) is REJECTED with error ""
2017.02.01 21:56:25.225 | → Request to amend position PID58918377 (SL: 0.73392, TP: 0.72719) is REJECTED with error ""
2017.02.01 21:56:25.241 | → Request to amend position PID58918377 (SL: 0.73651, TP: 0.72690) is REJECTED with error ""
2017.02.01 21:56:25.272 | → Request to amend position PID58918377 (SL: 0.73035, TP: 0.72758) is REJECTED with error ""
2017.02.01 21:56:25.288 | → Request to amend position PID58918377 (SL: 0.73181, TP: 0.72742) is REJECTED with error ""
2017.02.01 21:56:25.303 | → Request to amend position PID58918377 (SL: 0.73072, TP: 0.72754) is REJECTED with error ""
2017.02.01 21:56:25.319 | → Request to amend position PID58918377 (SL: 0.73137, TP: 0.72747) is REJECTED with error ""
2017.02.01 21:56:25.335 | → Request to amend position PID58918377 (SL: 0.73486, TP: 0.72708) is REJECTED with error ""