Errori, bug, domande - pagina 2133

 
Errore in CCanvas::Attach. Linea evidenziata mancante
//+------------------------------------------------------------------+
//| 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, dovrei chiedere a Nikolay Semko di scrivere una versione alternativa del kanvas, con un buon anti-aliasing, forse una visione diversa, e scrivere un articolo, forse lo farà?
 
Aleksandr Teleguz:

Salve. Per favore, aiutatemi a trovare la causa di questo errore. Sto trasferendo un indicatore da mql4 a mql5. Sto usando la seguente "shell" per le funzioni di iHigh:

Come risultato, ottengo l'errore 4301: "simbolo sconosciuto", anche se una stringa restituita dalla funzione Symbol() viene passata come parametro del simbolo. Ecco un frammento di codice della funzione che chiama iHigh

Chi è "io"? Qual è il suo valore prima del ciclo?


State facendo la chiamata ResetLastError prima diiHigh?

 
Vladimir Karputov:

Chi è la "i"? Qual è il suo valore prima del ciclo?


Fate una chiamata ResetLastError prima diiHigh?

Il valore di i è passato attraverso la funzione OnCalculate

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


Non ho fatto la chiamata ResetLastError, ora l'ho fatta - il codice di errore è lo stesso. Uso gli array low[i], high[i] ecc. nella funzione OnCalculate, e iHigh, iLow ecc. nelle funzioni esterne.

 
Aleksandr Teleguz:

Il valore di i è messo in loop nella funzione OnCalculate


Non ho chiamato ResetLastError, ora l'ho fatto - il codice di errore è lo stesso. Uso gli array low[i], high[i] ecc. nella funzione OnCalculate e iHigh, iLow ecc. nelle funzioni esterne.

Fornire il codice MQL5 che può essere eseguito e descrivere le condizioni in cui si verifica l'errore.

 
Vladimir Karputov:

Fornire il codice MQL5 che può essere eseguito e descrivere le condizioni in cui si verifica l'errore.

Sembra che ci sia qualcosa di sbagliato nel mio terminale. Ho eseguito lo stesso codice sul netbook su un altro mt5, stesso conto demo - nessun errore.

Ecco il codice stesso:

/+------------------------------------------------------------------+
//|                                                      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:

Sembra che ci sia qualcosa che non va nel mio terminale. Ho eseguito lo stesso codice sul netbook su un altro mt5, stesso conto demo - nessun errore.

Ecco il codice stesso:

Nota: stai scrivendo nella sezione principale del forum MQL5, è qui che si discute di MQL5. Per MQL4 c'è una sezione speciale:MQL4 e MetaTrader 4. Per favore pubblicate il vostro codice nella sezione appropriata. È ancora meglio quando l'editore rispetta gli utenti e pubblica il codice nell'intestazione dove viene visualizzato il tipo di lingua.

 
Questo è MQL5.
 

Ciao!
Non riesco a cambiare il timeframe di un oggetto grafico - non so se è il terminale che fa casino o io.
Ecco il codice di controllo

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);
}
 
Bug OBJ_CHART. Indicatore
#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);
}


Il risultato non è corretto

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


Ma non appena si commenta la linea selezionata, l'indicatore inizia a funzionare correttamente

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


Per qualche motivo, ChartGetInteger in OnInit influenza le proprietà di un oggetto grafico.

Motivazione: