Errors, bugs, questions - page 2133

 
Error in CCanvas::Attach. Missing highlighted line
//+------------------------------------------------------------------+
//| Attach new object without bitmap resource                        |
//+------------------------------------------------------------------+
bool CCanvas::Attach(const long chart_id,const string objname,const int width,const int height,ENUM_COLOR_FORMAT clrfmt=COLOR_FORMAT_XRGB_NOALPHA)
  {
   if(OBJ_BITMAP_LABEL==ObjectGetInteger(chart_id,objname,OBJPROP_TYPE))
     {
      string rcname=ObjectGetString(chart_id,objname,OBJPROP_BMPFILE);
      if(StringLen(rcname)==0 && width>0 && height>0 && ArrayResize(m_pixels,width*height)>0)
        {
         ZeroMemory(m_pixels);
         if(ResourceCreate("::"+objname,m_pixels,width,height,0,0,0,clrfmt) && 
            ObjectSetString(chart_id,objname,OBJPROP_BMPFILE,"::"+objname))
           {
            m_chart_id = chart_id;
            m_width=width;
            m_height=height;
            m_objname=objname;
            m_rcname="::"+objname;
            m_format=clrfmt;
            m_objtype=OBJ_BITMAP_LABEL;
            //--- success
            return(true);
           }
        }
     }
//--- failed
   return(false);
  }
 
Oh, I should ask Nikolay Semko to write an alternative version of the kanvas, with good anti-aliasing, maybe a different vision, and write an article, maybe he'll do it?
 
Aleksandr Teleguz:

Hello. Please help me find the cause of this error. I am trying to convert an indicator from mql4 to mql5. I am using the following "shell" for iHigh functions:

As a result, I get the error 4301: "Unknown symbol", even though a string returned by the Symbol() function is passed as the symbol parameter. Here is a code fragment of the function calling iHigh

Who is "i"? What is its value before the loop?


Are you doing ResetLastError call beforeiHigh?

 
Vladimir Karputov:

Who is the "i"? What is its value before the loop?


Do you make a ResetLastError call beforeiHigh?

The value of i is looped through in the OnCalculate function

for(int i=rates_total-prev_calculated; i>0 && !IsStopped(); i--)
     {
      if(i>rates_total-10) continue;


I didn't make ResetLastError call, now I did - error code is the same. I use arrays low[i], high[i] etc. in OnCalculate function, and iHigh, iLow etc. in external functions.

 
Aleksandr Teleguz:

The value of i is looped in the OnCalculate function


I didn't call ResetLastError, now I did - the error code is the same. I use arrays low[i], high[i] etc. in OnCalculate function and iHigh, iLow etc. in external functions.

Provide the MQL5 code that can be run and describe the conditions under which the error occurs.

 
Vladimir Karputov:

Provide MQL5 code that can be run and describe the conditions under which the error occurs.

Seems to be something wrong with my terminal. Ran the same code on netbook on another mt5, same demo account - no error.

Here is the code itself:

/+------------------------------------------------------------------+
//|                                                      Strelka.mq4 |
//|                                                Alexander Teleguz |
//|                                            https://investmany.ru |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 12
#property indicator_plots   6

#define OP_SELL 1

int OnInit()
{
  
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   
}
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   ArraySetAsSeries(time,true);
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   
   for(int i = rates_total-prev_calculated; i>0 && !IsStopped(); i--)
   {
      if(i>rates_total-10) continue;
      bool filtr = Filtr1(OP_SELL, i);
   }
      
   return(rates_total);
}
//+------------------------------------------------------------------+
bool Filtr1(int type, int i)
{
   ENUM_TIMEFRAMES tf = Period();
   string symbol = Symbol();
   int i1, i2=0; //индекс внешнего бара, счетчик
   for(i1=i+1; i2<6; i1++)
   {
      if(iLow(symbol, tf, i1)<=iLow(symbol, tf, i1+1)&&
         iHigh(symbol, tf, i1)>=iHigh(symbol, tf, i1+1)) //если бар внешний
      {
         break; //выход из цикла
      }
      else
      {
         i2++;
      }
   }
   return(false);
}
//+------------------------------------------------------------------+
double iHigh(string symbol, ENUM_TIMEFRAMES tf,int index)
{
   if(index < 0) return(-1);
   double Arr[1];
   if(CopyHigh(symbol,tf, index, 1, Arr)>0) 
        return(Arr[0]);
   else
   {
      Print(__FUNCTION__, GetLastError());
      return(-1);
   } 
}
//+------------------------------------------------------------------+
double iLow(string symbol, ENUM_TIMEFRAMES tf,int index)
{
   if(index < 0) return(-1);
   double Arr[1];
   if(CopyLow(symbol,tf, index, 1, Arr)>0) 
        return(Arr[0]);
   else
   {
      Print(__FUNCTION__, GetLastError());
      return(-1);
   }
}
//+------------------------------------------------------------------+
 
Aleksandr Teleguz:

I seem to have something wrong with my terminal. Ran the same code on netbook on another mt5, same demo account - no error.

Here is the code itself:

Note: You are writing in the main MQL5 forum section, this is where MQL5 is discussed. For MQL4 there is a special section:MQL4 and MetaTrader 4. Please publish your code in the appropriate section. It is even better when the publisher respects the users and immediately publishes the code in the header where the type of language can be seen.

 
This is MQL5.
 

Hello!
I can't change the timeframe of a graphical object - I can't tell if the terminal is screwing up or if it's me.
Here is the check code

int OnStart(void)
{
        double price;
        datetime time0, time1;
        string obj_name= "test_of_line_timeframe_setting";
        ENUM_TIMEFRAMES tf1, tf2;

        // берем последнюю цену и время 
        MqlRates rates[];
        int copied=CopyRates(NULL,0,0,3,rates);
        price= rates[0].open;
        time0= rates[0].time;
        
        // рисуем линию
        ObjectCreate(0, obj_name, OBJ_HLINE, 0, time0, price);
// --- отображение на переднем плане (false) или background (true)
    ObjectSetInteger (0, obj_name, OBJPROP_BACK , false);
// --- Включить (true) или отключить (false) режим для перемещения меток с помощью мыши
    ObjectSetInteger (0, obj_name, OBJPROP_SELECTABLE , true);
    ObjectSetInteger (0, obj_name, OBJPROP_SELECTED , false);
// --- Скрыть (true) или отобразить (false) графический объект в списке объектов
    ObjectSetInteger (0, obj_name, OBJPROP_HIDDEN , false);
// --- Установите порядок приоритета для получения события щелчка мыши по диаграмме
    ObjectSetInteger (0, obj_name, OBJPROP_ZORDER , 0);

        
        // устанавливаем видимость на дневном таймфрэйме
        ObjectSetInteger(0,obj_name,OBJPROP_PERIOD,PERIOD_D1); 
        // считываем видимость 
        tf1= ObjectGetInteger(0,obj_name,OBJPROP_PERIOD);

        // устанавливаем видимость на часовом таймфрэйме
        ObjectSetInteger(0,obj_name,OBJPROP_PERIOD,PERIOD_H1); 
        // считываем видимость 
        tf2= ObjectGetInteger(0,obj_name,OBJPROP_PERIOD);

        if (tf1==tf2) Alert("таймфрейм изменить не удается");
        else Alert("таймфрейм успешно изменен");

        ObjectDelete(0,obj_name); 

        return(0);
}
 
OBJ_CHART bug. Indicator
#property indicator_chart_window

#property indicator_buffers 0
#property indicator_plots indicator_buffers

#define  PRINT(A) Print(#A + " = " + (string)(A))

// Создаем OBJ_CHART
const string Name = __FILE__;
const bool Init = ObjectCreate(0, Name, OBJ_CHART, 0, 0, 0) && EventSetTimer(1);
const long Chart = ObjectGetInteger(0, Name, OBJPROP_CHART_ID);

void OnInit()
{  
  // Задаем свойства объекта
  ObjectSetInteger(0, Name, OBJPROP_XSIZE, 400); // Ширина
  ObjectSetInteger(0, Name, OBJPROP_YSIZE, 250); // Высота
  ChartSetInteger(Chart, CHART_SHOW, false);

  ChartGetInteger(Chart, CHART_WIDTH_IN_PIXELS); // Если закомментировать строку, то все будет работать правильно
}

void OnDeinit( const int )
{
  ObjectDelete(0, Name);
}

void OnTimer()
{
  // Считываем свойства объекта
  PRINT(ChartGetInteger(Chart, CHART_WIDTH_IN_PIXELS));  // Правильное значение - 400
  PRINT(ChartGetInteger(Chart, CHART_HEIGHT_IN_PIXELS)); // Правильное значение - 250

  EventKillTimer();
}

int OnCalculate( const int, const int, const int, const double& [] )
{  
  return(0);
}


The result is incorrect

ChartGetInteger(Chart,CHART_WIDTH_IN_PIXELS) = 330
ChartGetInteger(Chart,CHART_HEIGHT_IN_PIXELS) = 226


But as soon as you comment out the selected line, the indicator starts working correctly

ChartGetInteger(Chart,CHART_WIDTH_IN_PIXELS) = 400
ChartGetInteger(Chart,CHART_HEIGHT_IN_PIXELS) = 250


For some reason, ChartGetInteger in OnInit affects the properties of a graphical object.

Reason: