Questions from Beginners MQL5 MT5 MetaTrader 5 - page 603

 
Alex:

Thank you for your answers and patience.


Vladimir, I've probably bored you already:) But I'm having a hard time with the basics. I tried to do a test task with Copy functions... The indicator isn't drawn, though there are numbers in Printe... I don't understand anything.


One and the same array UpBar goes to two buffers: 0 and 1.

And for the indexes you don't want to set values for, write empty values.

And, as far as I understand, you are writing values from 3 to 3 bars. This means that the earliest values will be written, not the latest (the numbering order is different from mql4).

 
Alex:

Thank you for your answers and patience.


Vladimir, I've probably bored you already:) But I'm having a hard time with the basics. I tried to do a test task with Copy functions... The indicator isn't drawn, though there are numbers in Printe... I don't understand anything.


//+------------------------------------------------------------------+
//|                                                        PBars.mq5 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   1
//--- plot UpBar
#property  indicator_label1  "UpBar"
#property  indicator_type1   DRAW_HISTOGRAM
#property  indicator_color1  clrGreen
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  6
////--- plot DnBar
//#property indicator_label2  "DnBar"
//#property indicator_type2   DRAW_HISTOGRAM
//#property indicator_color2  clrRed
//#property indicator_style2  STYLE_SOLID
//#property indicator_width2  6
//--- input parameters
input int   Histori=30;
input ENUM_TIMEFRAMES TimeFrame=0;
input string  Simvol="EURUSD";
//--- indicator buffers
double         UpBar[];
//double         DnBar[];
double         O_Price[];
double         C_Price[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,UpBar,INDICATOR_DATA);
//SetIndexBuffer(1,UpBar,INDICATOR_DATA);
   SetIndexBuffer(1,O_Price,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,C_Price,INDICATOR_CALCULATIONS);
//---
   ArraySetAsSeries(O_Price,true);
   ArraySetAsSeries(C_Price,true);
   ArraySetAsSeries(UpBar,true);
   ArrayInitialize(UpBar,0.0);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(close,true);

   if(prev_calculated==0)
     {
      ArrayInitialize(UpBar,0.0);
      ArrayInitialize(O_Price,0.0);
      ArrayInitialize(C_Price,0.0);
      Print(__FUNCTION__);
      ResetLastError();
      if(CopyOpen(Simvol,TimeFrame,0,Histori,O_Price)==-1)
         Print("Error CopyOpen #",GetLastError());
      ResetLastError();
      if(CopyClose(Simvol,TimeFrame,0,Histori,C_Price)==-1)
         Print("Error CopyClose #",GetLastError());
      for(int t=3; t<Histori; t++)
        {
         UpBar[t]=MathAbs(NormalizeDouble((O_Price[t]-C_Price[t]),Digits()));
         Print(IntegerToString(t)," ",DoubleToString(UpBar[t],Digits()));
         int g=0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

And the result:

Result

 
Karputov Vladimir:

And the result:


Once again, thank you very much.
 
Alex:
Once again, thank you very much.
You are welcome. Do not hesitate to contact me if you have any questions on MQL5.
 

Are there any functions in MQL4 that give maximum/minimum price values for a given number of bars?

I think there was one, but I can't find it...

 
-Aleks-:

Are there any functions in MQL4 that give maximum/minimum price values for a given number of bars?

I think there was one, but I can't find it...

https://docs.mql4.com/ru/series/ihighest

https://docs.mql4.com/ru/series/ilowest

iHighest - Доступ к таймсериям и индикаторам - Справочник MQL4
iHighest - Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
iHighest - Доступ к таймсериям и индикаторам - Справочник MQL4
 
Yes, yes thanks - I didn't look hard enough - I've already found it myself.
 
-Aleks-:
Yes, thank you - I didn't look hard enough - I've already found it myself.
Functions compatible with mql5 CopyHigh and CopyLow then in the resulting array ArrayMaximum and ArrayMinimum
 
Is it true that each set of variables that make up a trading system has a random distribution of profits and losses?
 
Евгений:
Is it true that each set of variables that make up a trading system has a random distribution of profits and losses?

A counter question.

Do you think that the movement of any currency pair: chart, bid and ask prices, etc., depend on the set of your variables?