Discussion of article "Step on New Rails: Custom Indicators in MQL5"

 

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: Андрей

 

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

CopyHigh


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.



 
Rosh   :

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));
  }
//+------------------------------------------------------------------+
 
zfs   :


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)

 
Rosh   :


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)



Yes, it works well. Apparently, it's my fault, I mean the direction of arrays. But why I got different data during testing will remain a secret for me. Thank you for your attention. When you start something new, you always have doubts.
 

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

 
Rosh:

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.

 
Attached source code files and source code insets in HTML code are now completely translated into Portuguese for your convenience.
MQL5.community - User Memo
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 
Hello and thank you for this great article, a question :
did you never experienced an anomaly where if you define more than one INDICATOR_DATA flagged buffer consequently on your iCustom derived class code you always get a bad -1 when try to retrieve data (with CopyBuffer/GetData) from all the INDICATOR_DATA flagged buffer except the first one ?

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.