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

 
Iurii Tokman:

code needs to be inserted Alt+S
and where is the function ?
how did you compile it ? no errors ?

His code has work with pending orders and the function works with positions - needs a little tweaking

 
Vitaly Muzichenko:

His code works with pending orders, while the function works with positions - we need to make some adjustments

Exactly right, only limit orders sellstop and buystop are handled. What do you need to correct?

 
sibiriyak73:

Absolutely correct, only sellstop and buystop limit orders are being worked on. What needs to be fixed?

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает флаг торгов сегодня.                                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isTradeToDay(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (TimeDay  (OrderOpenTime())==Day()
              &&  TimeMonth(OrderOpenTime())==Month()
              &&  TimeYear (OrderOpenTime())==Year()) return(True);
            }
          }
        }
      }
    }
  }
  k=OrdersTotal();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()<=6) { 
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (TimeDay  (OrderOpenTime())==Day()
              &&  TimeMonth(OrderOpenTime())==Month()
              &&  TimeYear (OrderOpenTime())==Year()) return(True);
            }
          }
        }
      }
    }
  }
  return(False);
}
 
Vitaly Muzichenko:

Is this function for buy side or for both buy and sell?

Should I keep the 6 order types highlighted in yellow?

It compiled without errors, but it does not open orders

 
sibiriyak73:

Is this function for buy side or for both buy and sell?

Should I keep the 6 order types highlighted in yellow?

It compiles correctly but does not open orders

This is for all types. It should work if you use it correctly


P.S. Try to logically analyse why it might not work and what is preventing it from doing so.

 

And it's probably better to insert the function once, it doesn't matter what type is or has been in the market anyway

if(Hour()==Nac && !isTradeToDay(Symbol()))
 {
   if(iOpen(NULL,PERIOD_D1,0)<iOpen(NULL,PERIOD_D1,1))
   {
     int ticket1=OrderSend(Symbol(),OP_SELLSTOP,1.5,limit1,3,SL1,TP1,NULL,0,0,clrRed); //Здесь открываем
   }

   if(iOpen(NULL,PERIOD_D1,0)>iOpen(NULL,PERIOD_D1,1))
   {
     int ticket=OrderSend(Symbol(),OP_BUYSTOP,1.5,limit,3,SL,TP,NULL,0,0,clrBlueViolet); //Здесь открываем
   }
 }
 
Happy New Year Bulls to everybody! Bullish growth to all!)

Can you tell me how to calculate the point value of the previous day (or hour) between the lowest and highest price.
 
Порт-моне тв:
Happy New Year Bulls to everybody! Bullish growth to all!)

Can you tell me how to calculate the point value of the previous day (or hour) between the lowest and highest price.
( High[1] - Low[1] ) / Point()
 
Hello all!

Can you tell me what this code means or more precisely how it works in principle? In this case the macro substitution is used, and it is the main condition to open orders. PS. The global variable is not modified anywhere.

#define  MARKET_WATCH          (0)

bool  Gl_Var_MarketWatch    =  MARKET_WATCH;  // глобальная переменная

if(Gl_Var_MarketWatch) ticket=OrderSend(symbol_name,op,ll,pp,MaxSlippage,0,0,co,mn,0,clOpen);
      else ticket=OrderSend(symbol_name,op,ll,pp,MaxSlippage,sl,tp,co,mn,0,clOpen);
Макроподстановка (#define) - Препроцессор - Основы языка - Справочник MQL4
Макроподстановка (#define) - Препроцессор - Основы языка - Справочник MQL4
  • docs.mql4.com
Директива #define подставляет expression вместо всех последующих найденных вхождений identifier в исходном тексте. identifier заменяется только в том случае, если он представляет собой отдельный токен. identifier не заменяется, если он является частью комментария, частью строки, или частью другого более длинного идентификатора. expression может...
 
Tom Seljakin:
Hello all!

Can you tell me what this code means or more precisely how it works in principle? In this case the macro substitution is used, and it is the main condition to open orders. PS. The global variable is not modified anywhere.

maybe it's

MARKET_WATCH,                               // окна "Обзор рынка"
Reason: