Now I don't understand something, do I have to make 2 buffers for them to have High & Low of another period in the indicator????
and in the article
why functions work incorrectly, e.g:
//+------------------------------------------------------------------+
//|| Get High for a given bar number|
//+------------------------------------------------------------------+
doubleiHigh(stringsymbol,ENUM_TIMEFRAMES timeframe,int index)
{
double high=0;
ArraySetAsSeries(High,true);
intcopied=CopyHigh(symbol,timeframe,0,Bars(symbol,timeframe),High);
if(copied>0 && index<copied) high=High[index];
return(high);
}
What does "wrong" mean? You should give concrete examples instead of general statements "everything is bad".
Try to run the example from the CopyHigh() section:
//+------------------------------------------------------------------+
//|HighAndLow.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. | |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property description "Example of outputting High[i] and Low[i] values"
#property description "for bars selected at random".
double High[],Low[];
//+------------------------------------------------------------------+
//|| Get Low for a given bar number |
//+------------------------------------------------------------------+
double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double low=0;
ArraySetAsSeries(Low,true);
int copied=CopyLow(symbol,timeframe,0,Bars(symbol,timeframe),Low);
if(copied>0 && index<copied) low=Low[index];
return(low);
}
//+------------------------------------------------------------------+
//| Get High for a given bar number |
//+------------------------------------------------------------------+
double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
{
double high=0;
ArraySetAsSeries(High,true);
int copied=CopyHigh(symbol,timeframe,0,Bars(symbol,timeframe),High);
if(copied>0 && index<copied) high=High[index];
return(high);
}
//+------------------------------------------------------------------+
//| Expert tick function|
//+------------------------------------------------------------------+
void OnTick()
{
//--- display High and Low values for the bar with index on each tick,
//--- equal to the second of tick arrival
datetime t=TimeCurrent();
int sec=t%60;
printf("High[%d] =%G Low[%d] =%G",
sec,iHigh(Symbol(),0,sec),
sec,iLow(Symbol(),0,sec));
}
//+------------------------------------------------------------------+
This is what I got, it shows everything correctly.
What does "wrong" mean? You should give concrete examples instead of general statements "everything is bad".
Try to run the example from the CopyHigh() section:
This is what I got, it shows everything correctly.
I apologise for the unspecificity of the claims.
It seems to me that if a function is written, it is implied that it works under different parameters. Otherwise, they just don't make sense.
Let's add the TimeFrame parameter. And let's test the programme under a different parameter, for example, equal to the current one, i.e. for example, set it equal to PERIOD_D1 on a daily chart.
//+------------------------------------------------------------------+ //|HighAndLow.mq5 | //| Copyright 2009, MetaQuotes Software Corp. | | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property description "Example of outputting High[i] and Low[i] values" #property description "for bars selected at random". double High[],Low[]; input ENUM_TIMEFRAMES TimeFrame; //+------------------------------------------------------------------+ //|| Get Low for a given bar number | //+------------------------------------------------------------------+ double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index) { double low=0; ArraySetAsSeries(Low,true); int copied=CopyLow(symbol,timeframe,0,Bars(symbol,timeframe),Low); if(copied>0 && index<copied) low=Low[index]; return(low); } //+------------------------------------------------------------------+ //| Get High for a given bar number | //+------------------------------------------------------------------+ double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index) { double high=0; ArraySetAsSeries(High,true); int copied=CopyHigh(symbol,timeframe,0,Bars(symbol,timeframe),High); if(copied>0 && index<copied) high=High[index]; return(high); } //+------------------------------------------------------------------+ //| Expert tick function| //+------------------------------------------------------------------+ void OnTick() { //--- display High and Low values for the bar with index on each tick, //--- equal to the second of tick arrival datetime t=TimeCurrent(); int sec=t%60; printf("High[%d] =%G Low[%d] =%G", sec,iHigh(Symbol(),TimeFrame,sec), sec,iLow(Symbol(),TimeFrame,sec)); } //+------------------------------------------------------------------+
I apologise for the unspecificity of the claims.
It seems to me that if you write a function, it is implied that it works under different parameters. Otherwise, they just don't make sense.
Let's add the TimeFrame parameter. And let's test the program under another parameter, for example, equal to the current one, i.e., for example, set it equal to PERIOD_D1 on a daily chart.
I checked your variant - it works correctly too. I ran it as a script on the D1 timeframe with parameters H1 and D1. The values were correct (I checked the last three bars)
I checked your variant - it works correctly too. I ran it as a script on the D1 timeframe with parameters H1 and D1. The values were correct (I checked the last three bars)
I just started learning. downloaded it, put it in D:/\MetaTrader 5/ MQL5/Indicators folder.
I compiled it and put it on the chart. Some indicators don't show anything ((.
Is it supposed to be like this? Or have I done something wrong?
indicators CrossMa.mq5, Toned_WPR.mq5 and HistogramSample.mq5 do not show.
the others work
What does "wrong" mean? You should give concrete examples instead of general statements "everything is bad".
Try to run the example from the CopyHigh() section:
This is what I got, it shows everything correctly.
Copy the whole array of data???
I think it is very uneconomical to copy 1 element.
Prival:
Is it supposed to be like this? Or did I do something wrong?
Hello, Sergei. This article was written in the heat of the moment, for the very first public builds. A lot has changed since then, perhaps some indicators need to be improved.
I will revise it as soon as I have time.

- 2010.02.25
- MetaQuotes Software Corp.
- www.mql5.com
I was able to fix this problem only defining just one buffer flagged as INDICATOR_DATA and move all the others to INDICATOR_CALCULATIONS, this way CopyBuffer/GetData return the right copied items into the target arrays.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Step on New Rails: Custom Indicators in MQL5 is published:
In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
Author: Андрей