Download MetaTrader 5

MQL+ OnCalculate in expert

To add comments, please log in or register
Do you have questions on how to turn your idea into reality? Ask them on the Forum!
Ex Ovo Omnia
3154
Ex Ovo Omnia 2014.01.24 12:01 

If I prefer to include indicator calculation into EA rather than the iCustom call, probably the easiest way is setting correct parameters for OnCalculate() function.

Did anyone already invest some effort into coding? I guess it should use CopyClose(), CopyHigh() etc. to create the parameter arrays, but I am not familiar with them. I found an article about inclusion of indicators, which might help.

Keith Watford
Moderator
9624
Keith Watford 2014.01.24 12:33  
I am not familiar with these functions. Are they MQL4 or 5? This is the MQL4 forum
Ex Ovo Omnia
3154
Ex Ovo Omnia 2014.01.24 12:34  
GumRai:
I am not familiar with these functions. Are they MQL4 or 5? This is the MQL4 forum

They are MQL4+. But the online documentation for it is kinda lacking, so the MQL5 links.
Alain Verleyen
Moderator
30743
Alain Verleyen 2014.01.24 12:56  
Ovo:

They are MQL4+. But the online documentation for it is kinda lacking, so the MQL5 links.
What do you want to know ? I don't understand very well your issue ?
Ex Ovo Omnia
3154
Ex Ovo Omnia 2014.01.24 13:02  
angevoyageur:
What do you want to know ? I don't understand very well your issue ?


I would like to feed the original OnCalculate method without need to modify it.
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.24 13:22  
Ovo:

I would like to feed the original OnCalculate method without need to modify it.
Isn't OnCalculate() just for Indicators ?
Ex Ovo Omnia
3154
Ex Ovo Omnia 2014.01.24 13:32  
RaptorUK:
Isn't OnCalculate() just for Indicators ?


The new script respects scopes, so the answer is yes, if implemented in the main scope, but no if anywhere else, e.g. in a class:

class MT4NewIndicator : public MT4Object {

   int prevCalculated;
   
public:
   MT4NewIndicator() :  prevCalculated(0) {
      OnInit();
   }
   
   void start() {
      CopyHigh(symbol,...
      prevCalculated = OnCalculate (rates_total,prevCalculated, time,open,high,low,close,tick_volume,volume,spread);
      ...
   }
protected:
   virtual int OnCalculate (const int rates_total,
         const int prev_calculated,
         const datetime& time[],
         const double& open[],
         const double& high[],
         const double& low[],
         const double& close[],
         const long& tick_volume[],
         const long& volume[],
         const int& spread[]) {
      return 0;
   }

   virtual int OnInit(void) {
      return 0;
   }   
};
Alain Verleyen
Moderator
30743
Alain Verleyen 2014.01.24 13:56  
Ovo:


The new script respects scopes, so the answer is yes, if implemented in the main scope, but no if anywhere else, e.g. in a class:

Yes, in this case you have to use CopyXXX function to get data for open, high, low, etc... The following article gives you equivalence between "old" mql4 and mql5/new mql4. Feel free to ask more precise question about CopyXXX.

On the other hand I don't see why you want to embed to code of indicator directly in your EA.

Ex Ovo Omnia
3154
Ex Ovo Omnia 2014.01.24 14:07  
angevoyageur:

Yes, in this case you have to use CopyXXX function to get data for open, high, low, etc... The following article gives you equivalence between "old" mql4 and mql5/new mql4. Feel free to ask more precise question about CopyXXX.

On the other hand I don't see why you want to embed to code of indicator directly in your EA.


Thanks for support. And why (besides I want to be mysterious as MQs are) - it has easy distribution, easy update, no maintenance regarding the indicator, and compatibility with the indicator forever.

Alain Verleyen
Moderator
30743
Alain Verleyen 2014.01.24 14:13  
Ovo:


Thanks for support. And why (besides I want to be mysterious as MQs are) - it has easy distribution, easy update, and compatibility with the indicator forever.

Are you aware you can embed an indicator within the ex4/ex5, as a resource ? See also this topic for some examples. I haven't tested it with the new mql4 though.
Ex Ovo Omnia
3154
Ex Ovo Omnia 2014.01.24 14:19  
angevoyageur:
Are you aware you can embed an indicator within the ex4/ex5, as a resource ? See also this topic for some examples. I haven't tested it with the new mql4 though.


Wow, I am not yet so advanced. Good clue. I have to read it later, now is the time to give a lift kids from schools.

There are a lot of features I missed...

123
To add comments, please log in or register