How to get last highest value from GARCH indicator and get reverse value ?

 

GARCH

 

 I am not a creator of Garch indicator therefore I have some problems to get some values from it. If somebody get an ideas how to get these values from it, I would be very appreciated.

I mean previous highest value of dot 1 and reverse value of dot 2,

Last lowest value of dot 3 and reverse value of dot 4. 

I think the out put value of indicator has to be "GarchNum" 

Here is the code:

//+------------------------------------------------------------------+
//|                                                        GARCH.mq4 |
//|                                              Andres Barale Sarti |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Andres Barale Sarti"
#property link      "https://www.mql5.com"
#property version   "1.20"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                       GARCH.mq4  |
//|                      Copyright © 2014, andresbarale@gmail.com    |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, andresbarale@gmail.com  "
#property link      "https://www.mql5.com"

#property indicator_separate_window
#property indicator_color1 Blue
#property indicator_width1 2
#property indicator_buffers 1
//************************************************************
// Input parameters
//************************************************************
extern int    e_type_data   = PRICE_CLOSE;
extern int    e_reverse_data   = 1;
extern double e_alpha = 0.010; 
extern double e_beta = 0.080;
//************************************************************
// Constant
//************************************************************
string INDICATOR_NAME="GARCH";
string FILENAME      ="___GARCH.mq4";
double LOG_2;
//************************************************************
// Private vars
//************************************************************
double ExtOutputBuffer[];
double ExtInputBuffer[];
int g_period_minus_1;
//+-----------------------------------------------------------------------+
//| FUNCTION : init                                                       |                                                                                                                                                                                                                                                      
//| Initialization function                                               |                                   
//| Check the user input parameters and convert them in appropriate types.|                                                                                                    
//+-----------------------------------------------------------------------+
int init() {
   if(e_type_data < PRICE_CLOSE || e_type_data > PRICE_WEIGHTED ) {
      Alert( "[ 20-ERROR  " + FILENAME + " ] input parameter \"e_type_data\" unknown (" + e_type_data + ")" );
      return( -1 );
   }
   IndicatorBuffers( 1 );
   SetIndexBuffer( 0, ExtOutputBuffer );
   SetIndexStyle( 0, DRAW_LINE, STYLE_SOLID, 2 );
//----
   return( 0 );
 }
//+------------------------------------------------------------------+
//| FUNCTION : deinit                                                |
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
  }
//+------------------------------------------------------------------+
//| FUNCTION : start                                                 |
//| This callback is fired by metatrader for each tick               |
//+------------------------------------------------------------------+
int start(){
   int counted_bars = IndicatorCounted();
   
   _computeLastNbBars();
//----
   return(0);
  }
//+================================================================================================================+
//+=== FUNCTION : _computeLastNbBars                                                                            ===+
//+===                                                                                                          ===+
//+===                                                                                                          ===+
//+=== This callback is fired by metatrader for each tick                                                       ===+
//+===                                                                                                          ===+
//+===                                                                                                          ===+
//+================================================================================================================+
//+------------------------------------------------------------------+
//| FUNCTION : _computeLastNbBars                                    |
//| This callback is fired by metatrader for each tick               |
//| In : - lastBars : these "n" last bars must be repainted          | 
//+------------------------------------------------------------------+
double tmpArray[];

void _computeLastNbBars( ) {
  int pos;
   switch( e_type_data ){
      case PRICE_CLOSE    : ArrayCopy(tmpArray,Close,0,0,WHOLE_ARRAY); _GARCH( tmpArray); break;
      case PRICE_OPEN     : ArrayCopy(tmpArray,Open,0,0,WHOLE_ARRAY);  _GARCH( tmpArray); break;
      case PRICE_HIGH     : ArrayCopy(tmpArray,High,0,0,WHOLE_ARRAY);  _GARCH( tmpArray); break;
      case PRICE_LOW      : ArrayCopy(tmpArray,Low,0,0,WHOLE_ARRAY);   _GARCH( tmpArray); break;      
      default :
         Alert( "[ 20-ERROR  " + FILENAME + " ] the imput parameter e_type_data <" + e_type_data + "> is unknown" );
     }
    
  }
//+------------------------------------------------------------------+
//| FUNCTION : _GARCH                                                |
//| Compute GARCH ARMA indicator                                     |
//| In :                                                             |                      
//|    - inputData : data array on which the computation is applied  | 
//+------------------------------------------------------------------+
void _GARCH(double &inputData[] ) {
   int    pos;
   double GarchNum;
   double residual;
   double residualSq;
   double GarchNumVar = 0.000001;
   int posData = ArraySize(inputData)-1;
//----
   for( pos=1; pos<(ArraySize(inputData)); pos++ ) {
      if(e_reverse_data == 0){
         posData = pos;
      }
      residual = inputData[posData] - inputData[posData - 1];
      residualSq = MathPow(residual, 2.0);
      GarchNumVar = e_alpha * residualSq + e_beta * GarchNumVar;
      GarchNum = MathSqrt(GarchNumVar);
      ExtOutputBuffer[posData]=GarchNum;
      posData--;
      Text
   } 
}
Files:
garch.mq4  7 kb
 

As the indicator data are stored in only one array: ExtOutputBuffer

you should find the e.g. value4 (newest bar) => ExtOutputBuffer[0], value3 (prev. bar) => ExtOutputBuffer[1], value2 => ExtOutputBuffer[n], value4 => ExtOutputBuffer[n+1];

To use garch.mq4 in an EA read about iCustom(..)

 
zerrow: how to get these values from it
Just read them, it has just one buffer. Detailed explanation of iCustom - MQL4 forum
 

Thanks, I'll try to figure it out.

 

OK. I have some coding done. But it is just to make it work without any sophisticated logic. I understand that my coding is very dirty. My question is does exist any normal debugger like in other languages to see result of functions and variables, because I cannot understand what's wrong. Please check my modified expert and ea, may be you can find  errors. Here is my indicator: 

 

 

 

 

 

 

 

 

 Here is my EA:

//+------------------------------------------------------------------+
//|                                             garch_expert_v.3.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "3.00"
#property strict
//--- input parameters
input double   GarchVar=0.001;
double GarchNum;
double indicator_call;
extern double control_line;
extern int    e_type_data   = PRICE_CLOSE;
extern int    e_reverse_data   = 1;
extern double e_alpha = 0.010; 
extern double e_beta = 0.080;
int order_send;
extern double LOTSize=0.01;
double price;
extern int stoploss = 100;
extern int takeprofit = 200;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert logic                                             |
//+------------------------------------------------------------------+
int start()
  {
indicator_call = iCustom(NULL ,0 ,"garch_mod_1",3, GarchNum);

if 
(GarchNum > 0.00001)  
  order_send = OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",0,clrGreen);
 
   if (GarchVar <0.0001)   
     OrderClose( "My order" , 0.5, Bid, 2 ); 
return 0;
  }
  
  
