Debugging a MT4 MTF ichimoku converted to MT5

 

Hello there,

As I am a newbie in mql coding ... is there anyone to help debugging this code from 31 errors ? 

It's a public & free indicator & have to stay free for MT5 so ... just avoid the "post in the jobs" ;)

#property copyright "www,forex-tsd.com"
#property link      "www,forex-tsd.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  LimeGreen
#property indicator_color2  Red
#property indicator_width1  3
#property indicator_width2  3
#property indicator_minimum 0
#property indicator_maximum 1

//
//
//
//
//

input string TimeFrame       = "Current time frame";
input int    Tenkan          = 9;
input int    Kijun           = 26;

input bool   alertsOn        = true;
input bool   alertsOnCurrent = false;
input bool   alertsMessage   = true;
input bool   alertsSound     = false;
input bool   alertsEmail     = false;
input string soundfile       = "alert2.wav"; 

//
//
//
//
//

double UpH[];
double DnH[]; 
double Tenkan_Buffer[];
double Kijun_Buffer[];
double trend[];

//
//
//
//
//

string indicatorFileName;
int    timeFrame;
bool   returnBars;
bool   calculateValue;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
     //IndicatorBuffers(5);
     SetIndexBuffer(0,UpH); SetIndexStyle(0,DRAW_HISTOGRAM);
     SetIndexBuffer(1,DnH); SetIndexStyle(1,DRAW_HISTOGRAM);
     SetIndexBuffer(2,Tenkan_Buffer);
     SetIndexBuffer(3,Kijun_Buffer);  
     SetIndexBuffer(4,trend); 
     
      //
      //
      // 
      //
      //
      
      indicatorFileName = WindowExpertName();
      calculateValue    = (TimeFrame=="calculateValue"); if (calculateValue) return(0);
      returnBars        = (TimeFrame=="returnBars");     if (returnBars)     return(0);
      timeFrame         = stringToTimeFrame(TimeFrame);
      
      //
      //
      //
      //
      //
       
    IndicatorShortName(timeFrameToString(timeFrame)+"  Tenkan Sen-Kijun Sen Histo");
   return(0);
}

//
//
//
//
//

int deinit() {  return(0);}

//
//
//
//                           
//
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,k,limit;
   
   
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
           limit = MathMin(Bars-counted_bars,Bars-1); 
           if (returnBars) { UpH[0] = limit+1; return(0); }

   //
   //
   //
   //
   //
   
   if (calculateValue || timeFrame==Period())
   {
     for (i=limit; i>=0; i--)
     {
       
       double thi    = High[i];
       double tlo    = Low[i];
       double tprice = 0;
       if (i >= Bars - Tenkan) continue;
       for(k = 0; k < Tenkan; k++)
       {
           tprice = High[i+k];
           if(thi < tprice)  thi = tprice;
         
           tprice = Low[i+k];
           if(tlo  > tprice) tlo = tprice;
       }
       
       if ((thi+tlo) > 0.0) 
            Tenkan_Buffer[i] = (thi + tlo)/2; 
       else Tenkan_Buffer[i] = 0;
       
       //
       //
       //
       //
       //
       
       double khi    = High[i];
       double klo    = Low[i];
       double kprice = 0;
       if  (i >= Bars - Kijun) continue;
       for (k = 0; k < Kijun; k++)
       {
          kprice = High[i+k];
          if(khi < kprice)  khi  = kprice;
         
          kprice = Low[i+k];
          if(klo  > kprice) klo  = kprice;
       }
        
       if ((khi+klo) > 0.0) 
            Kijun_Buffer[i] = (khi + klo)/2; 
       else Kijun_Buffer[i] = 0;
       
       //
       //
       //
       //
       //
       
       UpH[i]   = EMPTY_VALUE;
       DnH[i]   = EMPTY_VALUE;
       trend[i] = trend[i+1]; 

            if (Tenkan_Buffer[i] > Kijun_Buffer[i]) trend[i] =  1;
       if (Tenkan_Buffer[i] < Kijun_Buffer[i]) trend[i] = -1;
       if (trend[i] == 1) UpH[i] = 1;
       if (trend[i] ==-1) DnH[i] = 1;
      }
      manageAlerts();
      return(0);
   }
      
   //
   //
   //
   //
   //
   
   limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
   for (i=limit;i>=0; i--)
   {
      int y = iBarShift(NULL,timeFrame,Time[i]);
         trend[i]  = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",Tenkan,Kijun,4,y);
         UpH[i]    = EMPTY_VALUE;
         DnH[i]    = EMPTY_VALUE;
         
         if (trend[i] == 1) UpH[i] = 1;
         if (trend[i] ==-1) DnH[i] = 1;
   }
   manageAlerts();  
   return(0);         
}


//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}

//
//
//
//
//

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//
//
//
//
//

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int char = StringGetCharacter(s, length);
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                     s = StringSetCharacter(s, length, char - 32);
         else if(char > -33 && char < 0)
                     s = StringSetCharacter(s, length, char + 224);
   }
   return(s);
}

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//
//

void manageAlerts()
{
   if (! calculateValue && alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1; whichBar = iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar));
      if (trend[whichBar] != trend[whichBar+1])
      {
         if (trend[whichBar] == 1) doAlert(whichBar,"buy");
         if (trend[whichBar] ==-1) doAlert(whichBar,"sell");
      }         
   }
}   

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message =  StringConcatenate(_Symbol," at ",TimeToString(TimeLocal(),TIME_SECONDS)," - ",timeFrameToString(timeFrame)+" Tenkan Sen-Kijun Sen ",doWhat);
          if (alertsMessage) Alert(message);
          if (alertsEmail)   SendMail(StringConcatenate(_Symbol," Tenkan Sen-Kijun Sen "),message);
          if (alertsSound)   PlaySound("alert2.wav");
   }
}     
   
  
  
//********************************************  Emulation *******************************************
double Ask;
double Bid;
double Bars;
double Open[];
double Close[];
double High[];
double Low[];
datetime Time[];
long Volume[];

void Set_Values_to_variables()
{
   MqlTick last_tick;
   SymbolInfoTick(_Symbol,last_tick);
   Ask=last_tick.ask;
   Bid=last_tick.bid;
  
   ArraySetAsSeries(Close,true);
   CopyClose(_Symbol,_Period,0,Bars(_Symbol,_Period),Close);
   ArraySetAsSeries(Open,true);
   CopyOpen(_Symbol,_Period,0,Bars(_Symbol,_Period),Open);
   ArraySetAsSeries(Low,true);
   CopyLow(_Symbol,_Period,0,Bars(_Symbol,_Period),Low);
   ArraySetAsSeries(High,true);
   CopyHigh(_Symbol,_Period,0,Bars(_Symbol,_Period),High);
   ArraySetAsSeries(Time,true);
   CopyTime(_Symbol,_Period,0,Bars(_Symbol,_Period),Time);
   ArraySetAsSeries(Volume,true);
   CopyTickVolume(_Symbol,_Period,0,Bars(_Symbol,_Period),Volume);
} 
void OnTick()
{
        Set_Values_to_variables();
}
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[])     
{
        Set_Values_to_variables();
}
void OnInit()
{
        Set_Values_to_variables();
        init();
}
void OnDeinit()
{
        deinit();
}
ENUM_TIMEFRAMES TFMigrate(int tf)
{
   switch(tf)
   {
      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);
      
      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);      
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);      

      default: return(PERIOD_CURRENT);
   }
}
 
blouf:

Hello there,

As I am a newbie in mql coding ... is there anyone to help debugging this code from 31 errors ? 

It's a public & free indicator & have to stay free for MT5 so ... just avoid the "post in the jobs" ;)

You haven't converted anything,  you have just bolted some rubbish on to the end . . .  where is your "emulation" of iBarShift() ?  where is your "emulation" of IndicatorCounted() ?

Use the Jobs section and specify that the source code must be provided and that it will be open source . . .
 
See this article Migrating from mql4 to mql5 and...
Transferring Indicators from MQL4 to MQL5
Transferring Indicators from MQL4 to MQL5
  • 2010.07.28
  • Vasily
  • www.mql5.com
This article is dedicated to peculiarities of transferring price constructions written in MQL4 to MQL5. To make the process of transferring indicator calculations from MQL4 to MQL5 easier, the mql4_2_mql5.mqh library of functions is suggested. Its usage is described on the basis of transferring of the MACD, Stochastic and RSI indicators.
 
@RaptorUK : May you ? (no open source in the jobs section)
 
blouf:
@RaptorUK : May you ? (no open source in the jobs section)
May I what ?   write your code for you ?  nope,  sorry, I don't have time and my mql5 is rusty to say the least . . .  as I said use the Jobs section and make it a condition that the code will be open source . . .  is it just that you don't want to pay ? 
 
It's not. Open source is open source. I was mostly wondering if I had to ask author permissions before using his codes.
 
blouf:
It's not. Open source is open source. I was mostly wondering if I had to ask author permissions before using his codes.

Open source doesn't mean free.

The code you posted is copyrighted, it's not really the same as open source.

Reason: