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

 
законопослушный гражданин #:

As far as I can see, the difference is this:

You can go through the story from the beginning or from the end. There is no difference. Anyway, the function searches for the order with the latest close time. And if you want to delete or close orders, we should search from the end of the list. Otherwise, the loop will skip orders.

 
законопослушный гражданин #:

as far as I can see, the difference is as follows:

In this case there is no difference. The cycle from OrersTotal to 0 is mandatory only in the case of closing positions or removing orders. In other cases it is up to your liking.

 
Mihail Matkovskij #:

You can go through the story from the beginning or from the end. There is no difference. Anyway, the function searches for the order with the latest closing time. And if you want to delete or close orders, then you need to search from the end of the list. Otherwise, the loop will skip orders.

If the function searches for the order with the latest close time, then the search will obviously be faster from the end - from the current time to the past, rather than from the beginning of the history.

 
Artyom Trishkin #:

If the function is looking for an order with the latest close time, the search will obviously be faster, not from the beginning of the history, but from the end - from the current time to the past time.

In the opposite direction, the function will find the order with the latest close time faster, it won't change it until the end of the cycle and will return the result. In the forward direction, it will search through all orders and return one of the last orders. The difference is that the variables will be overwritten on every pass of the loop. Yes, there is a difference. But I think it is not very significant. Although I would prefer the loop in the reverse direction to the forward one. Despite the fact that the function will work one way or another.

 
Hi all, is there any way to switch between chart windows programmatically, i.e. make any chart active from within the program?
 
Maksim Mihajlov #:
Hi all, is there any way to switch between chart windows programmatically, i.e. make any chart active from a program?

Check out

CHART_BRING_TO_TOP

Display chart on top of all other charts

bool

 
Alexey Viktorov #:

Check out

CHART_BRING_TO_TOP

Display chart on top of all other charts

bool

Thank you!

 
Mihail Matkovskij #:

You can go through the story from the beginning or from the end. There is no difference. Anyway, the function searches for the order with the latest closing time. And if you want to delete or close orders, then you need to search from the end of the list. Otherwise, the loop will skip orders.

Anyway, I made two completely identical EAs, except for order lot counting!!! and here is the result:

DOES NOT WORK (i.e. does not open BAY instead of SELL)

void OnTick()
{
// Получим значение индикатора
   dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.

// Если нет открытых ордеров, то входим в условие
      if(CountOrders()==0)
 {
//Если появился сигнал на покупку, то откроем ордер на покупку
  if(bSignalBuy())
  {
   if(GetLotSize()>LotControl) vOrderOpenSell();
   else vOrderOpenBuy();
  }
// Если появился сигнал на продажу, то откроем ордер на продажу
  if(bSignalSell())
  {
   if(GetLotSize()>LotControl) vOrderOpenBuy();
   else vOrderOpenSell();
  }
 }
}
,,,
double GetLotSize()
  {
   double Ls=0;
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL) {Ls=OrderLots();}
           }
        }
     }
   return Ls;
  }

WORKING ( (i.e. opens BAY instead of SELL)


void OnTick()
{
// Получим значение индикатора
   dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.

// Если нет открытых ордеров, то входим в условие
      if(CountOrders()==0)
 {
//Если появился сигнал на покупку, то откроем ордер на покупку
  if(bSignalBuy())
  {
   if(GetLotSize()>LotControl) vOrderOpenSell();
   else vOrderOpenBuy();
  }
// Если появился сигнал на продажу, то откроем ордер на продажу
  if(bSignalSell())
  {
   if(GetLotSize()>LotControl) vOrderOpenBuy();
   else vOrderOpenSell();
  }
 }
}
...
double GetLotSize()
  {
   double Ls=0;
   datetime t=0;
   int i=OrdersHistoryTotal();
   for(int pos=0; pos<i; pos++)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               if(t<OrderCloseTime()) {t=OrderCloseTime(); Ls=OrderLots();}
              }
           }
        }
     }
   return Ls;
  }
 
законопослушный гражданин #:

Anyway, I made two completely identical EAs, Except for order lot counting!!! and here's the result:

DOES NOT WORK (i.e. does not open BAY instead of SELL)

WORKING (i.e. opens BAY instead of SELL)


Once again I emphasize the difference

1 variant

double GetLotSize()
  {
   double Ls=0;
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_TRADES))

2 variant

double GetLotSize()
  {
   double Ls=0;
   datetime t=0;
   int i=OrdersHistoryTotal();
   for(int pos=0; pos<i; pos++)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
 
законопослушный гражданин #:

Anyway, I made two completely identical EAs, Except for order lot counting!!! and here's the result:

DOES NOT WORK (i.e. does not open BAY instead of SELL)

WORKING ( (i.e. opens BAY instead of SELL)


Try to understand what you are coding, rather than blindly copyingOrdersTotal,OrdersHistoryTotal,

OrderSelect

pool=MODE_TRADES

[in] Source of the data to select. Used when the select parameter is SELECT_BY_POS. Can be one of the following values:

MODE_TRADES (default) - order is selected among open and pending orders,
MODE_HISTORY - order is selected among closed and deleted orders.

    OrdersTotal - Торговые функции - Справочник MQL4
    OrdersTotal - Торговые функции - Справочник MQL4
    • docs.mql4.com
    OrdersTotal - Торговые функции - Справочник MQL4
    Reason: