MQL+ OnCalculate in expert

 

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.

 
I am not familiar with these functions. Are they MQL4 or 5? This is the MQL4 forum
 
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.
 
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 ?
 
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.
 
Ovo:

I would like to feed the original OnCalculate method without need to modify it.
Isn't OnCalculate() just for Indicators ?
 
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;
   }   
};
 
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.

 
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.

 
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.
 
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...

Reason: