Questions from Beginners MQL5 MT5 MetaTrader 5 - page 747

 
Sergey Gritsay:

Vitaliy, check out https://www.mql5.com/ru/docs/series/timeseries_access#synchronized, there is a sample script for loading history, it might help

Thank you, I will try to deal with it.

Now a question already arises:

The next important check is to check the type of program from which the function is called. Recall that sending a request for refreshing a timeseries with the same period as that of the indicator that calls the refresh is highly undesirable. The undesirability of requesting data of the same symbol-period, as the indicator has, because the historical data update is done in the same thread, in which the indicator works. Therefore, there is a high probability of a clash. To check it, we use theMQL5InfoInteger() functionwith theMQL5_PROGRAM_TYPE modifier.

if(MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR&&Period()==period&&Symbol()==symbol)
return(-4);


It should work in my indicator.

 

Gentlemen, struggling with ZigZag.

I need to get the exact data of the four vertices. Turns out the first, most necessary vertex iCustom gives incorrectly. It lags from the graphic image, the next three are correct. Similar thing has already been found - https://www.mql5.com/ru/forum/100123

I've tried everything I could, I even created a separate Expert Advisor just for checking the data of ZigZag. See for yourself, maybe I made a mistake somewhere? Just install and enable visualisation of opening prices. Get this-


//+------------------------------------------------------------------+
//|                                                  data_ZigZag.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

input string   data_Zig_Zag_IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII;
input int      ExtDepth=12;
input int      ExtDeviation=5;
input int      ExtBackstep =3;
input int n_zz=100;//n_zz =100; 
double pd_1,pd_2,pd_3,pd_4;
int pn_1,pn_2,pn_3,pn_4;
int zz_Handle;
double zz_buf[];
datetime time[];
string this_sym;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   this_sym=Symbol();
//+------------------------------------------------------------------+
//--- сохраним текущий символ графика для дальнейшей работы советника именно на этом символе
   zz_Handle=iCustom(this_sym,0,"Examples\\Zigzag",
                     ExtDepth,
                     ExtDeviation,
                     ExtBackstep
                     );
   Print(__FUNCTION__,"__LINE__",__LINE__," . . . . . ",
         "zz_Handle = ",zz_Handle,"  error = ",GetLastError());
//--- проверяем наличие хендла индикатора
   if(zz_Handle==INVALID_HANDLE)
     {
      //--- хендл не получен, выводим сообщение в лог об ошибке, завершаем работу с ошибкой
      Print(__FUNCTION__,"__LINE__",__LINE__," ----- ",
            "Не удалось получить хендл индикатора zz_Handle","  error = ",GetLastError());
      return(-1);
     }
//--- добавляем индикатор на ценовой график
   ChartIndicatorAdd(ChartID(),0,zz_Handle);
//--- устанавливаем индексацию для массива zz_buf как в таймсерии
   ArraySetAsSeries(zz_buf,true);
   ArraySetAsSeries(time,true);
//---

//+------------------------------------------------------------------+
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   IndicatorRelease(zz_Handle);
   ArrayFree(zz_buf);
   ArrayFree(time);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//+------------------------------------------------------------------+
   int zz_copy=0;
//--- копируем данные из индикаторного массива в динамический массив 
   zz_copy=CopyBuffer(zz_Handle,0,0,n_zz,zz_buf);
//--- если есть ошибки, то выводим сообщение в лог об ошибке и выходим из функции
   if(zz_copy<0)
     {
      Print("Не удалось скопировать данные из индикаторного буфера zz_buf.  error = ",
            GetLastError()); return;
     }
//+------------------------------------------------------------------+
   pd_1 =0;
   pd_2 =0;
   pd_3 =0;
   pd_4 =0;
   pn_1 =0;
   pn_2 =0;
   pn_3 =0;
   pn_4 =0;

   int zz_q=ArraySize(zz_buf);
   int q=0;

   for(q=0; q<zz_q; q++)
     {
      if(zz_buf[q]!=0 && zz_buf[q]!=EMPTY_VALUE)
        {
              if(pd_1==0) { pn_1=q; pd_1=zz_buf[q]; }
         else if(pd_2==0) { pn_2=q; pd_2=zz_buf[q]; }
         else if(pd_3==0) { pn_3=q; pd_3=zz_buf[q]; }
         else if(pd_4==0) { pn_4=q; pd_4=zz_buf[q]; }
        }
      if(pn_4>0)break;
     }
//+------------------------------------------------------------------+
   CopyTime(this_sym,Period(),0,n_zz,time);
//+------------------------------------------------------------------+
   ObjectDelete(0,"name1");
   string name1="name1";

   if(!ObjectCreate(0,name1,OBJ_ARROW_UP,0,time[pn_1],pd_1))
     {
      Print(__FUNCTION__,"__LINE__",__LINE__,
            ": не удалось создать знак \"Стрелка вверх\"! Код ошибки = ",GetLastError());
     }
//--- установим размер знака 
   ObjectSetInteger(0,name1,OBJPROP_WIDTH,6);
//+------------------------------------------------------------------+
   ObjectDelete(0,"name2");
   string name2="name2";

   if(!ObjectCreate(0,name2,OBJ_ARROW_UP,0,time[pn_2],pd_2))
     {
      Print(__FUNCTION__,"__LINE__",__LINE__,
            ": не удалось создать знак \"Стрелка вверх\"! Код ошибки = ",GetLastError());
     }
//--- установим размер знака 
   ObjectSetInteger(0,name2,OBJPROP_WIDTH,6);
//+------------------------------------------------------------------+
   ObjectDelete(0,"name3");
   string name3="name3";

   if(!ObjectCreate(0,name3,OBJ_ARROW_UP,0,time[pn_3],pd_3))
     {
      Print(__FUNCTION__,"__LINE__",__LINE__,
            ": не удалось создать знак \"Стрелка вверх\"! Код ошибки = ",GetLastError());
     }
//--- установим размер знака 
   ObjectSetInteger(0,name3,OBJPROP_WIDTH,6);
//+------------------------------------------------------------------+
   ObjectDelete(0,"name4");
   string name4="name4";

   if(!ObjectCreate(0,name4,OBJ_ARROW_UP,0,time[pn_4],pd_4))
     {
      Print(__FUNCTION__,"__LINE__",__LINE__,
            ": не удалось создать знак \"Стрелка вверх\"! Код ошибки = ",GetLastError());
     }
//--- установим размер знака 
   ObjectSetInteger(0,name4,OBJPROP_WIDTH,6);
//+------------------------------------------------------------------+
///*
   if(pd_1!=0 && pd_2!=0 && pd_3!=0 && pd_4!=0)
      Alert(__FUNCTION__,"__LINE__",__LINE__,
            "   q =",q,
            "   pd_1 =",pd_1,
            "   pd_2 =",pd_2,
            "   pd_3 =",pd_3,
            "   pd_4 =",pd_4,

            "   pn_1 =",pn_1,
            "   pn_2 =",pn_2,
            "   pn_3 =",pn_3,
            "   pn_4 =",pn_4,
            "   TimeCurrent()=",TimeCurrent()
            );
//*/
//+------------------------------------------------------------------+
  }
//+------------------------------------------------------------------+
How to get accurate data?
Как получить значение индикатора ZigZag в точках...
Как получить значение индикатора ZigZag в точках...
  • 2006.04.09
  • www.mql5.com
Уважаемые гуру и другие адепты MQ4 Я прикрепил схемку. Это стандартный ZigZag...
 
Hello. The day before yesterday I started studying MQL.


The tester gives this result:


I can't figure out the catch. Dear professionals please enlighten me, I would be very grateful.


 

Question Can I write a program in Metatrader 4 to open from 2 to 250 positions of my choice with a set stoploss and set profit in one click? So I don't have to manually open one at a time

 
fxtz:

Question Can I write a program in Metatrader 4 to open from 2 to 250 positions of my choice with a set stoploss and set profit in one click? You do not need to open one by one

Yes, you can. But you are asking the question in the wrong place - here on MT5.

There are several threads for newbies on MT4.

For example - here.

 
antonsinichkin:
Hello. The day before yesterday I started studying MQL.


The tester gives this result:


Where's the catch I can't figure out. Distinguished professionals please enlighten me, I will be very grateful.



Translate it into string before the print. Or explain what is wrong.
 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 
Good afternoon. After the latest MT5 update to build 1604 my indicators are no longer working correctly. I am using
So called "liquid" indicators. For example, I have several multi-period stochastics in one window. Well, now the short ones are drawn
As before, slightly longer ones draw only a few bars and the longest ones are not drawn at all.

I have the impression that they have suddenly started to lack history. Can you tell me what could be wrong?
 
I just switched from mql4 to mql5. I am testing an Expert Advisor on the RTS Index and now I have the problem that it opens several deals, but one of the conditions for opening a deal is as follows: if (...OrdersTotal()==0). Why does not this condition work? What can I do to open only one position?
 
RogozaIV:
I have recently switched from mql4 to mql5. I am testing an Expert Advisor on the RTS Index and have a problem with opening several positions, although one of the conditions for opening a position is specified: if (...OrdersTotal()==0). Why does not this condition work? What can I do to open only one trade?
PositionsTotal()
Reason: