Oncalculate error when converting mql4 indicator to mql5

 

Hello everyone,

First of all my apologies if I am in the wrong section. Please can someone help me in converting an indicator from mql4 to mql5 ?
I am trying for weeks to convert the indicator, but I just have some basic knowledge in programming. I made some research about that topic and try all the tools and techniques that were advised but can't figure out the issue.
Whatever tool or technique I used, even using them together, I ended up with the same 3 errors:
'}' - unexpected end of program
'{' - unbalanced parentheses
OnCalculate function not found in custom indicator.

(find attached the original file and the converted one)

I was able to fix all the errors but these one are the hardest to fix.(Reminder: The indicator works perfectly on MT4.)
Thus if someone can help me or just tell me what to look for to fix that issue it will be great.
Thank you in advance.

 

Do not post code that will not compile.

bool ObjectSet(const string name, const OBJPROP_DOUBLE_BROKER &property, const double value)
{               «««« where is this terminated?
  return ObjectSetDouble(0, name, property.p, property.i, value);

vvvv where can this code ever be called?
  int adjustment = MathMod(SymbolInfoInteger(0,SYMBOL_DIGITS), 2);
   ⋮
   
   string sym = Symbol();
   {            «««« where is this terminated?
   if      (sym == prefix+"EURUSD"+suffix) root=1.2000;
   
   ArrayResize(storage, 0);

vvv what is this BS?   
  int createByLine(objectPrefix + "byline","Indicator by Akuma99, http://www.beginnertrader.com", 8, 2, 5, 10);

   Comment("\n© Copyright, 2006-2009, Lewis Evans\nhttp://www.leftbraintrading.com");
         
   return(0);}  «««« this closing bracket is from where?
??? where is the other closing bracket?   
   
int OnInit()
⋮
 

William Roeder

Thanks a lot for your quick reply. You are totally right in your comments.When I was trying to fix the issue I was asking myself the same questions.Well I am a bit confused now as I don't know how to raise my issue.
In summary, I got the indicator compiling fine on MT4 editor. As I want to use it on MT5 I used a script to convert it.But the author of the script mentioned that some errors needed to be fixed after the compilation and he provided a MQL4 to MQL5 porting table (ver. 0.2 coded by fai.).Unfortunately that porting table wasn't enough as I ended with 41 errors after fixing them with the porting table.Then I used some other portions of codes suggested by other forums to get a rid of these errors and ended up with the 3 errors, I mentioned in my previous post. That is why the code seems to be a nonsense.For instance when I terminate the functions you mentioned, I get more and more errors.
Below is the code right after the conversion. I left it untouched so that you can see the errors which drive me crazy for weeks and led me to nowhere. :)
Sorry if it seems to be obvious as I am new to MQL programming.Once again thank you for trying to help.   



#property indicator_chart_window


//:::::::::::::::::::::::::::::::::::::::::::::
#include <mt4accountinfo.mqh>
#include <mt4string.mqh>
#include <mt4datetime.mqh>
#include <mt4objects_1.mqh>
#include <mt4timeseries_2.mqh>
//Etc.
//:::::::::::::::::::::::::::::::::::::::::::::::

input string     suffix = "";
input string     prefix = "";
input int        MN1_fib_number=1000;
input int        W1_fib_number=1000;
input int        D1_fib_number=1000;
input int        H4_fib_number=382;
input int        H1_fib_number=382;
input int        M30_fib_number=236;
input int        M15_fib_number=146;
input int        M5_fib_number=90;
input int        M1_fib_number=56;
input bool       showStickies=true;
input int        minStickies=1;
input double     stickyPercentBuffer=0.1;
input int        sets=5;
input int        labelOffset=15;
input bool       labelOnLeft=false;
input bool       showID=true;
input color      frameworkColor=LimeGreen;
input color      weakLineColor=Purple;
input color      subBaselineColor=DeepSkyBlue;
input color      stickyColor=Red;

string      objectPrefix = "lbt";
bool        drawn = false;
double      base = 0, root = 0;
int         fibNumber, trimNumber;
double      storage[];
int         basePeriod;
int         nums[6] = {56,90,146,236,382,1000};
double      fibs[8] = {0.146,0.236,0.382,0.50,0.618,0.764,0.854,1};
double      compareFibs[8] = {14.6,23.6,38.2,50,61.8,76.4,85.4,100};
string      labels[8] = {"146","236","382","50","618","764","854","1000"};
int         subStyles[7] = {0,0,2,2,2,0,0};
double      multiple = 1;

int OnInit()
{
  //:::::::::::::::::::::::::::::::::::::::::::::
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  int Bars=Bars(Symbol(),PERIOD_CURRENT);
  double Point=Point();
  //Etc.
  //:::::::::::::::::::::::::::::::::::::::::::::::
  
   int adjustment = MathMod(MarketInfo(Symbol(),MODE_DIGITS), 2);
   if (adjustment == 0) {
      adjustment = 1;
   } else {
      adjustment = 10;
   }
      
   multiple = Point * adjustment;
   
   drawn = false;
   trimNumber = MarketInfo(Symbol(),MODE_DIGITS);
   basePeriod = Period()*60;
   
   string sym = Symbol();
   
   if (sym == prefix+"EURUSD"+suffix)      root=1.2000;
   else if (sym == prefix+"USDCHF"+suffix) root=1.2000;
   else if (sym == prefix+"USDCAD"+suffix) root=1.2000;
   else if (sym == prefix+"GBPUSD"+suffix) root=2.0000;
   else if (sym == prefix+"GBPCHF"+suffix) root=2.0000;
   else if (sym == prefix+"EURAUD"+suffix) root=2.0000;
   else if (sym == prefix+"USDJPY"+suffix) root=100.00;
   else if (sym == prefix+"AUDJPY"+suffix) root=100.00;
   else if (sym == prefix+"CHFJPY"+suffix) root=100.00;
   else if (sym == prefix+"CADJPY"+suffix) root=100.00;
   else if (sym == prefix+"NZDJPY"+suffix) root=100.00;
   else if (sym == prefix+"EURJPY"+suffix) root=120.00;
   else if (sym == prefix+"GBPJPY"+suffix) root=200.00;
   else if (sym == prefix+"USDCNY"+suffix) root=8.0000;
   else if (sym == prefix+"EURCHF"+suffix) root=1.5000;
   else if (sym == prefix+"AUDUSD"+suffix) root=1.0000;
   else if (sym == prefix+"EURGBP"+suffix) root=1.0000;
   else if (sym == prefix+"AUDCAD"+suffix) root=1.0000;
   else if (sym == prefix+"NZDUSD"+suffix) root=0.5000;
   else if (sym == prefix+"AUDNZD"+suffix) root=1.0000;
   
   ArrayResize(storage, 0);
   
   createByLine(objectPrefix + "byline","Indicator by Akuma99, http://www.beginnertrader.com", 8, 2, 5, 10);
   Comment("\n© Copyright, 2006-2009, Lewis Evans\nhttp://www.leftbraintrading.com");
         
   return(0);
}

int OnDeinit()
{
  //:::::::::::::::::::::::::::::::::::::::::::::
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  int Bars=Bars(Symbol(),PERIOD_CURRENT);
  double Point=Point();
  //Etc.
  //:::::::::::::::::::::::::::::::::::::::::::::::
  
   drawn = false;
   clearScreen(objectPrefix, true, NULL);
   return(0);
}

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[])
{
  //:::::::::::::::::::::::::::::::::::::::::::::
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  int Bars=Bars(Symbol(),PERIOD_CURRENT);
  double Point=Point();
  //Etc.
  //:::::::::::::::::::::::::::::::::::::::::::::::

   if (!drawn) {
      
      clearStorage();
      
      // find which fib set we are drawing
      
      switch (Period()) {
         case PERIOD_W1:
            fibNumber = MN1_fib_number; break;
         case PERIOD_MN1:
            fibNumber = W1_fib_number; break;
         case PERIOD_D1:
            fibNumber = D1_fib_number; break;
         case PERIOD_H4:
            fibNumber = H4_fib_number; break;
         case PERIOD_H1:
            fibNumber = H1_fib_number; break;
         case PERIOD_M30:
            fibNumber = M30_fib_number; break;
         case PERIOD_M15:
            fibNumber = M15_fib_number; break;
         case PERIOD_M5:
            fibNumber = M5_fib_number; break;
         case PERIOD_M1:
            fibNumber = M1_fib_number; break;
      }
      
      if (showID) createID(objectPrefix + "id_label", fibNumber, 28, 4, 5, 55);
      
      // find the closest baseline to start from
      base = findBaseline(root, Close[0], fibNumber);
      
      int i, l = sets * 2, stickyCount;
      double baseVal;
      double subVal;
      string subLabel;
      color subColor;
      int subStyle;
      
      for (i=-l; i<l; i++) {
         
         baseVal = base + ((fibNumber * i) * multiple);
            
         int j, lj=ArraySize(fibs);
         
         for (j=0; j < lj; j++) {
           
            subVal = baseVal + ((fibNumber * fibs[j]) * multiple);
            subLabel = DoubleToString(fibs[j] * 100,1);
            
            switch (j) {
               case 0:
               subColor = weakLineColor; break;
               case 1:
               subColor = frameworkColor; break;
               case 5:
               subColor = frameworkColor; break;
               case 6:
               subColor = weakLineColor; break;
               case 7:
               storeOtherValues(baseVal);
               subColor = subBaselineColor; break;
               default:
               subColor = frameworkColor; break;
            }
            
            subStyle = subStyles[j];
            
            string linename = objectPrefix + "-" + labels[j] + i;
            drawHorizontalLine(linename, subVal, 1, subColor, subStyle, false);
            
            stickyCount = findStickies(subVal, fibNumber, linename);
            
            string stickyLabel; 
            
            if (showStickies && stickyCount >= minStickies) {
               ObjectSet(objectPrefix + labels[j] + i, OBJPROP_COLOR, stickyColor);
               stickyLabel = " [" + IntegerToStr(stickyCount) + "]";
            } else {
               stickyLabel = "";
            }
            
            if (labelOnLeft) {
               drawLabel(objectPrefix+labels[j] + i, subLabel + "% (" + DoubleToString(subVal,trimNumber)+")" + stickyLabel, 8, "Tahoma", Gray, Time[0], subVal);
            } else {
               drawLabel(objectPrefix+labels[j] + "_label" + i, subLabel + "% (" + DoubleToString(subVal,trimNumber)+")" + stickyLabel, 8, "Tahoma", Gray, Time[0]+basePeriod*labelOffset, subVal);
            }
         
         }
         
      }
      
      drawn = true;
      
   } else {
       
      if (!labelOnLeft) {
      
         l = sets * 2;
         lj = ArraySize(fibs);
         
         for (i=-l; i<l; i++) {
            for (j=0; j<lj; j++) {
               ObjectSet(objectPrefix + labels[j] + "_label" + i, OBJPROP_TIME1, Time[0] + basePeriod * labelOffset);
            }
         }
      }
         
   }
   
   return(rates_total);
}

void storeOtherValues(double start)
{
   addStorage(start);   
}

bool addStorage (double val)
{
   ArrayResize(storage,ArraySize(storage) + 1);
   storage[ArraySize(storage) - 1] = val;
   if (storage[ArraySize(storage) - 1] == val) return (true);
   return(false);
}

void clearStorage ()
{
   ArrayResize(storage,0);
}

int findStickies (double val, int fib_number, string linename)
{
   // nums, fibs
   int i, l = ArraySize(nums), count = 0, fib;
   int j, jl = ArraySize(compareFibs);
   double closestBase, gap, ratio;
   string history;
   
   for (i = 0; i < l; i++) {
      
      fib = nums[i];
      
      if (fib != fib_number) {
         closestBase = findBaseline(root, val, fib);         
         gap = MathAbs(val - closestBase);
         ratio = (gap / (fib * multiple)) * 100;
         
         for (j=0; j < jl; j++) {
            double compare = compareFibs[j];
            
            if (ratio < compare + stickyPercentBuffer && ratio > compare - stickyPercentBuffer) {
              if (StringLen(history) > 0) {
                  history = history + ", " + IntegerToStr(fib) + " | " + DoubleToString(100 - compare, 1) + "%";
              } else {
                  history = history + IntegerToStr(fib) + " | " + DoubleToString(100 - compare, 1) + "%";
              }
               count++;
            }
         }
      }
   }
   
   if (count >= minStickies && showStickies) {
      ObjectSet(linename,OBJPROP_COLOR,stickyColor);
      clone(linename, "[" + history +"]" + " " + linename);
      ObjectDelete(linename);
   }
   
   return (count);
}

double findBaseline (double base, double comparePrice, int fib_number) 
{ 
   double diff, extra;
   
   // find the difference between the current price and the baselines above
   diff = (comparePrice - base);
   
   // if price is more than one set away, adjust base closer (for performance improvement)
   if (MathAbs(diff) > (fib_number * multiple)) { 
      
      extra = MathMod(diff / multiple, fib_number) * multiple;
      
      base = base + (diff - extra);
   }
   
   return (base);
}

void clone(string name, string cloneName)
{
   int type = ObjectType(name);
   datetime time1, time2;
   double price1, price2;
   color objectColor;
   int style, width, arrowCode, fontSize;
   bool background;
   switch (type) {
      case OBJ_HLINE:
      price1 = ObjectGet(name, OBJPROP_PRICE1);
      objectColor = ObjectGet(name, OBJPROP_COLOR);
      style = ObjectGet(name, OBJPROP_STYLE);
      width = ObjectGet(name, OBJPROP_WIDTH);
      background = ObjectGet(name, OBJPROP_BACK);
      drawHorizontalLine(cloneName, price1, width, objectColor, style, background);
      break;
  }
}

int createID(string name, string txt, int fontSize, int corner, int xoff, int yoff) 
{
   ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
   ObjectSet(name, OBJPROP_CORNER, corner);
   ObjectSet(name, OBJPROP_XDISTANCE, xoff);
   ObjectSet(name, OBJPROP_YDISTANCE, yoff);
   ObjectSet(name, OBJPROP_BACK, true);
   ObjectSetText(name,txt,fontSize,"Arial",Gray);
   
}

int createByLine(string name, string txt, int fontSize, int corner, int xoff, int yoff) 
{
   ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
   ObjectSet(name, OBJPROP_CORNER, corner);
   ObjectSet(name, OBJPROP_XDISTANCE, xoff);
   ObjectSet(name, OBJPROP_YDISTANCE, yoff);
   ObjectSet(name, OBJPROP_BACK, true);
   ObjectSetText(name,txt,fontSize,"Arial",Gray);
   
}

void drawHorizontalLine(string name, double price, int thickness, color colour, int style, bool background) 
{
   if (ObjectFind(name) != 0) { // if line does not already exist draw a new line
      ObjectCreate(name, OBJ_HLINE, 0, 0, price);
   } else { // if line already exists, just move the existing line
      ObjectSet(name, OBJPROP_PRICE1, price);
   }
   
   ObjectSet(name,OBJPROP_COLOR, colour);
   ObjectSet(name,OBJPROP_WIDTH, thickness);
   ObjectSet(name, OBJPROP_BACK, background);
   ObjectSet(name, OBJPROP_STYLE, style);
}

void drawLabel(string name, string txt, int fontSize, string font, color colour, int time, double price) 
{
   if (ObjectFind(name) < 0) {
      ObjectCreate(name, OBJ_TEXT, 0, time, price);
   } else {
      if (ObjectType(name) == OBJ_TEXT) {
         ObjectSet(name, OBJPROP_TIME1, time);
         ObjectSet(name, OBJPROP_PRICE1, price);
      }
   }
   
   ObjectSetText(name,txt,fontSize,font,colour);
   ObjectSet(name,OBJPROP_FONTSIZE, fontSize);
}

void clearScreen(string prefix, bool clearComments, string exception)
{   
   if (clearComments) Comment("");
   
   int objectstotal = ObjectsTotal(); 
   string name = "";

   for (int i = objectstotal; i >= 0; i--) {
     
     name = ObjectName(i);
     
     if (StringFind(name,prefix,0) > -1) ObjectDelete(name); 
     
   }
}

string IntegerToStr(int number)
{
   return(DoubleToString(number,0));
} 



 
It might be a useful indicator to some extent.
 
Nagisa Unada:
It might be a useful indicator to some extent.

Nagisa Unada,

Thank you for your help. Will check it. Thanks :)

 

Nagisa Unada,

Wow, the indicator runs perfectly. I am really grateful to you.

I think that there is no way for me to have been able to find some lines you added or modified. I was still trying but ended with a the indicator just showing up the name of the the author and the indicator after compiling it successfully.

So thank you one more time for your help.Really appreciate.

 

You're welcome.

There was an oversight in OnInit(). Download it again.