Metatrader crashes - custom indicator

 

hi 

i'm going crazy, so i'm asking for your help.. maybe i need some fresh eyes..

i'm tryng to create a custom indicator, based on a MT4 indicator -already on my Indicators folder- but when i select it when my metatrader is running, the sistem crahes and i need to restart it. 

i'm leaving here the mql4 code, maybe you can see some errors that i can't see... 


//+------------------------------------------------------------------+
//|                                             Indicator: GIBBI.mq4 |
//+------------------------------------------------------------------+
#property copyright "moon corp."
#property version   "1.00"
#property description ""


//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 5
#property indicator_color1 clrRed
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 5
#property indicator_color2 clrLime
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

datetime time_alert; //used when sending alert
bool Audible_Alerts = true;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | GIBBI @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 242);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 241);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| 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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
     
      //Indicator Buffer 1
      if(iCustom(NULL, 0, "GbbiDouble3.0", true, 0, 0, 0, 0, 0, 0, 0, 0, 0)  //GbbiDouble3.0 is not equal to fixed value
      )
        {
         
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(iCustom(NULL, 0, "GbbiDouble3.0", 0, true, 0, 0, 0, 0, 0, 0, 0, 0)  //GbbiDouble3.0 is not equal to fixed value
      )
        {
         
        }
      else
        {
         Buffer2[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

thanks a lot for your help, 

Rob

 

So maybe your problem is from your new MT4:

https://www.mql5.com/en/forum/320299

New MT4 build 1184 error
New MT4 build 1184 error
  • 2019.08.17
  • www.mql5.com
There is a new MT 4 build that is forced upon us (/skipupdate does not work - as usual) Once when you allow it - whatever you compile, it will not...
 
  1. if(iCustom(NULL, 0, "GbbiDouble3.0", true, 0, 0, 0, 0, 0, 0, 0, 0, 0)  //GbbiDouble3.0 is not equal to fixed value
    
    Why are you setting all bars to the same value?
  2. Does your indicator actually return zero? If not, your double to bool conversion is bogus.
  3. Without seeing the indicator, we can only guess if the call is correct.
    You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 programming forum


 

@Mehrad Jeddi, thanks for your idea... 

i just checked, and i have the 1170 build; i don't know if this is the problem, because i don't get any error message, but the mt4 just crashes. 

do you have any other idea?

tnks, 

rob

 
missroby:

@Mehrad Jeddi, thanks for your idea... 

i just checked, and i have the 1170 build; i don't know if this is the problem, because i don't get any error message, but the mt4 just crashes. 

do you have any other idea?

tnks, 

rob

So in this case i dont have any idea,because we dont know return value of the custom indicator,

By syntax everything seems correct.

So if you want to get other bar buffer value,you should set "i" loop variable as the icustom shift bar.

 
      //Indicator Buffer 1
      if(iCustom(NULL, 0, "GbbiDouble3.0", true, 0, 0, 0, 0, 0, 0, 0, 0, 0)  //GbbiDouble3.0 is not equal to fixed value
      )
        {
          //What do you have here?????????
        }
      else
        {
         Buffer1[i] = 0;
        }

Are you showing the complete code?

 
Keith Watford:

Are you showing the complete code?

hi,

yes, it is the complete code

 
missroby:

hi,

yes, it is the complete code

Then I can see nothing that will crash the terminal. Maybe you should look at what other indicators/EAs you have running.

 
Usual stuff : wrong parameters (or parameters types) in the iCustom() call
 
Mladen Rakic:
Usual stuff : wrong parameters (or parameters types) in the iCustom() call


Hi mladen, what is wrong with those parameters?

I just followed the instructions Of the iCustom function founded on this website...

please if you could clarify, it would be really helpful.. 

Thanks 

rob 

 
missroby:


Hi mladen, what is wrong with those parameters?

I just followed the instructions Of the iCustom function founded on this website...

please if you could clarify, it would be really helpful.. 

Thanks 

rob 

Apart from a fact that I have never saw an indicator expecting all zeroes (0) as parameter inputs (placing 0 does not mean to use default for the parameter, but to use 0), check this part of that description in the documentation _ https://www.mql5.com/en/docs/indicators/icustom:

[in] input-parameters of a custom indicator, separated by commas. Type and order of parameters must match. If there is no parameters specified, then default values will be used.

Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
[in]  The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/ [in] input-parameters of a custom indicator, separated by commas. Type and order of parameters must match. If there is no parameters specified, then...