You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am experiencing hard time in using the indicator classes in the library.
Regarding OOP, I found first this excellent article, but unfortunatelly the author doesn't use the library to build his indicators in his EA: https://www.mql5.com/en/articles/138
Then I bought the book "Expert Advisor Programming for MetaTrader5". In the book the author does the following, for example to build a moving average in an EA:
i. Include pre processing directive "#include <Indicators\Trend.mqh>";
ii. Creates and object: "CiMA MA";
iii. In the OnInit() event handler initializes the object like this: "MA.Init(_Symbol, _Period, MAShift, MAMethod, MAPrice);" --> here is one problem, the function "Init" seems to not exist at all, I tried to use "MA.Create(.......)" without success;
iv. Finally use the Main function in the OnTick() function: "MA.Main()";
Using the "Create" method I think I can successfully create the indicator for there is no error message, but when I use the "Main" method nothing happens, not even an error message.
I have managed to create my own class to work with indicator because I have never used the indicator library successfully. However, I suspect that it has been more costly in computational terms, thats why I would like to try the library.
It appears that even EAs suggested by MetaQuotes don't use the library that way very much, for example: https://www.mql5.com/en/code/2154 or https://www.mql5.com/en/code/1921 , although I realize that programming styles are a very personal matter.
I am actually trying to use the SAR, this way:
CiSAR mySAR;
int OnInit()
{
if(mySAR.Create(_Symbol, TFSAR,0.02,0.2)==false);
{Alert("Error creating indicator ", GetLastError(), " !!");}
return(0);
}
and then in the OnTick() function I just use "mySAR.Main(1)".
Could anyone please recommend me an article or give any suggestion on what I am doing wrong?
Thanks! :)