Question on mql5 - how do I work with stopLoss and takeProfit triggers?
I send an order, modify it, it is executed and disappears. I am not able to change sl or tp afterwards because OrderSelect has no order found. Then a trigger is triggered and a new order is created which implements StopLoss / TakeProfit automatically.
Forux: Question on mql5 - How do I work with stopLoss and takeProfit triggers?
I send the order, modify it, it is executed and disappears. Then there is no opportunity to change sl, tp - OrderSelect will pop up with an error The order has not been found. Then a trigger is triggered and a new order is created which automatically executes a StopLoss / TakeProfit.
The ideology of mql5 is that after the order triggering, a position is opened (changed, closed) for the selected symbol. So after the order triggering (if it didn't result in closing the position), we should work with the position. For example, using PositionSelect(). And for changing of stopLoss and takeProfit levels, the position has its own variant of trade request.
Yedelkin: The mql5 ideology consists in opening (changing, closing) a position for the selected symbol after the order triggering. So after the order triggering (if it hasn't led to position closing) we should work with the position. For example, using PositionSelect(). And for changing of stopLoss and takeProfit levels, the position has its own variant of trade request.
Then why does stopLoss not close the position?
2013.01.1610:33:50 Core 12010.05.0300:01:21 order performed sell 0.10 at 1.33260 [#3 sell 0.10 EURUSD at 1.33260]2013.01.1610:33:50 Core 12010.05.0300:01:21 deal performed [#3 sell 0.10 EURUSD at 1.33260]2013.01.1610:33:50 Core 12010.05.0300:01:21 deal #3 sell 0.10 EURUSD at 1.33260 done (based on order #3)2013.01.1610:33:50 Core 12010.05.0300:01:21 stop loss triggered buy 0.10 EURUSD 1.33310 sl: 1.33260 tp: 1.33360 [#3 sell 0.10 EURUSD at 1.33260]2013.01.1610:33:50 Core 12010.05.0300:00:02 Cant select order 2 error 47542013.01.1610:33:50 Core 12010.05.0300:00:00 position modified [buy 0.10 EURUSD 1.33310 sl: 1.33260 tp: 1.33360]
2013.01.1610:33:50 Core 12010.05.0300:00:00 === add order === 22013.01.1610:33:50 Core 12010.05.0300:00:00 order performed buy 0.10 at 1.33310 [#2 buy 0.10 EURUSD at 1.33310]2013.01.1610:33:50 Core 12010.05.0300:00:00 deal performed [#2 buy 0.10 EURUSD at 1.33310]2013.01.1610:33:50 Core 12010.05.0300:00:00 deal #2 buy 0.10 EURUSD at 1.33310 done (based on order #2)2013.01.1610:33:50 Core 12010.05.0300:00:00 exchange buy 0.10 EURUSD at 1.33310 (1.33290 / 1.33310 / 1.33290)
Besides, its volume is always equal to 0.10 lots, even after astop loss is reached.
Forux: If I understood correctly what was meant then yes, doing the following:
Yes, that's what I was talking about. I.e. using such a construction for 10 seconds still returns a non-zero volume of the Sl-closed position? In that case, no idea about it yet :(
if(PositionSelect(_Symbol))
Print("myPositionGetDouble(POSITION_VOLUME) == " + PositionGetDouble(POSITION_VOLUME));
else
Print("Сведения о позиции не обнаружены");
2013.01.1612:47:49 Core 1 disconnected
2013.01.1612:47:45 Core 12010.05.0300:01:30 Сведения о позиции не обнаружены
2013.01.1612:47:45 Core 12010.05.0300:01:28 Сведения о позиции не обнаружены
2013.01.1612:47:45 Core 12010.05.0300:01:26 Сведения о позиции не обнаружены
2013.01.1612:47:45 Core 12010.05.0300:01:24 Сведения о позиции не обнаружены
2013.01.1612:47:45 Core 12010.05.0300:01:22 Сведения о позиции не обнаружены
2013.01.1612:47:45 Core 12010.05.0300:01:21 order performed sell 0.10 at 1.33260 [#3 sell 0.10 EURUSD at 1.33260]2013.01.1612:47:45 Core 12010.05.0300:01:21 deal performed [#3 sell 0.10 EURUSD at 1.33260]2013.01.1612:47:45 Core 12010.05.0300:01:21 deal #3 sell 0.10 EURUSD at 1.33260 done (based on order #3)2013.01.1612:47:45 Core 12010.05.0300:01:21 stop loss triggered buy 0.10 EURUSD 1.33310 sl: 1.33260 tp: 1.33360 [#3 sell 0.10 EURUSD at 1.33260]2013.01.1612:47:45 Core 12010.05.0300:00:11 myPositionGetDouble(POSITION_VOLUME) == 0.12013.01.1612:47:45 Core 12010.05.0300:00:09 myPositionGetDouble(POSITION_VOLUME) == 0.12013.01.1612:47:45 Core 12010.05.0300:00:06 myPositionGetDouble(POSITION_VOLUME) == 0.12013.01.1612:47:45 Core 12010.05.0300:00:04 myPositionGetDouble(POSITION_VOLUME) == 0.12013.01.1612:47:45 Core 12010.05.0300:00:02 myPositionGetDouble(POSITION_VOLUME) == 0.12013.01.1612:47:45 Core 12010.05.0300:00:00 position modified [buy 0.10 EURUSD 1.33310 sl: 1.33260 tp: 1.33360]
2013.01.1612:47:45 Core 12010.05.0300:00:00 === add order === 22013.01.1612:47:45 Core 12010.05.0300:00:00 order performed buy 0.10 at 1.33310 [#2 buy 0.10 EURUSD at 1.33310]2013.01.1612:47:45 Core 12010.05.0300:00:00 deal performed [#2 buy 0.10 EURUSD at 1.33310]2013.01.1612:47:45 Core 12010.05.0300:00:00 deal #2 buy 0.10 EURUSD at 1.33310 done (based on order #2)2013.01.1612:47:45 Core 12010.05.0300:00:00 exchange buy 0.10 EURUSD at 1.33310 (1.33290 / 1.33310 / 1.33290)
2013.01.1612:47:45 Core 1 magic=12345
Good afternoon,
Question on mql5 - how do I work with stopLoss and takeProfit triggers?
I send an order, modify it, it is executed and disappears. I am not able to change sl or tp afterwards because OrderSelect has no order found. Then a trigger is triggered and a new order is created which implements StopLoss / TakeProfit automatically.
I send the order, modify it, it is executed and disappears. Then there is no opportunity to change sl, tp - OrderSelect will pop up with an error The order has not been found. Then a trigger is triggered and a new order is created which automatically executes a StopLoss / TakeProfit.
The mql5 ideology consists in opening (changing, closing) a position for the selected symbol after the order triggering. So after the order triggering (if it hasn't led to position closing) we should work with the position. For example, using PositionSelect(). And for changing of stopLoss and takeProfit levels, the position has its own variant of trade request.
Then why does stopLoss not close the position?
Besides, its volume is always equal to 0.10 lots, even after astop loss is reached.
Forux: Тогда почему stopLoss не закрывает позицию? Кроме того ее объем постоянно равен 0.10 лотам, да же после отыгрывания stop loss
And how do you determine that the position is not closed after the SL is triggered and that its volume remains the same?
PositionGetDouble(POSITION_VOLUME);
And do you update the position information as prescribed in the Handbook before using PositionGetDouble(POSITION_VOLUME) again?
If I understood correctly what was meant then yes, doing the following
Try this:
if(PositionSelect(_Symbol)) Print("myPositionGetDouble(POSITION_VOLUME) == " + PositionGetDouble(POSITION_VOLUME)); else Print("Сведения о позиции не обнаружены");Try it like this:
Thank you very much :)