Features of the mql5 language, subtleties and tricks - page 57

 
A100:

The gift of a hard-to-find error in execution

How is ::CopyTicks better than Copyticks ?

And also why the result is always -1. These errors should be reported at compile time

It makes sense.ERR_INVALID_ARRAY got error.

The CopyTicks is exactly of type, if only its size is equal to sizeof(MqlTick). Of course, exactly this size can be checked at compile time.

Well, and the custom CopyTicks obeys all MQL rules.


The descendant arrays are not able to convert to the ancestor arrays. But element by element, yes. This is a restriction of ArrayCopy, which would be nice to remove.

 

Forum on Trading, Automated Trading Systems and Strategy Tests

Questions from beginners MQL5 MT5 MetaTrader 5

fxsaber, 2017.10.19 21:13

// Возвращает true, если нет бара с таким временем ("дырка")
bool IsHole( const string Symb, const ENUM_TIMEFRAMES TimeFrame, const datetime time )
{
  return(Bars(Symb, TimeFrame, SeriesInfoInteger(_Symbol, PERIOD_CURRENT, SERIES_FIRSTDATE), time) +
         Bars(Symb, TimeFrame, time, SeriesInfoInteger(_Symbol, PERIOD_CURRENT, SERIES_LASTBAR_DATE)) ==
         SeriesInfoInteger(_Symbol, PERIOD_CURRENT, SERIES_BARS_COUNT));
}

Works without access to the server.

 
A100:

A gift in the form of a hard-to-find error in execution

In the next build the gift will be turned off, unfortunately.

 
Are you still going to work on this account or not?
Документация по MQL5: Программы MQL5 / Выполнение программ
Документация по MQL5: Программы MQL5 / Выполнение программ
  • www.mql5.com
Каждый скрипт и каждый эксперт работает в собственном отдельном потоке. Все индикаторы, рассчитываемые на одном символе, даже если они запущены на разных графиках, работают в одном потоке. Таким образом, все индикаторы на одном символе делят между собой ресурсы одного потока. В одном потоке с индикаторами также последовательно выполняются...
 

Forum on trading, automated trading systems and testing trading strategies

Libraries: Expert

fxsaber, 2017.10.31 01:27

A little tiphack - running EAs/scripts on OBJ_CHART objects.

So running EAs hang dead - not executed in any way. But scripts work fine. Therefore, it opens some opportunities.

For example, it is possible to use Order-functions from indicators on charts, where there is already a running Expert Advisor. It's not necessary to open new auxiliary charts.

 
fxsaber:

You have usedthe tiphack, although the indicator can trade without it, through events


 
Vitaly Muzichenko:

You have useda tiphack, although the indicator can trade without it, through events

This requires a "wireframe" EA to run in parallel, i.e. an auxiliary chart is required.

The situation in the example is somewhat different: there is one chart and some EA is already running on it. And we want to run OrderSend through the indicator without opening new ones.

Of course, without DLL, for Market to pass.

 
fxsaber:

This requires that an EA "wire" is running in parallel, i.e. an auxiliary chart is required.

The situation in the example is somewhat different: there is one chart and some EA is already running on it. And we want to run OrderSend through the indicator without opening new ones.

Of course, I want it to pass the Market without DLL.

Well in the video it also works without DLL. The Expert Advisor only needs one on any chart, it may be on the current one.

 
Vitaly Muzichenko:

You only need one Expert Advisor on any chart, you can have one on the current one.

Forum on trading, automated trading systems and trading strategies testing

Peculiarities of mql5 language, tips and tricks

fxsaber, 2017.10.31 06:08

In the example, a slightly different situation: one chart and it is already running some advisor. And I want to run OrderSend through the indicator without opening new ones sometimes.

 
// Сохранение Bitmap-объекта в bmp/gif/png-файле (прозрачность не учитывается)
bool BitmapObjectToFile( const long chartID, const string ObjName, const string FileName, const bool FullImage = false )
{  
  const ENUM_OBJECT Type = (ENUM_OBJECT)ObjectGetInteger(chartID, ObjName, OBJPROP_TYPE);  
  bool Res = (Type == OBJ_BITMAP_LABEL) || (Type == OBJ_BITMAP);
             
  if (Res)
  {
    const string Name = __FUNCTION__ + (string)MathRand();

    ObjectCreate(chartID, Name, OBJ_CHART, 0, 0, 0);
    ObjectSetInteger(chartID, Name, OBJPROP_XDISTANCE, -1 e3);
    
    const long chart = ObjectGetInteger(chartID, Name, OBJPROP_CHART_ID);
        
    Res = ChartSetInteger(chart, CHART_SHOW, false) && ObjectCreate(chart, Name, OBJ_BITMAP_LABEL, 0, 0, 0) &&
          ObjectSetString(chart, Name, OBJPROP_BMPFILE, ObjectGetString(chartID, ObjName, OBJPROP_BMPFILE)) &&
          (FullImage || (ObjectSetInteger(chart, Name, OBJPROP_XSIZE, ObjectGetInteger(chartID, ObjName, OBJPROP_XSIZE)) &&
                         ObjectSetInteger(chart, Name, OBJPROP_YSIZE, ObjectGetInteger(chartID, ObjName, OBJPROP_YSIZE)) &&
                         ObjectSetInteger(chart, Name, OBJPROP_XOFFSET, ObjectGetInteger(chartID, ObjName, OBJPROP_XOFFSET)) &&
                         ObjectSetInteger(chart, Name, OBJPROP_YOFFSET, ObjectGetInteger(chartID, ObjName, OBJPROP_YOFFSET)))) &&
                         ChartScreenShot(chart, FileName, (int)ObjectGetInteger(chart, Name, OBJPROP_XSIZE),
                                                          (int)ObjectGetInteger(chart, Name, OBJPROP_YSIZE));
    ObjectDelete(chartID, Name);
  }                    

  return(Res);
}


Application

// Сохраняет в png-файлах все Bitmap-объекты текущего чарта
void OnStart()
{  
  for (int i = ObjectsTotal(0) - 1; i >= 0; i--)
  {
    const string Name = ObjectName(0, i);
    
    BitmapObjectToFile(0, Name, (string)ChartID() + "\\" + Name + ".png");    
  }      
}


SZY The BMP->GIF/PNG file converter is also implemented.

Reason: