Building an Object Oriented Indicator Action Library

 

Hey everyone,

I was thinking today if it is possible to build an indicator action library using the object oriented programming in mql5 ?  Let me give an example:

Let's say I'm programming an EA that enters the market shortwhen the EMA trend of period 34 is smallerthan zero, and the MACD Signal crosses the zero line downwards.

Normally I would have to write everything for scratch.  Would it be possible to write a library to make the following possible:

if (EMA.trend == DOWN && MACD.signal.zero_cross == DOWN) {trade.open.short(lot_size,stoploss,takeprofit);}

 Of course the above is just an example and not how it shoulkd exactly be structured.

If it is possible won't it be great if we all can make one big library for all the indis to make this possible ?

I know this article (https://www.mql5.com/en/articles/116) explains how to work if OO programming, but I think it would be awesome if metaquotes could write such a library for all to use.  I don't have the time or knowledge to do this all by myself 

Writing an Expert Advisor Using the MQL5 Object-Oriented Programming Approach
  • 2010.07.12
  • Samuel
  • www.mql5.com
This article focuses on the object oriented approach to doing what we did in the article "Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners" - creating a simple Expert Advisor. Most people think this is difficult, but I want to assure you that by the time you finish reading this article, you will be able to write your own Expert Advisor which is object oriented based.
 

This is the concept for which I took on learning MQL5. I waited, and neglected poor old MQL4 all the while.

 I'm not compiling yet... will my version be done in time for the competion? Absolutely not. Hopefully I'll have a pet zombie in the race, at any rate.

I am thinking in selfish terms for my library. I am only making my class structure fit my particular functions of the things you want to do.

However when it comes down to it, there are a lot of very useful "bits" for putting in place - open source mentalities, rather than only compiling before distribution, is healthy.

Leadership on the MetaQuotes team into these areas would be the most simple answer. Start version tracking database for user projects. The best conceptual material on the site I have found are the Price Histogram indicator and the VOM library. Those projects are already prepared for a thorough communal enhancing - and have well documented concepts for the OO usage (at least in part)

The Price Histogram (Market Profile) and its implementation in MQL5
  • 2010.01.28
  • Dmitry
  • www.mql5.com
The Market Profile was developed by trully brilliant thinker Peter Steidlmayer. He suggested to use the alternative representation of information about "horizontal" and "vertical" market movements that leads to completely different set of models. He assumed that there is an underlying pulse of the market or a fundamental pattern called the cycle of equilibrium and disequilibrium. In this article I will consider Price Histogram - a simplified model of Market Profile, and will describe its implementation in MQL5.
 
Lugner:

This is the concept for which I took on learning MQL5. I waited, and neglected poor old MQL4 all the while.

 I'm not compiling yet... will my version be done in time for the competion? Absolutely not. Hopefully I'll have a pet zombie in the race, at any rate.

I am thinking in selfish terms for my library. I am only making my class structure fit my particular functions of the things you want to do.

However when it comes down to it, there are a lot of very useful "bits" for putting in place - open source mentalities, rather than only compiling before distribution, is healthy.

Leadership on the MetaQuotes team into these areas would be the most simple answer. Start version tracking database for user projects. The best conceptual material on the site I have found are the Price Histogram indicator and the VOM library. Those projects are already prepared for a thorough communal enhancing - and have well documented concepts for the OO usage (at least in part)

I'm just curious why the metaquotes team have not done something similar already.  This would drastically decrease EA development time and attract more programmers
 

Well in fairness this idea was not practical in the past.

Since the platform and language itself both are not released maybe it is better to keep their heads down.

Our day will come. I will be happy to provide codes once they are proficient. I am in no position for charity at the moment, however.

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.
 

I just started out trying this, made a quick one for the MACD cross.  My programming skills aint great, but it works. 

//+------------------------------------------------------------------+
//|                                            Indicator_Actions.mqh |
//|                      
//|                                        
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, FJ Mocke"
//+------------------------------------------------------------------+

class MACD
{

public:

string   Cross_Signal(const string symbol,ENUM_TIMEFRAMES tf,int fast_EMA, int slow_EMA, int SMA, double avg_slope);
double   Signal_Avg(const string symbol,ENUM_TIMEFRAMES tf,int fast_EMA, int slow_EMA, int SMA, int bars);

  
};


//+------------------------------------------------------------------+
//| MACD Cross Signal                                                       |
//+------------------------------------------------------------------+
string MACD::Cross_Signal(const string symbol,ENUM_TIMEFRAMES tf,int fast_EMA, int slow_EMA, int SMA, double avg_slope)
{
double Signal[];
string cross;

//Calculate Cross

int MACD_Handle = iMACD(symbol,tf,fast_EMA,slow_EMA,SMA,PRICE_CLOSE);

ArraySetAsSeries(Signal,true);

if(CopyBuffer(MACD_Handle,1,0,4,Signal)<=0) {return("Error");}

if (Signal[1] > 0 && Signal[2] < 0 && Signal[0] > 0) {cross = "Up";}
if (Signal[1] < 0 && Signal[2] > 0 && Signal[0] < 0) {cross = "Down";}

//Calculate Slope

double slope = Signal[1] - Signal[2];

//Return the value of the function

if (cross == "Up" && slope > 0 && MathAbs(slope) > avg_slope ) {return("Up");}
if (cross == "Down" && slope < 0  && MathAbs(slope) > avg_slope) {return("Down");}



return("No Cross");
}



//+------------------------------------------------------------------+
//| Calculate The Average Trend of MACD Signal Line Over Certain Period|
//+------------------------------------------------------------------+
double MACD::Signal_Avg(const string symbol,ENUM_TIMEFRAMES tf,int fast_EMA, int slow_EMA, int SMA, int bars)
{
double Signal[];
double sum = 0;
int count = 0;

int MACD_Handle = iMACD(symbol,tf,fast_EMA,slow_EMA,SMA,PRICE_CLOSE);

ArraySetAsSeries(Signal,true);

if(CopyBuffer(MACD_Handle,1,0,bars,Signal)<=0) {return(0);}

for (int i =0;i<bars-1;i++) 
{
if ( Signal[i] != 0 && Signal[i+1] != 0 )
{
sum = sum + MathAbs(Signal[i] - Signal[i+1]);
count++;
}
}

return(sum/count);

}







Reason: