Download MetaTrader 5

iClose return 0 ???

To add comments, please log in or register
stanislass
87
stanislass  
On my Pc W7 pro this code runs without problem.
On a VPS W2008R2 it causes a "zero divide".
Even broker, account different.

How would it be possible that "iClose (pair [i], FastUnit, FastNumb-1" return zero?


#property copyright "Copyright 2015, JLF"
#property link      "https://www.rototo.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


input ENUM_TIMEFRAMES FastUnit=1;
extern int FastNumb = 120;

double vari[28];

string pair[28]={"EURGBP","EURAUD","EURNZD","EURUSD","EURCAD","EURCHF","EURJPY", 
                 "GBPAUD","GBPNZD","GBPUSD","GBPCAD","GBPCHF","GBPJPY",
                 "AUDNZD","AUDUSD","AUDCAD","AUDCHF","AUDJPY",
                 "NZDUSD","NZDCAD","NZDCHF","NZDJPY",
                 "USDCAD","USDCHF","USDJPY",
                 "CADCHF","CADJPY",
                 "CHFJPY"};
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   EventSetTimer(5);
   return(INIT_SUCCEEDED);
  }
  
//---------------------------------  
  
void OnDeinit(const int reason)
  {
   
  }  
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 value of prev_calculated for next call
   return(rates_total);
   }
//+------------------------------------------------------------------+

void OnTimer()
   {
   for(int i =0;i <=27; i++)
      {
      RefreshRates();
      vari[i]=((iClose(pair[i],FastUnit,0)/iClose(pair[i],FastUnit,FastNumb-1))-1)*10000;
      }
...


  


whroeder1
15923
whroeder1  
stanislass: How would it be possible that "iClose (pair [i], FastUnit, FastNumb-1" return zero?
   for(int i =0;i <=27; i++){
      RefreshRates();
      vari[i]=((iClose(pair[i],FastUnit,0)/iClose(pair[i],FastUnit,FastNumb-1))-1)*10000;
    }
  1. You must handle 4066/4073 errors. See Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
  2. No need for the RefreshRates. That only updates:

    Refreshing of data in pre-defined variables and series arrays.

    RefreshRates - Timeseries and Indicators Access - MQL4 Reference

    Predefined variables are: _Digits, _LastError, _Period, _Point, _RandomSeed, _StopFlag, _Symbol, _UninitReason, Ask, Bars, Bid, Close[], Digits, High[], Low[], Open[], Point, Time[], Volume[]

    Predefined Variables - MQL4 Reference

    Also updates: Hour, Minute, and Seconds

    Minute() returns wrong values - or am I wrong? - MQL4 and MetaTrader 4 - MQL4 programming forum

    You aren't using any of them.
  3. Don't hard code numbers. If you ever change the size of pair, your code breaks. ArraySize
  4. Don't hard code numbers. Code breaks on JPY pairs and metals. If you want the value in points divide by _Point
stanislass
87
stanislass  

Yes, it's ok with the history;

thank you

Mehmet Bastem
659
Mehmet Bastem  
stanislass:
On my Pc W7 pro this code runs without problem.
On a VPS W2008R2 it causes a "zero divide".
Even broker, account different.

How would it be possible that "iClose (pair [i], FastUnit, FastNumb-1" return zero?




double abc=iClose(pair[i],FastUnit,FastNumb-1);
      if (abc==0) abc=1; 
    //  Print (i," ",pair[i]," ",iClose(pair[i],FastUnit,FastNumb-1));
      vari[i]=((iClose(pair[i],FastUnit,0)/abc)-1)*10000;
To add comments, please log in or register