// errors   
string Error(int error_code)
{
string error_string;
switch(error_code)
{
case 0: error_string="Net oshibok";break;
case 1: error_string="Net oshibki, no rezul'tat neizvesten"; break;
case 2: error_string="Obshhaja oshibka"; break;
case 3: error_string="Nepravil'nye parametry"; break;
case 4: error_string="Torgovyj server zanjat"; break;
case 5: error_string="Staraja versija klientskogo terminala"; break;
case 6: error_string="Net svjazi s torgovym serverom"; break;
case 7: error_string="Nedostatochno prav"; break;
case 8: error_string="Slishkom chastye zaprosy"; break;
case 9: error_string="Nedopustimaja operacija narushajushhaja funkcionirovanie servera"; break;
case 64: error_string="Schet zablokirovan"; break;
case 65: error_string="Nepravil'nyj nomer scheta"; break;
case 128: error_string="Istek srok ozhidanija sovershenija sdelki"; break;
case 129: error_string="Nepravil'naja cena"; break;
case 130: error_string="Nepravil'nye stopy"; break;
case 131: error_string="Nepravil'nyj ob#em"; break;
case 132: error_string="Rynok zakryt"; break;
case 133: error_string="Torgovlja zapreshhena"; break; 
case 134: error_string="Nedostatochno deneg dlja sovershenija operacii"; break;
case 135: error_string="Cena izmenilas'"; break;
case 136: error_string="Net cen"; break;
case 137: error_string="Broker zanjat";break;
case 138:error_string="Novye ceny Ask="+DoubleToStr(Ask,Digits)+" Bid="+DoubleToStr(Bid,Digits); break; 
case 139: error_string="Order zablokirovan i uzhe obrabatyvaetsja"; break;
case 140: error_string="Razreshena tol'ko pokupka";break;
case 141: error_string="Slishkom mnogo zaprosov"; break;
case 145: error_string="Modifikacija zapreshhena, tak kak order slishkom blizok k rynku"; break;
case 146: error_string="Podsistema torgovli zanjata"; break;
case 147: error_string="Ispol'zovanie daty istechenija ordera zapreshheno brokerom"; break;
case 148: error_string="Kolichestvo otkrytyh i otlozhennyh orderov dostiglo predela, ustanovlennogo brokerom.";break;
case 4000: error_string="Net oshibki"; break;
case 4001: error_string="Nepravil'nyj ukazatel'funkcii"; break;
case 4002: error_string="Indeks massiva - vne diapazona"; break;
case 4003: error_string="Net pamjati dlja steka funkcij"; break;
case 4004: error_string="Perepolnenie steka posle rekursivnogo vyzova"; break;
case 4005: error_string="Na steke net pamjati dlja peredachi parametrov"; break;
case 4006: error_string="Net pamjati dlja strokovogo parametra"; break;
case 4007: error_string="Net pamjati dlja vremennoj stroki"; break;
case 4008: error_string="Neinicializirovannaja stroka"; break;
case 4009: error_string="Neinicializirovannaja stroka v massive"; break;
case 4010: error_string="Net pamjati dlja strokovogo massiva"; break;
case 4011: error_string="Slishkom dlinnaja stroka"; break;
case 4012: error_string="Ostatok ot delenija na nol'"; break;
case 4013: error_string="Delenie na nol'"; break;
case 4014: error_string="Neizvestnaja komanda"; break;
case 4015: error_string="Nepravil'nyj perehod"; break;
case 4016: error_string="Neinicializirovannyj massiv"; break;
case 4017: error_string="Vyzovy DLL ne razresheny"; break;
case 4018: error_string="Nevozmozhno zagruzit' biblioteku"; break;
case 4019: error_string="Nevozmozhno vyzvat' funkciju"; break;
case 4020: error_string="Vyzovy vneshnih bibliotechnyh funkcij ne razresheny"; break;
case 4021: error_string="Nedostatochno pamjati dlja stroki, vozvrashhaemoj iz funkcii"; break;
case 4022: error_string="Sistema zanjata"; break;
case 4050: error_string="Nepravil'noe kolichestvo parametrov funkcii"; break;
case 4051: error_string="Nedopustimoe znachenie parametra funkcii"; break;
case 4052: error_string="Vnutrennjaja oshibka strokovoj funkcii"; break;
case 4053: error_string="Oshibka massiva"; break;
case 4054: error_string="Nepravil'noe ispol'zovanie massiva-tajmserii"; break;
case 4055: error_string="Oshibka pol'zovatel'skogo indikatora"; break;
case 4056: error_string="Massivy nesovmestimy"; break;
case 4057: error_string="Oshibka obrabotki global'nyeh peremennyh"; break;
case 4058: error_string="Global'naja peremennaja ne obnaruzhena"; break;
case 4059: error_string="Funkcija ne razreshena v testovom rezhime"; break;
case 4060: error_string="Funkcija ne razreshena"; break;
case 4061: error_string="Oshibka otpravki pochty"; break;
case 4062: error_string="Ozhidaetsja parametr tipa string"; break;
case 4063: error_string="Ozhidaetsja parametr tipa integer"; break;
case 4064: error_string="Ozhidaetsja parametr tipa double"; break;
case 4065: error_string="V kachestve parametra ozhidaetsja massiv"; break;
case 4066: error_string="Zaproshennye istoricheskie dannye v sostojanii obnovlenija"; break;
case 4067: error_string="Oshibka pri vypolnenii torgovoj operacii"; break;
case 4099: error_string="Konec fajla"; break;
case 4100: error_string="Oshibka pri rabote s fajlom"; break;
case 4101: error_string="Nepravil'noe imja fajla"; break;
case 4102: error_string="Slishkom mnogo otkrytyh fajlov"; break;
case 4103: error_string="Nevozmozhno otkryt' fajl"; break;
case 4104: error_string="Nesovmestimyj rezhim dostupa k fajlu"; break;
case 4105: error_string="Ni odin order ne vybran"; break;
case 4106: error_string="Neizvestnyj simvol"; break;
case 4107: error_string="Nepravil'nyj parametr ceny dlja torgovoj funkcii"; break;
case 4108: error_string="Nevernyj nomer tiketa"; break;
case 4109: error_string="Torgovlja ne razreshena.Neobhodimo vkljuchit' opciju Razreshit' sovetniku torgovat' v svojstvah jeksperta."; break;
case 4110: error_string="Dlinnye pozicii ne razresheny. Neobhodimo proverit' svojstva jeksperta."; break;
case 4111: error_string="Korotkie pozicii ne razresheny. Neobhodimo proverit' svojstva jeksperta."; break;
case 4200: error_string="Ob#ekt uzhe sushhestvuet"; break;
case 4201: error_string="Zaprosheno neizvestnoe svojstvo ob#ekta"; break;
case 4202: error_string="Ob#ekt ne sushhestvuet";break;
case 4203: error_string="Neizvestnyj tip ob#ekta"; break;
case 4204: error_string="Net imeni ob#ekta"; break;
case 4205: error_string="Oshibka koordinat ob#ekta"; break;
case 4206: error_string="Ne najdeno ukazannoe podokno"; break;
default: error_string="Oshibka pri rabote s ob#ektom";
}
return(error_string);
}
  
//+------------------------------------------------------------------+
 

Here is my indicator:

 
//+------------------------------------------------------------------+
//|                                                        GARCH.mq4 |
//|                                              Andres Barale Sarti |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Andres Barale Sarti"
#property link      "https://www.mql5.com"
#property version   "1.20"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                       GARCH.mq4  |
//|                      Copyright © 2014, andresbarale@gmail.com    |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, andresbarale@gmail.com  "
#property link      "https://www.mql5.com"

#property indicator_width1 2       //garch linijos storis

//#property indicator_buffers 1    //garch buferis

#property indicator_buffers 3      //visi trys buferiai
#property indicator_color2  Red    //control_line_1 color
#property indicator_color3  Yellow //control_line_2 collor
#property indicator_color1  Blue   //garch linijos spalva

//************************************************************
// Input parameters
//************************************************************
extern double control_line_1 = 0.001;      //control line l 
extern double control_line_2 = 0.00001 ;    //control line 2 

extern int    e_type_data   = PRICE_CLOSE;
extern int    e_reverse_data   = 1;
extern double e_alpha = 0.010; 
extern double e_beta = 0.080;
//************************************************************
// Constant
//************************************************************
string obj_name;
string INDICATOR_NAME="GARCH";
string FILENAME      ="___GARCH.mq4";
double LOG_2;
//************************************************************
// Private vars
//************************************************************
double ExtOutputBuffer[]; //garch blue line buffer
double ExtOutputBuffer1[];//control_line_1 buferis
double ExtOutputBuffer2[];//control_line_2 buferis

// ivedimo buferis
double ExtInputBuffer[]; //input buffer
int g_period_minus_1;
//+-----------------------------------------------------------------------+
//| FUNCTION : init                                                       |                                                                                                                                                                                                                                                      
//| Initialization function                                               |                                   
//| Check the user input parameters and convert them in appropriate types.|                                                                                                    
//+-----------------------------------------------------------------------+
int init() {
//mano levels

if (Period()==PERIOD_D1)//mano
  SetLevelValue(0, 0.001); // D1 
  SetLevelValue(1, 0.009);// mano
  
  if (Period()==PERIOD_H4)
   SetLevelValue(0, 0.001); // H4  
   SetLevelValue(1, 0.009);// mano
   
     if (Period()==PERIOD_H1)
    SetLevelValue(0, 0.001); // H1  
    SetLevelValue(1, 0.009);// mano
   
        if (Period()==PERIOD_M30)
     SetLevelValue(0, 0.001); // M30
     SetLevelValue(1, 0.009);// mano
         
           if (Period()==PERIOD_M15)
      SetLevelValue(0, 0.001); // M15
      SetLevelValue(1, 0.009);// mano
      
               if (Period()==PERIOD_M5)
       SetLevelValue(0, 0.001); // M5
       SetLevelValue(1, 0.009);// mano  
  
  
  
   if(e_type_data < PRICE_CLOSE || e_type_data > PRICE_WEIGHTED ) {
      Alert( "[ 20-ERROR  " + FILENAME + " ] input parameter \"e_type_data\" unknown (" + e_type_data + ")" );
      return( -1 );
   }
//garch blue line buffer   
   IndicatorBuffers( 3 );                        //how many buffers we have
   SetIndexBuffer( 0, ExtOutputBuffer );         //garch linijos buferis
   SetIndexStyle( 0, DRAW_LINE, STYLE_SOLID, 2 );//garch linijos stilius 

// mano control_line_1   
   SetIndexBuffer( 1, ExtOutputBuffer1 );
   SetIndexStyle( 1, DRAW_LINE, STYLE_SOLID, 1, Red );
   
// mano control_line_2   
   SetIndexBuffer( 2, ExtOutputBuffer2 );
   SetIndexStyle( 2, DRAW_LINE, STYLE_SOLID, 1, Yellow );   
   
   
//----
   return( 0 );
 }
//+------------------------------------------------------------------+
//| FUNCTION : deinit                                                |
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
  }
//+------------------------------------------------------------------+
//| FUNCTION : start                                                 |
//| This callback is fired by metatrader for each tick               |
//+------------------------------------------------------------------+
int start(){
   int counted_bars = IndicatorCounted();
   
   _computeLastNbBars();
//----
   return(0);
  }
//+================================================================================================================+
//+=== FUNCTION : _computeLastNbBars                                                                            ===+
//+===                                                                                                          ===+
//+===                                                                                                          ===+
//+=== This callback is fired by metatrader for each tick                                                       ===+
//+===                                                                                                          ===+
//+===                                                                                                          ===+
//+================================================================================================================+
//+------------------------------------------------------------------+
//| FUNCTION : _computeLastNbBars                                    |
//| This callback is fired by metatrader for each tick               |
//| In : - lastBars : these "n" last bars must be repainted          | 
//+------------------------------------------------------------------+
double tmpArray[];

void _computeLastNbBars( ) {
  int pos;
   switch( e_type_data ){
      case PRICE_CLOSE    : ArrayCopy(tmpArray,Close,0,0,WHOLE_ARRAY); _GARCH( tmpArray); break;
      case PRICE_OPEN     : ArrayCopy(tmpArray,Open,0,0,WHOLE_ARRAY);  _GARCH( tmpArray); break;
      case PRICE_HIGH     : ArrayCopy(tmpArray,High,0,0,WHOLE_ARRAY);  _GARCH( tmpArray); break;
      case PRICE_LOW      : ArrayCopy(tmpArray,Low,0,0,WHOLE_ARRAY);   _GARCH( tmpArray); break;      
      default :
         Alert( "[ 20-ERROR  " + FILENAME + " ] the imput parameter e_type_data <" + e_type_data + "> is unknown" );
     }
    
  }
//+------------------------------------------------------------------+
//| FUNCTION : _GARCH                                                |
//| Compute GARCH ARMA indicator                                     |
//| In :                                                             |                      
//|    - inputData : data array on which the computation is applied  | 
//+------------------------------------------------------------------+
void _GARCH(double &inputData[] ) {
   int    pos;
   double GarchNum;
   double residual;
   double residualSq;
   double GarchNumVar = 0.000001;
   int posData = ArraySize(inputData)-1;
//----
   for( pos=1; pos<(ArraySize(inputData)); pos++ ) {
      if(e_reverse_data == 0){
         posData = pos;
      }
      residual = inputData[posData] - inputData[posData - 1];
      residualSq = MathPow(residual, 2.0);
      GarchNumVar = e_alpha * residualSq + e_beta * GarchNumVar;
      GarchNum = MathSqrt(GarchNumVar);
      ExtOutputBuffer[posData]=GarchNum;
      posData--;
//isvedame GarchNum i ekrana      
      Comment ("current_value =", DoubleToStr(GarchNum));
//sukuriam control_line_1      
      obj_name="control_line_1";
      ObjectDelete(obj_name);
      ObjectCreate(obj_name,OBJ_HLINE,0,0,control_line_1);
      ObjectSet(obj_name,OBJPROP_WIDTH,1);
      ObjectSet(obj_name,OBJPROP_COLOR,Red);
//sukuriam control_line_2      
      obj_name="control_line_2";
      ObjectDelete(obj_name);
      ObjectCreate(obj_name,OBJ_HLINE,0,0,control_line_2);
      ObjectSet(obj_name,OBJPROP_WIDTH,1);
      ObjectSet(obj_name,OBJPROP_COLOR,Red);
     
   } 
}

Files:
 
double GarchNum;
:
indicator_call = iCustom(NULL ,0 ,"garch_mod_1",3, GarchNum);

if (GarchNum > 0.00001)  

//|                                                        GARCH.mq4 |
extern double control_line_1 = 0.001;      //control line l 
extern double control_line_2 = 0.00001 ;    //control line 2 
extern int    e_type_data   = PRICE_CLOSE;
extern int    e_reverse_data   = 1;
extern double e_alpha = 0.010; 
extern double e_beta = 0.080;   
IndicatorBuffers( 3 );                        //how many buffers we have

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Your iCustom calls "garch_mod_1.ex4" but your posted code for "garch.mq4"
  3. Your indicator takes five (5) parameters you are passing none - using the defaults.
  4. Your indicator has three (3) buffers, indexed [0 .. 2] but your iCustom call tries to access buffer 4 (index 3)
  5. The last parameter for iCustom is the shift number, an int. Your iCustom call passes a double that has a random value (GarchNum never initialized.)
  6. Even if the iCustom call worked, you assign the value to the double indicator_call which you never use. and then read the random value of GarchNum to determine opening an order.
  7. Detailed explanation of iCustom - MQL4 forum
Reason: