Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 517

 
Alexey Viktorov:

And then you continue to use the same wording.


))) Two objects, one older and one younger, I need the point price of the younger (closer) object and I get the point price of the older (farther) object in the comment. Why? If previous, commented out loop returned the furthest object, current loop must return the closest - last but returns the penultimate. I am missing something here.
 
PolarSeaman:
))) Two objects, one older and one younger, I need the point price of the younger (closer) object and I get the point price of the older (farther) object in the comment. Why? If previous, commented out loop returned the furthest object, current loop must return the closest - last but returns the penultimate. I am missing something here.

One, and two - to select objects in the loop by time, you need to compare two times - the previous object and the current one. If the current time is longer, then store it in a variable to be checked at the next iteration of the loop. At the end of the loop, the variable will contain the most recent object created.

 
YanSay:

Tried it, it doesn't work, I must be doing something wrong(

The roughest error here is specifying value 100 instead of ticket in OrderDelete() function argument.

The next error is not so rough, but it is related to the fact that the calculated value of Stop Loss is checked instead of its actual value.

The order type is also not checked. What if we have chosen a market order? How to delete it? The order symbol has not been checked.

Taking into consideration these errors, we get the code of deleting the pending order when the price reaches its Stop Loss:

for (int i = OrdersTotal() - 1; i >= 0; --i)
{
   if (!OrderSelect(i, SELECT_BY_POS))
      continue;

   if (OrderSymbol() != Symbol())
      continue;

   if (OrderMagicNumber() != 100)
      continue;

   if (((OrderType == OP_BUYSTOP || OrderType() == OP_BUYLIMIT) && Bid <= OrderStopLoss()) ||
       ((OrderType == OP_SELLSTOP || OrderType() == OP_SELLLIMIT) && Ask >= OrderStopLoss() && OrderStopLoss() > 0.0))
   {
      if (OrderDelete(OrderTicket()))
         RefreshRates();
   }
                                        
}   
Also in your code, the Stop Loss is checked immediately after opening an order. It seems that after opening a pending order, this code is no longer executed. That is, you need to separate the execution branches. One is responsible for setting the order, and the second is responsible for its accompaniment.
Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 

Hello ladies and gentlemen !

Please tell me how to catch the combination of keys, e.g. Ctrl+1. I know how to catch one key on the keyboard.

But I need a combination in mt4 - how to do it !

 
Игорь:

Hello ladies and gentlemen !

Can you tell me how to catch the combination of keys such as Ctrl+1. I know how to catch one key on the keyboard.

I need a combination of Mt4 - how to do this !

The event OnChartEvent, analyze parameters lparam and sparam, because pressing Ctrl+1 is two events.

 
Ihor Herasko:

OnChartEvent event, analyse lparam and sparam parameters, as pressing Ctrl+1 is two events.

Nah it doesn't work i tried it !!!

It only displays the ctrl press and all other plus 1's and letters don't work !!!

 
Игорь:

Nah it doesn't work I tried it !!!

It only displays kntrl press and all the other plus 1's and letters don't work !!!

I wrote:

pressing Ctrl+1 is two events

Catch two events and analyse:

2018.04.05 12:26:32.170 Test EURUSD,M15: OnChartEvent, id: CHARTEVENT_KEYDOWN, lparam: 17, dparam: 1.0, sparam: 285
2018.04.05 12:26:32.396 Test EURUSD,M15: OnChartEvent, id: CHARTEVENT_KEYDOWN, lparam: 49, dparam: 1.0, sparam: 2

This is a Ctrl+1 press.

 
Ihor Herasko:

I wrote:

Catch two events and analyse:

This is a Ctrl+1 press.

Here I have only countercl or 1 and no event on the other or show your code !

After pressing ctrl no other events until you release ctrl !

I found the error, thanks !

 
Deleted the duplicates.
 
Vitaly Muzichenko:

With a profile? =)

:)

Reason: