Download MetaTrader 5

How to call OnCalculate() function at a specific timing

To add comments, please log in or register
Publish your article and get a reward!
stitchtrader
133
stitchtrader 2013.07.16 08:46 
Hello Guys!

The OnCalculate() function is called when a new tick is received.
Is it possible to call it at a specific timing?

Example:

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[])
  {
            //
  }
void OnChartEvent(const int id,
                  const long& lparam,
                  const double& dparam,
                  const string& sparam
                  )
  {
     if(id==CHARTEVENT_CHART_CHANGE)
     {
          //Call OnCalculate() again here
     }
  }

 

 

 


Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
Language Basics / Functions / Event Handling Functions - Documentation on MQL5
Alain Verleyen
Moderator
30724
Alain Verleyen 2013.07.16 09:20  
stitchtrader:
Hello Guys!

The OnCalculate() function is called when a new tick is received.
Is it possible to call it at a specific timing?

...

No you can't. Why do you need that, maybe there is a workaround.
stitchtrader
133
stitchtrader 2013.07.16 10:03  
angevoyageur:
No you can't. Why do you need that, maybe there is a workaround.
Hi Alain! Thank you xx :)

I got it.
I need that because to modify the objects size and location when the chart size changes.
And time[], open[], high[], low[] and close[] arrays are necessary.

Maybe I should work around to make arrays with like CopyTime function et cetera?

 

Alain Verleyen
Moderator
30724
Alain Verleyen 2013.07.16 10:22  
stitchtrader:
Hi Alain! Thank you xx :)

I got it.
I need that because to modify the objects size and location when the chart size changes.
And time[], open[], high[], low[] and close[] arrays are necessary.

Maybe I should work around to make arrays with like CopyTime function et cetera?

 

Yes you are right, the best way is to use CopyXXXX functions in the OnChartEvent().

Another solution would be to set a flag when OnChartEvent() is raised and to process your objects in OnCalculate() but that would be on the next tick.

stitchtrader
133
stitchtrader 2013.07.16 10:34  
angevoyageur:

Yes you are right, the best way is to use CopyXXXX functions in the OnChartEvent().

Another solution would be to set a flag when OnChartEvent() is raised and to process your objects in OnCalculate() but that would be on the next tick.

Thank you Alain!  I'll try that.

Have a nice day ♫

To add comments, please log in or register