Errors, bugs, questions - page 2459

 
Uladzimir Izerski:

What?

No one can answer my question?

What's there to master? Put everything in OnInit into a separate function, make it MyOnInit. From OnInit call MyOnInit and from OnChartEvent after changing input field.

These are the basics, you may need something else. I have a free indicator in the Market which colors bars or candlesticks on the condition that MACD is above or below zero. But if you switch the chart to a line, the number of required buffers already changes. The solution is found in this way.

 
Uladzimir Izerski:

So you've already posted the code.

If I'm an inept, someone must be a pro. I don't see it yet.

I accept your effort to find an answer. It's deeper in the understanding. That is, at the level of the developers.


The code is crazy, but it's the only way it worked for me... but my computer's really busy right now...

//+------------------------------------------------------------------+
//|                                                      Probe_2.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                                 https://mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com"
#property description "The MA "
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot MA1
#property indicator_label1  "MA 1"

#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDarkOrange
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1


//--- input parameters
extern int PBB=10;  //  период МА
//--- indicator buffers
double         BufferMA1[];
//--- global variables
int            period_ma1;
int            period_max;

int            handle_ma1;
string sn,sPBB;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

   sPBB=IntegerToString(PBB);
   if(ObjectFind(0,"P2edit")!=0)
     {
      ObjectCreate(0,"P2edit",OBJ_EDIT,0,0,0);
      ObjectSetInteger(0,"P2edit",OBJPROP_XDISTANCE,300);
      ObjectSetInteger(0,"P2edit",OBJPROP_YDISTANCE,1);
      ObjectSetInteger(0,"P2edit",OBJPROP_XSIZE,70);
      ObjectSetInteger(0,"P2edit",OBJPROP_YSIZE,40);
      ObjectSetInteger(0,"P2edit",OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,"P2edit",OBJPROP_BGCOLOR,clrBlack);
      ObjectSetString(0,"P2edit",OBJPROP_TEXT,sPBB);
      ObjectSetInteger(0,"P2edit",OBJPROP_FONTSIZE,16);
      ObjectSetInteger(0,"P2edit",OBJPROP_COLOR,clrGray);
      ObjectSetInteger(0,"P2edit",OBJPROP_ALIGN,ALIGN_CENTER);
      ObjectSetInteger(0,"P2edit",OBJPROP_READONLY,false);
     }
//=================//
//
   else
     {
      string get_text=ObjectGetString(0,"P2edit",OBJPROP_TEXT);
      PBB=(int)StringToInteger(get_text);
     }
//
//=================//

//--- set global variables
   period_ma1=int(PBB<1 ? 1 : PBB);
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferMA1,INDICATOR_DATA);
   ArraySetAsSeries(BufferMA1,true);
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
//--- create handle
   ResetLastError();

   Comment("Должна соответствовать зеленой, а равна= ",period_ma1);

   handle_ma1=iMA(Symbol(),PERIOD_CURRENT,period_ma1,0,1,PRICE_CLOSE);
   if(handle_ma1==INVALID_HANDLE)
     {
      Print("The iMA(",(string)period_ma1,") object was not created: Error ",GetLastError());
      return INIT_FAILED;
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   if(id==CHARTEVENT_OBJECT_ENDEDIT)
     {
      string obj_name=sparam;
      if(StringCompare(obj_name,"P2edit")==0)
        {
         string novPBB=NULL;
         if(ObjectGetString(0,obj_name,OBJPROP_TEXT,0,novPBB))
           {
            if(StringCompare(novPBB,sPBB,false))
              {
               PBB=(int)StringToInteger(novPBB);
               ObjectSetInteger(0,"P2edit",OBJPROP_BGCOLOR,clrBlack);
               ObjectSetInteger(0,"P2edit",OBJPROP_COLOR,clrLime);
              }
           }

         //=================//
         //
         OnInit();
         //
         //=================//

         Print(TimeLocal(),"   ",ChartSetSymbolPeriod(0,Symbol(),PERIOD_CURRENT),"  ",BufferMA1[0]);
        }
     }
   return;
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//    Пробовал от сюда запускать.
//   sPBB=IntegerToString(PBB);
//   if(ObjectFind(0,"P2edit")!=0)
//    {
//       ObjectCreate(0,"P2edit",OBJ_EDIT,0,0,0);
//       ObjectSetInteger(0,"P2edit",OBJPROP_XDISTANCE,300);
//       ObjectSetInteger(0,"P2edit",OBJPROP_YDISTANCE,1);
//       ObjectSetInteger(0,"P2edit",OBJPROP_XSIZE,70);
//       ObjectSetInteger(0,"P2edit",OBJPROP_YSIZE,40);
//       ObjectSetInteger(0,"P2edit",OBJPROP_SELECTABLE,false);
//       ObjectSetInteger(0,"P2edit",OBJPROP_BGCOLOR,clrBlack);
//       ObjectSetString (0,"P2edit",OBJPROP_TEXT,sPBB);
//       ObjectSetInteger(0,"P2edit",OBJPROP_FONTSIZE,16);
//       ObjectSetInteger(0,"P2edit",OBJPROP_COLOR,clrGray);
//       ObjectSetInteger(0,"P2edit",OBJPROP_ALIGN,ALIGN_CENTER);
//       ObjectSetInteger(0,"P2edit",OBJPROP_READONLY,false);
//    } 
//   
//   if(PBB==0) PBB=(int)StringToInteger(sPBB);
// 
//   if(PBB<5) period_ma1=5; else  period_ma1=PBB;
//   if(PBB>300) period_ma1=300; else  period_ma1=PBB;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

   ArraySetAsSeries(close,true);//--- Установка массивов буферов как таймсерий
//--- Проверка количества доступных баров
   if(rates_total<fmax(period_max,4)) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-2;
      ArrayInitialize(BufferMA1,EMPTY_VALUE);
     }

//--- Подготовка данных
   int count=(limit>0 ? rates_total : 1),copied=0;
   copied=CopyBuffer(handle_ma1,0,0,count,BufferMA1);
   if(copied!=count) return 0;

//Comment("ошибка = ");

//--- возвращаемое значение prev_calculated для следующего вызова
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|            deinit                                                |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   int i;
   int obj_total=ObjectsTotal(0,0,-1);
   for(i=obj_total-1;i>=0;i--)
     {
      sn=ObjectName(0,i,0,-1);
      if(ObjectFind(0,sn)==0)
        {
         if(StringFind(sn,"P2edit",0)==0) ObjectDelete(0,sn);
        }
     }

   Comment("");
   return;
  }
//+------------------------------------------------------------------+
 
Vladimir Pastushak:

Respect for the effort.

Successful.

Grateful. Frankly.

 
Vladimir Pastushak:

Am I correct in assuming that after a pass agents sleep and wait for the remaining busy agents to finish their work?


Yes. Sometimes this downtime for free cores takes a long time when optimizing over real ticks.

Maybe developers can solve this problem?

 

There is no way to get a link to the entry in the feed. For example, to leave it in your bookmarks.

 
fxsaber:

There is no way to get a link to the entry in the feed. For example, to leave it in your bookmarks.

https://www.mql5.com/ru/users/fxsaber#profileMessage_6131695 is it?
 

Yes, but I don't see a regular way to get the link.

 
   long a=132;
   if(a>-9223372036854775808)
     {Print("а прошла проверку на  > INT64_MIN");}
   else{Print("а НЕ прошла проверку на  > INT64_MIN");}

   if(a<-9223372036854775808)
     {Print("а прошла проверку на < INT64_MIN");}
   else{Print("а НЕ прошла проверку на < INT64_MIN");}

   if(a!=-9223372036854775808)
     {Print("а прошла проверку на != INT64_MIN");}
   else{Print("а НЕ прошла проверку на != INT64_MIN");}

Result

2019.05.14 11:49:13.574 check (EURUSD,M5)       а НЕ прошла проверку на  > INT64_MIN
2019.05.14 11:49:13.574 check (EURUSD,M5)       а прошла проверку на < INT64_MIN
2019.05.14 11:49:13.574 check (EURUSD,M5)       а прошла проверку на != INT64_MIN


Is this exactly how it should be ?

 

Hi all.

In the latest builds this error has started to appear:

2019.05.14 13:03:50.526 EURUSD: history data load error
2019.05.14 13:03:50.528 EURUSD,M5: history cache allocated for 101454 bars and contains 74274 bars from 2018.01.02 09:00 to 2018.12.31 20:55
2019.05.14 13:03:50.528 EURUSD,M5: history begins from 2018.01.02 09:00
2019.05.14 13:03:50.533 history error 9 in undefined function
2019.05.14 13:03:50.533 stopped on 0% of testing interval with error '03 EURUSD'


and it keeps coming up every other time.

What does it mean?

 
Alexey Klenov:

Result

Is this exactly how it should be ?

If you dig deeper, there are several such contradictions:
void OnStart()
{
        Print( typename( LONG_MIN             ),             LONG_MIN ); //(1)
        Print( typename( -9223372036854775808 ), -9223372036854775808 ); //(2)
        Print( typename( -9223372036854775807 ), -9223372036854775807 ); //(3)

        Print( typename( INT_MIN              ),              INT_MIN ); //(4)
        Print( typename( -2147483648          ), -2147483648          ); //(5)
        Print( typename( -2147483647          ), -2147483647          ); //(6)
}

Result:

long -9223372036854775808
ulong 9223372036854775808
long -9223372036854775807

int -2147483648
long-2147483648
int -2147483647

What is the fundamental difference between (1)(2)(3) and (4)(5)(6), respectively?

Reason: