Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1613

 

Aleksei Stepanenko thank you.


Valeriy Yastremskiy Maybe it's because the code is incomplete, as I removed all unnecessary functions.


//+----------------------------------------------------------------------------+
//|                                                          AverageRange.mq4  |
//|                                                    Ким Игорь В. aka KimIV  |
//|                                                       http://www.kimiv.ru  |
//|                                                                            |
//|  14.09.2005  Скрипт для расчёта:                                           |
//|              средней волатильности инструмента High-Low                    |
//|              среднего размера тела свечи       ABS(Open-Close)             |
//|              среднего размера тени свечи                                   |
//|                                                                            |
//|  17.11.2007  Возможность использования заданного количества баров          |
//+----------------------------------------------------------------------------+
#property copyright "Ким Игорь В. aka KimIV"
#property link      "http://www.kimiv.ru"
#property  show_inputs

extern datetime BeginDateCalc = D'2013.01.01';
extern datetime EndDateCalc   = D'2013.12.31';
extern int      NumberOfBars  = 100;         


//+----------------------------------------------------------------------------+
//|  script program start function                                             |
//+----------------------------------------------------------------------------+
void start() {
   int    i;           
   int    b  = 0;     
   int    bb = 0;      
   int    h  = 0;      
   int    l  = 0;     
   int    s  = 0;      
   int    t  = 0;      
   string st = "";        

  for (i = Bars; i > 0; i--) {
    
    if ((Time [i] >= BeginDateCalc && Time [i] <= EndDateCalc && NumberOfBars <= 0)
    || (NumberOfBars > 0 && NumberOfBars >= i)) {
      
      if (bb == 0) bb = i;
      s += (High [i] - Low [i]) / Point;
      t += MathAbs (Open [i] - Close [i]) / Point;
      
      if (Open [i] > Close [i]) {
        h += (High [i] - Open [i]) / Point;
        l += (Close [i] - Low [i]) / Point;
      } else {
        h += (High [i] - Close [i]) / Point;
        l += (Open [i] - Low [i]) / Point;
      }
      
      b++;
    }
  }

  st =      "Начало: " + TimeToStr (Time [bb], TIME_DATE | TIME_MINUTES) + "\n";
  st = st + "Конец: " + TimeToStr (Time [bb - b + 1], TIME_DATE | TIME_MINUTES) + "\n";
  st = st + "Использовано баров: " + b + "\n";
  st = st + "Средняя волатильность: " + s / b + " п.\n";
  st = st + "Средний размер тела: " + t / b + " п.\n";
  st = st + "Средний размер верхней тени: " + h / b + " п.\n";
  st = st + "Средний размер нижней тени: " + l / b + " п.";

  Comment (st);
}
//+----------------------------------------------------------------------------+
Aleksei Stepanenko
Aleksei Stepanenko
  • www.mql5.com
Профиль трейдера
 
Valeriy Yastremskiy #:

To be honest, I don't understand Kim's logic, why the conditions of bar time exceeding the set value and the number of calculated bars are negative with OR the number of calculated bars is greater than the number of bars Barz)))) And at the same time it just corrects the custom parameters)

And it doesn't even display an alert that the user has messed up)

Logically, if NumberOfBars is specified (greater than 0), the time is ignored and just the latest bars are taken into account

But a user can make a mistake with dates or if there is a hole in the quote, then nothing is printed, it just returns DivideByZero :-)

 
Hi

can anyone know how to convert quotes from mt5 to mt4? or any ways to take advantage of better history from mt5 to mt4... except TDS2😊
 
Pavel Malyshko #:
Hi

can anyone know how to convert quotes from mt5 to mt4? or any ways to take advantage of better history from mt5 to mt4... except TDS2😊
Export/import
 
MakarFX #:
Export/import

so mt5 has a different quote format. mt4 won't read them. that's the problem...😎

 
Pavel Malyshko #:

so mt5 has a different quote format. mt4 won't read them. that's the problem...😎

MT5 export to csv and mt4 reads everything

 
Oksana_Timakova Point;

Why do I need division by Point?

...

I strongly recommend it:

s+=MathRound((High [i] - Low [i]) / Point);

Otherwise you get an oops)))

void OnStart(){
   double first=0.00001;
   double point=0.00001;
   for(uint i=0;i<10;++i){
      double value=NormalizeDouble(first+i*point,5);
      int res=(int)((value-first)/point);
      if (res!=i)
         PrintFormat("Alert: (%.5 f-%.5 f)/%.5 f!=%u, but ==%i",value,first,point,i,res);
   }
}
2021.09.12 11:06:26.041 Script test EURGBP,H1: removed
2021.09.12 11:06:26.038 test EURGBP,H1: uninit reason 0
2021.09.12 11:06:26.038 test EURGBP,H1: Alert: (0.00007-0.00001)/0.00001!=6, but ==5
2021.09.12 11:06:26.038 test EURGBP,H1: Alert: (0.00003-0.00001)/0.00001!=2, but ==1
2021.09.12 11:06:26.038 test EURGBP,H1: initialized
2021.09.12 11:06:25.998 Script test EURGBP,H1: loaded successfully
 

How to make the indicator window completely hide the price chart?

I cannot do it through ChartSetInteger(0,CHART_HEIGHT_IN_PIXELS,0,0). I have to first set the size of the indicator and then add the height of the price window to it:

int chart_height=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);
IndicatorSetInteger(INDICATOR_HEIGHT,200+chart_height);


However, if you open the order window at the bottom, the size of the indicator window becomes larger than the screen size and the terem shows the price again.

I don't know how to measure the order window, besides, it keeps changing.

What to do?

 

Please help!

Help translate this code into mql5...

I want to understand how to work with handles.

//+------------------------------------------------------------------+
//|                                                Stochastic.v1.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers  2
#property indicator_plots    2
#property indicator_minimum -51
#property indicator_maximum  51
#property indicator_level1   0
#property indicator_levelstyle 0
#property indicator_levelcolor clrDimGray
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDimGray
#property indicator_style1  STYLE_SOLID
#property indicator_width1  0
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  0
//--- input parameters
input int             WeekCount   = 1;     // Ограничение истории в неделях(0-вся история)
input int             StochPeriod = 14;
input ENUM_TIMEFRAMES TimeFrame   = PERIOD_CURRENT;
//--- indicator buffers
double   Label1Buffer[];
double   Label2Buffer[];
int      index=-1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(2);
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   ArrayInitialize(Label1Buffer,0);
   ArrayInitialize(Label2Buffer,0);
   int limit,i;
   int barPlus=iBarShift(_Symbol,_Period,iTime(_Symbol,PERIOD_W1,WeekCount));
   limit=rates_total-prev_calculated-1;
   if(WeekCount!=0)limit=barPlus-2;
   if(limit<1) return(0);
   for(i=limit;i>=0;i--)
     {
      index=iBarShift(_Symbol,TimeFrame,time[i],false);
      Label1Buffer[i]=iStochastic(_Symbol,TimeFrame,StochPeriod,3,3,MODE_SMA,1,MODE_MAIN,index)-50; 
     }
   for(i=limit;i>=0;i--)
     {
      Label2Buffer[i]=iMAOnArray(Label1Buffer,0,StochPeriod*3,0,MODE_SMA,i);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

I would appreciate your help.

 
MakarFX #:

Please help!

Help translate this code into mql5...

I want to understand how to work with handles.

I would appreciate your help.

The only question is about this line

  Label1Buffer[i]=iStochastic(_Symbol,TimeFrame,StochPeriod,3,3,MODE_SMA,1,MODE_MAIN,index)-50; 
-50 redundant and array