Обсуждение статьи "Переход с MQL4 на MQL5" - страница 7

 
Sergey Pavlov:

Да он был создан одновременно со статьёй. Только смысла в нём, без торговых функций, нет! 

Сделал (выложил в кодобазу) MQL4-торговые функции, работающие одновременно и с MQL5-торговыми функциями.

Поэтому смысл в эмуляторе еще может быть.

 
fxsaber:

Сделал (выложил в кодобазу) MQL4-торговые функции, работающие одновременно и с MQL5-торговыми функциями.

Поэтому смысл в эмуляторе еще может быть.

https://www.mql5.com/ru/code/16006
MT4Orders
MT4Orders
  • 2016.08.05
  • fxsaber
  • www.mql5.com
Параллельное использование ордерных систем MetaTrader 4 и MetaTrader 5.
 

Еще на тему. 

MQL's OOP notes: Converting MetaTrader 4 indicators to MetaTrader 5
MQL's OOP notes: Converting MetaTrader 4 indicators to MetaTrader 5
  • 2016.09.28
  • //www.mql5.com/en/users/marketeer">
  • www.mql5.com
It has been a long time since MetaTrader 5 was released, but MQL products for MetaTrader 4 do still prevail on mql5.com site (both in the codebase, and in the market), and in the Internet in general....
 
buh400:
Все я понял что этот вопрос уже поднимали, и надо прочитать другую статью:) Мои сообщения можно удалить

 Расскажите мне, пожалуйста, что Вы поняли, какую статью читать и как исправить вышеописанную ошибку?

Я вот понимаю, что это для добавления индикатора пользователем - поэтому закомментировал...
 

я так понимаю все 

MQLInfoInteger(MQL5_....


 надо заменить на 

MQLInfoInteger(MQL_


 

 

iBarShift не рабочая.

Мое исполнение - не совсем уверен, но работает корректно и вроде все логично

int iBarShift(string symbol,int tf,datetime time,bool exact=false)
  {
   if(time<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[],time1;
   CopyTime(symbol,timeframe,0,1,Arr);
   time1=Arr[0];
   if(time1<time){
      return(0); /// Если данное нам время меньше времени открытия бара
   }
   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)
     {
      return(ArraySize(Arr));
     }
   else return(-1);
  }
 

Не могу понять, как использовать функцию

bool ObjectSetMQL4(string name,
                   int index,
                   double value)
  {
   switch(index)
     {
      case OBJPROP_TIME1:
         ObjectSetInteger(0,name,OBJPROP_TIME,(int)value);return(true);
      case OBJPROP_PRICE1:
         ObjectSetDouble(0,name,OBJPROP_PRICE,value);return(true);
      case OBJPROP_TIME2:
         ObjectSetInteger(0,name,OBJPROP_TIME,1,(int)value);return(true);
      case OBJPROP_PRICE2:
         ObjectSetDouble(0,name,OBJPROP_PRICE,1,value);return(true);
      case OBJPROP_TIME3:
         ObjectSetInteger(0,name,OBJPROP_TIME,2,(int)value);return(true);
      case OBJPROP_PRICE3:
         ObjectSetDouble(0,name,OBJPROP_PRICE,2,value);return(true);
      case OBJPROP_COLOR:
         ObjectSetInteger(0,name,OBJPROP_COLOR,(int)value);return(true);
      case OBJPROP_STYLE:
         ObjectSetInteger(0,name,OBJPROP_STYLE,(int)value);return(true);
      case OBJPROP_WIDTH:
         ObjectSetInteger(0,name,OBJPROP_WIDTH,(int)value);return(true);
      case OBJPROP_BACK:
         ObjectSetInteger(0,name,OBJPROP_BACK,(int)value);return(true);
      case OBJPROP_RAY:
         ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,(int)value);return(true);
      case OBJPROP_ELLIPSE:
         ObjectSetInteger(0,name,OBJPROP_ELLIPSE,(int)value);return(true);
      case OBJPROP_SCALE:
         ObjectSetDouble(0,name,OBJPROP_SCALE,value);return(true);
      case OBJPROP_ANGLE:
         ObjectSetDouble(0,name,OBJPROP_ANGLE,value);return(true);
      case OBJPROP_ARROWCODE:
         ObjectSetInteger(0,name,OBJPROP_ARROWCODE,(int)value);return(true);
      case OBJPROP_TIMEFRAMES:
         ObjectSetInteger(0,name,OBJPROP_TIMEFRAMES,(int)value);return(true);
      case OBJPROP_DEVIATION:
         ObjectSetDouble(0,name,OBJPROP_DEVIATION,value);return(true);
      case OBJPROP_FONTSIZE:
         ObjectSetInteger(0,name,OBJPROP_FONTSIZE,(int)value);return(true);
      case OBJPROP_CORNER:
         ObjectSetInteger(0,name,OBJPROP_CORNER,(int)value);return(true);
      case OBJPROP_XDISTANCE:
         ObjectSetInteger(0,name,OBJPROP_XDISTANCE,(int)value);return(true);
      case OBJPROP_YDISTANCE:
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,(int)value);return(true);
      case OBJPROP_FIBOLEVELS:
         ObjectSetInteger(0,name,OBJPROP_LEVELS,(int)value);return(true);
      case OBJPROP_LEVELCOLOR:
         ObjectSetInteger(0,name,OBJPROP_LEVELCOLOR,(int)value);return(true);
      case OBJPROP_LEVELSTYLE:
         ObjectSetInteger(0,name,OBJPROP_LEVELSTYLE,(int)value);return(true);
      case OBJPROP_LEVELWIDTH:
         ObjectSetInteger(0,name,OBJPROP_LEVELWIDTH,(int)value);return(true);

      default: return(false);
     }
   return(false);
  }

Компилятор ругается

'OBJPROP_TIME1' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2891 12
'OBJPROP_TIME1' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2891 12
'OBJPROP_PRICE1' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2893 12
'OBJPROP_PRICE1' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2893 12
'OBJPROP_TIME2' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2895 12
'OBJPROP_TIME2' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2895 12
'OBJPROP_PRICE2' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2897 12
'OBJPROP_PRICE2' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2897 12
'OBJPROP_TIME3' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2899 12
'OBJPROP_TIME3' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2899 12
'OBJPROP_PRICE3' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2901 12
'OBJPROP_PRICE3' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2901 12

 
-Aleks-:

Не могу понять, как использовать функцию

Компилятор ругается

'OBJPROP_TIME1' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2891 12
'OBJPROP_TIME1' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2891 12
'OBJPROP_PRICE1' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2893 12
'OBJPROP_PRICE1' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2893 12
'OBJPROP_TIME2' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2895 12
'OBJPROP_TIME2' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2895 12
'OBJPROP_PRICE2' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2897 12
'OBJPROP_PRICE2' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2897 12
'OBJPROP_TIME3' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2899 12
'OBJPROP_TIME3' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2899 12
'OBJPROP_PRICE3' - undeclared identifier TZ_Sky_and_Ground_V_04.mq5 2901 12
'OBJPROP_PRICE3' - constant expression required TZ_Sky_and_Ground_V_04.mq5 2901 12

Смените в строках где ругается на такие конструкции ObjectSetInteger(...) на ObjectSetMQL4(...)

А вообще, проще переписать, там менять очень быстро, буквально 2 минуты времени

 
Vitaly Muzichenko:

Смените в строках где ругается на такие конструкции ObjectSetInteger(...) на ObjectSetMQL4(...)

А вообще, проще переписать, там менять очень быстро, буквально 2 минуты времени

 

Не понял или не получается.

Вот  у меня была такая функция


//+------------------------------------------------------------------+
//|Функция вывода информации на экран                                |
//+------------------------------------------------------------------+
void Label(string _name,int _window,int _x,int _y,string _text,int _font,color _color,int corner)
  {
   ObjectDelete(0,_name);
   ObjectCreate(0,_name,OBJ_LABEL,_window,0,0);
   ObjectSet(_name,OBJPROP_CORNER,corner);
   ObjectSet(_name,OBJPROP_XDISTANCE,_x);
   ObjectSet(_name,OBJPROP_YDISTANCE,_y);
   ObjectSetText(_name,_text,_font,"Arial",_color);
  }

для того что б она работала в MQL5 я добавил из статьи


  bool ObjectSetText(string name, string text, int font_size,string font="", color text_color=CLR_NONE)
  {
   int tmpObjType=(int)ObjectGetInteger(0,name,OBJPROP_TYPE);
   if(tmpObjType!=OBJ_LABEL && tmpObjType!=OBJ_TEXT) return(false);
   if(StringLen(text)>0 && font_size>0)
     {
      if(ObjectSetString(0,name,OBJPROP_TEXT,text)==true
         && ObjectSetInteger(0,name,OBJPROP_FONTSIZE,font_size)==true)
        {
         if((StringLen(font)>0)
            && ObjectSetString(0,name,OBJPROP_FONT,font)==false)
            return(false);
         if(text_color>-1
            && ObjectSetInteger(0,name,OBJPROP_COLOR,text_color)==false)
            return(false);
         return(true);
        }
      return(false);
     }
   return(false);
  }
  
bool ObjectSet(string name, int index, double value)
  {
   switch(index)
     {
      case OBJPROP_TIME1:
         ObjectSetInteger(0,name,OBJPROP_TIME,(int)value);return(true);
      case OBJPROP_PRICE1:
         ObjectSetDouble(0,name,OBJPROP_PRICE,value);return(true);
      case OBJPROP_TIME2:
         ObjectSetInteger(0,name,OBJPROP_TIME,1,(int)value);return(true);
      case OBJPROP_PRICE2:
         ObjectSetDouble(0,name,OBJPROP_PRICE,1,value);return(true);
      case OBJPROP_TIME3:
         ObjectSetInteger(0,name,OBJPROP_TIME,2,(int)value);return(true);
      case OBJPROP_PRICE3:
         ObjectSetDouble(0,name,OBJPROP_PRICE,2,value);return(true);
      case OBJPROP_COLOR:
         ObjectSetInteger(0,name,OBJPROP_COLOR,(int)value);return(true);
      case OBJPROP_STYLE:
         ObjectSetInteger(0,name,OBJPROP_STYLE,(int)value);return(true);
      case OBJPROP_WIDTH:
         ObjectSetInteger(0,name,OBJPROP_WIDTH,(int)value);return(true);
      case OBJPROP_BACK:
         ObjectSetInteger(0,name,OBJPROP_BACK,(int)value);return(true);
      case OBJPROP_RAY:
         ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,(int)value);return(true);
      case OBJPROP_ELLIPSE:
         ObjectSetInteger(0,name,OBJPROP_ELLIPSE,(int)value);return(true);
      case OBJPROP_SCALE:
         ObjectSetDouble(0,name,OBJPROP_SCALE,value);return(true);
      case OBJPROP_ANGLE:
         ObjectSetDouble(0,name,OBJPROP_ANGLE,value);return(true);
      case OBJPROP_ARROWCODE:
         ObjectSetInteger(0,name,OBJPROP_ARROWCODE,(int)value);return(true);
      case OBJPROP_TIMEFRAMES:
         ObjectSetInteger(0,name,OBJPROP_TIMEFRAMES,(int)value);return(true);
      case OBJPROP_DEVIATION:
         ObjectSetDouble(0,name,OBJPROP_DEVIATION,value);return(true);
      case OBJPROP_FONTSIZE:
         ObjectSetInteger(0,name,OBJPROP_FONTSIZE,(int)value);return(true);
      case OBJPROP_CORNER:
         ObjectSetInteger(0,name,OBJPROP_CORNER,(int)value);return(true);
      case OBJPROP_XDISTANCE:
         ObjectSetInteger(0,name,OBJPROP_XDISTANCE,(int)value);return(true);
      case OBJPROP_YDISTANCE:
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,(int)value);return(true);
      case OBJPROP_FIBOLEVELS:
         ObjectSetInteger(0,name,OBJPROP_LEVELS,(int)value);return(true);
      case OBJPROP_LEVELCOLOR:
         ObjectSetInteger(0,name,OBJPROP_LEVELCOLOR,(int)value);return(true);
      case OBJPROP_LEVELSTYLE:
         ObjectSetInteger(0,name,OBJPROP_LEVELSTYLE,(int)value);return(true);
      case OBJPROP_LEVELWIDTH:
         ObjectSetInteger(0,name,OBJPROP_LEVELWIDTH,(int)value);return(true);

      default: return(false);
     }
   return(false);
  }
И получил выше описанные ощибки.
 
-Aleks-:

 

Не понял или не получается.

Вот  у меня была такая функция


для того что б она работала в MQL5 я добавил из статьи


И получил выше описанные ощибки.

Вот такие конструкции нужно было смыть в унитаз ещё в 2013 году

   ObjectSet(_name,OBJPROP_CORNER,corner);
   ObjectSet(_name,OBJPROP_XDISTANCE,_x);
   ObjectSet(_name,OBJPROP_YDISTANCE,_y);
   ObjectSetText(_name,_text,_font,"Arial",_color);


Используйте:

ObjectSetDouble(...)
ObjectSetInteger(...)