Questions from Beginners MQL5 MT5 MetaTrader 5 - page 82

 

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.

 
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.16 10:33:50     Core 1  2010.05.03 00:01:21   order performed sell 0.10 at 1.33260 [#3 sell 0.10 EURUSD at 1.33260]
2013.01.16 10:33:50     Core 1  2010.05.03 00:01:21   deal performed [#3 sell 0.10 EURUSD at 1.33260]
2013.01.16 10:33:50     Core 1  2010.05.03 00:01:21   deal #3 sell 0.10 EURUSD at 1.33260 done (based on order #3)
2013.01.16 10:33:50     Core 1  2010.05.03 00: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.16 10:33:50     Core 1  2010.05.03 00:00:02   Cant select order 2 error 4754
2013.01.16 10:33:50     Core 1  2010.05.03 00:00:00   position modified [buy 0.10 EURUSD 1.33310 sl: 1.33260 tp: 1.33360]
2013.01.16 10:33:50     Core 1  2010.05.03 00:00:00    === add order === 2
2013.01.16 10:33:50     Core 1  2010.05.03 00:00:00   order performed buy 0.10 at 1.33310 [#2 buy 0.10 EURUSD at 1.33310]
2013.01.16 10:33:50     Core 1  2010.05.03 00:00:00   deal performed [#2 buy 0.10 EURUSD at 1.33310]
2013.01.16 10:33:50     Core 1  2010.05.03 00:00:00   deal #2 buy 0.10 EURUSD at 1.33310 done (based on order #2)
2013.01.16 10:33:50     Core 1  2010.05.03 00: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: Тогда почему stopLoss не закрывает позицию?   Кроме того ее объем постоянно равен 0.10 лотам, да же после отыгрывания stop loss 

And how do you know that when the SL is triggered the position is not closed and its volume remains the same?
 
Yedelkin:
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);

2013.01.16 11:38:36     Core 1  disconnected
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:30   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:28   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:26   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:24   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:22   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:21   order performed sell 0.10 at 1.33260 [#3 sell 0.10 EURUSD at 1.33260]
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:21   deal performed [#3 sell 0.10 EURUSD at 1.33260]
2013.01.16 11:38:34     Core 1  2010.05.03 00:01:21   deal #3 sell 0.10 EURUSD at 1.33260 done (based on order #3)
2013.01.16 11:38:34     Core 1  2010.05.03 00: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.16 11:38:34     Core 1  2010.05.03 00:00:11   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:09   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:06   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:04   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:02   PositionGetDouble(POSITION_VOLUME) = 0.1
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:00   position modified [buy 0.10 EURUSD 1.33310 sl: 1.33260 tp: 1.33360]
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:00    === add order === 2
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:00   order performed buy 0.10 at 1.33310 [#2 buy 0.10 EURUSD at 1.33310]
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:00   deal performed [#2 buy 0.10 EURUSD at 1.33310]
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:00   deal #2 buy 0.10 EURUSD at 1.33310 done (based on order #2)
2013.01.16 11:38:34     Core 1  2010.05.03 00:00:00   exchange buy 0.10 EURUSD at 1.33310 (1.33290 / 1.33310 / 1.33290)
2013.01.16 11:38:34     Core 1    magic=12345
 
And do you update the position information, as prescribed in the Reference Manual, before using PositionGetDouble(POSITION_VOLUME) again?
 
Yedelkin:
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

PositionSelect(_Symbol); // судя по справке обновляет кеш
Print("PositionGetDouble(POSITION_VOLUME) = " + PositionGetDouble(POSITION_VOLUME));
 
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 :(
 

Try this:

if(PositionSelect(_Symbol)) 
   Print("myPositionGetDouble(POSITION_VOLUME) == " + PositionGetDouble(POSITION_VOLUME));
else 
   Print("Сведения о позиции не обнаружены");
 
Yedelkin:

Try it like this:

Thank you very much :)

2013.01.16 12:47:49     Core 1  disconnected
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:30   Сведения о позиции не обнаружены
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:28   Сведения о позиции не обнаружены
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:26   Сведения о позиции не обнаружены
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:24   Сведения о позиции не обнаружены
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:22   Сведения о позиции не обнаружены
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:21   order performed sell 0.10 at 1.33260 [#3 sell 0.10 EURUSD at 1.33260]
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:21   deal performed [#3 sell 0.10 EURUSD at 1.33260]
2013.01.16 12:47:45     Core 1  2010.05.03 00:01:21   deal #3 sell 0.10 EURUSD at 1.33260 done (based on order #3)
2013.01.16 12:47:45     Core 1  2010.05.03 00: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.16 12:47:45     Core 1  2010.05.03 00:00:11   myPositionGetDouble(POSITION_VOLUME) == 0.1
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:09   myPositionGetDouble(POSITION_VOLUME) == 0.1
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:06   myPositionGetDouble(POSITION_VOLUME) == 0.1
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:04   myPositionGetDouble(POSITION_VOLUME) == 0.1
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:02   myPositionGetDouble(POSITION_VOLUME) == 0.1
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:00   position modified [buy 0.10 EURUSD 1.33310 sl: 1.33260 tp: 1.33360]
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:00    === add order === 2
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:00   order performed buy 0.10 at 1.33310 [#2 buy 0.10 EURUSD at 1.33310]
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:00   deal performed [#2 buy 0.10 EURUSD at 1.33310]
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:00   deal #2 buy 0.10 EURUSD at 1.33310 done (based on order #2)
2013.01.16 12:47:45     Core 1  2010.05.03 00:00:00   exchange buy 0.10 EURUSD at 1.33310 (1.33290 / 1.33310 / 1.33290)
2013.01.16 12:47:45     Core 1    magic=12345