How do I get Open,Low,High,Close parameters in MQL5? - page 3

 

An example of a script:

//+------------------------------------------------------------------+
//|                                                            1.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property script_show_inputs
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   for(int i=0;i<3;i++)
      Print("# ",i,": ",DoubleToString(iOpen(Symbol(),PERIOD_CURRENT,i),Digits()));
//---
  }
//+------------------------------------------------------------------+

and the result:

2019.07.29 20:36:41.215 1 (EURUSD,H1)   # 0: 1.11399
2019.07.29 20:36:41.215 1 (EURUSD,H1)   # 1: 1.11425
2019.07.29 20:36:41.215 1 (EURUSD,H1)   # 2: 1.11319


Edited.

Files:
1.mq5  2 kb
 

Here they are.

Works on both 4pc and 5pc

In 4-rka apply Period(), Symbol(), etc.

In 5-pc, apply _Period, _Symbol(), etc.

iBars

Returns the number of bars in the history for a specified symbol and period

iBarShift

Returns the offset of the bar to which the specified time belongs

iClose

Returns the closing price of the bar of the corresponding chart

iHigh

Returns the value of the maximal price of the bar in the chart

iHighest

Returns the index of the highest found value of the corresponding chart

iLow

Returns the value of the minimum bar price of the corresponding chart

iLowest

Returns the index of the smallest found value of the corresponding chart

iOpen

Returns the value of the bar open price of the corresponding chart

iTime

Returns the bar open time of the corresponding chart

iVolume

Returns the value of the tick volume of the bar in the chart

iBars - Доступ к таймсериям и индикаторам - Справочник MQL4
iBars - Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
iBars - Доступ к таймсериям и индикаторам - Справочник MQL4
 
With CopyRates, it worked. It works.
 

And here is theCopyRates variant

//+------------------------------------------------------------------+
//|                                                            1.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property script_show_inputs
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   MqlRates rates[];
   ArraySetAsSeries(rates,true);
   int start_pos=0,count=3;
   if(CopyRates(Symbol(),Period(),start_pos,count,rates)!=count)
      return;

   for(int i=0;i<count;i++)
      Print("Open # ",i,": ",DoubleToString(rates[i].open,Digits()));
//---
  }
//+------------------------------------------------------------------+

and result

2019.07.29 20:44:55.491 1 (EURUSD,H1)   Open # 0: 1.11399
2019.07.29 20:44:55.491 1 (EURUSD,H1)   Open # 1: 1.11425
2019.07.29 20:44:55.491 1 (EURUSD,H1)   Open # 2: 1.11319
Files:
1.mq5  3 kb
 
Alexey Viktorov:

Alexey, this is for those who are in a tank. And for the normal ones, CopyRates() is available in mql4 as well. So forget all iOpen and other nonsense. I don't even understand why they put it in mql5.

Oh! Teeny-weeny guys have appeared))

Why do we need in practice to have a lot of consecutive OHLC values - which you suggested to get using CopyRates() ? - except to meditate? ))))

there's not much practical use, here's a trivial task, the unloading (or use) of the Fractals indicator, i have such a code:

#define  Time(n)   iTime(NULL,0,n)
//+------------------------------------------------------------------+
void OnStart()
  {
   int handle=iFractals(NULL,0);
   if(handle==INVALID_HANDLE)
     {
      Print("Error№,",::GetLastError()," create handle indicator");
      return;
     }
   int count=0,i=0;
   double buffup[1],buffdn[1];
   while(i<Bars(_Symbol,_Period) && count<10)
     {
      if(CopyBuffer( handle,0,i,1, buffup)<1) Print("buffup , error № ",::GetLastError());
      if(CopyBuffer( handle,1,i,1, buffdn)<1) Print("buffup , error № ",::GetLastError());
      if(buffup[0]<EMPTY_VALUE && ++count>0)  Print("Bar № ",i," : ",Time(i)," , Fractals Up = ",buffup[0]);
      if(buffdn[0]<EMPTY_VALUE && ++count>0)  Print("Bar № ",i," : ",Time(i)," , Fractals Dn = ",buffdn[0]);
     i++;
     }
  }
//+------------------------------------------------------------------+


show me your code with use of CopyRates()...

 
Vladimir Karputov:

And here is theCopyRates variant

and result

But, if we need to constantly track data on new bars, it means to refer to CopyRates on every tick and make a timeseries on every tick?

I'm trying to figure out the best place to put CopyRates.

 
Реter Konow:

But, if you need to constantly track data on new bars, then do you need to refer to CopyRates on every tick and make a timeseries on every tick?

I'm trying to understand where better to put the CopyRates.

I've already asked above: WHY? Is it necessary to consider the value of zero bar (the rightmost bar on the chart)?

 
Vladimir Karputov:

I have already asked above: WHY? Should the value of the zero bar (the rightmost bar on the chart) be taken into account?

For the table. There are four parameters in the table: Open, Close, High, Low, the last 10 bars, not including the current one.

Last, in the sense of moving backwards from the current one (zero).

 
Igor Makanu:

Ooh! teeny-weenies have appeared))

why in practice to have a lot of consecutive OHLC values - which you propose to get using CopyRates() ? - except to meditate? ))))

there's not much practical use, here's a trivial task, the unloading (or use) of the Fractals indicator, i have such a code:


show me your code using CopyRates()...

Igor, you should go to the first grade. They teach letters there and after studying you will understand the difference between CopyRates and CopyBuffer.

You better offer me a solution to this problem WITHOUT CopyRates(!)

Forum on trading, automated trading systems and trading strategies testing

How to get Open,Low,High,Close parameters in MQL5?

Retrog Konow, 2019.07.29 19:58

For the table. There are four parameters in the table: Open, Close, High, Low, last 10 bars, not including the current one.

Last, I mean if moving backwards from the current one (zero).


 
Реter Konow:

For the table. There are four parameters in the table: Open, Close, High, Low, the last 10 bars, not including the current one.

Last, in the sense of moving backwards from the current one (zero).

In this case CopyRates from the first bar is unambiguously 10. And call it not every tick, but enough when a new bar appears.