OOP and Indicators

 
Dears,

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! :)
The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor
The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor
  • 2010.11.10
  • Samuel Olowoyo
  • www.mql5.com
This article explains how to use the major functionalities of the MQL5 Standard Library Trade Classes in writing Expert Advisors which implements position closing and modifying, pending order placing and deletion and verifying of Margin before placing a trade. We have also demonstrated how Trade classes can be used to obtain order and deal details.
Reason: