Download MetaTrader 5

Calculating SMA for strategies

To add comments, please log in or register
Add our Twitter channel to friends and follow the news!
andrew.potter77
54
andrew.potter77 2011.09.18 04:30 

hello the Moving Average file includes this function:

double SimpleMA(const int position,const int period,const double &price[])

  {

//---

   double result=0.0;

//--- check position

   if(position>=period && period>0)

     {

      //--- calculate value

      for(int i=0;i<period;i++) result+=price[position-i];

      result/=period;

     }

//---

   return(result);

  } 

 

What price array should I pass to the function when calculating on a Symbol?  Thanks 

Ge Senlin
1355
Ge Senlin 2011.09.18 04:59  

Generaly,it should be close[].

andrew.potter77
54
andrew.potter77 2011.09.18 18:44  
thanks
andrew.potter77
54
andrew.potter77 2011.09.19 06:25  

I have had difficulty in passing the array. 


here is my code in the main program:


double close_fast[50],close_slow[100],close_veryslow[150];


 CopyClose(_Symbol,PERIOD_D1,0,FastEntry,close_fast);


  double FastEntryMA=SimpleMA(0, 50,close_fast);


the error i get is

2011.09.18 19:25:30    Core 2    2011.05.02 00:00:00   Array out of range in 'MovingAverages.mqh' (19,12)

Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
MQL5 programs / Runtime Errors - Documentation on MQL5
Ge Senlin
1355
Ge Senlin 2011.09.19 06:46  


double close_fast[50],close_slow[100],close_veryslow[150];

>>Modified to: 

double close_fast[],close_slow[],close_veryslow[];

To add comments, please log in or register