call custom indicator into EA with iCustom does not work

 

My dear collegues , I have a perfect custom indicator(fx_snipers_ergodic_cci_trigger.mq4) that works perfectly, hereby the indicator:

//+------------------------------------------------------------------+
//|                                       Louw Coetzer aka FX Sniper |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, Fx Sniper."
#property  link      "http://www.dunno.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red


// Ergo Variables

extern int pq =2;
extern int pr = 10;
extern int ps = 5;
extern int trigger =3;
double alertTag;

//---- indicator buffers

string signal;
string lastsignal;
double mtm[];
double absmtm[];
double ErgoCCI[];
double MainCCI[];
double var1[];
double var2[];
double var2a[];
double var2b[];
//double valor1[];
//double valor2[];
//double extvar[];
//double cciSignal[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(8);
  
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Blue);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Red);
  
   SetIndexBuffer(0,ErgoCCI);
   SetIndexLabel(0,"Ergodic CCI");
   SetIndexBuffer(1,MainCCI);
   SetIndexLabel(1,"Trigger Line");
   SetIndexBuffer(2,mtm);
   SetIndexBuffer(3,var1);
   SetIndexBuffer(4,var2);
   SetIndexBuffer(5,absmtm);
   SetIndexBuffer(6,var2a);
   SetIndexBuffer(7,var2b);
     
//---- name for DataWindow and indicator subwindow label

  
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int i;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
 
//---- main loop
  
//---- done

   for(i=0; i <= Bars; i++)
   {
   mtm[i]= Close[i]- Close[i +1];
   //absmtm[i] =  MathAbs(mtm[i]);
   }
   for(i=0; i <= Bars-1; i++)
   {
    absmtm[i] =  MathAbs(mtm[i]);
   }
   for(i=0; i <= Bars-1; i++)
   {  
    var1[i]= iMAOnArray(mtm,0,pq,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++)
   {
   var2[i]= iMAOnArray(var1,Bars,pr,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++)
   {
   var2a[i]= iMAOnArray(absmtm,0,pq,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++)
   {
   var2b[i]= iMAOnArray(var2a,0,pr,0,MODE_EMA,i);
   }
    for(i=0; i <= Bars-1; i++)
   {  
   ErgoCCI[i] = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,i))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,i)); //var2a[i]/var2b[i];
  
   }
   for(i=0; i<=Bars; i++)
   {
      MainCCI[i]=iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,i);
   }
  
   for(i=0; i<=Bars; i++)
   {
  
    
      if(MainCCI[i] > ErgoCCI[i]){
    
      {signal = "SHORT";}
    if(lastsignal != signal && alertTag!=Time[0]){
    Alert("Sniper going Short on ",Symbol()," i= ",i,"   ",MainCCI[i], "    " ,ErgoCCI[i] );
    alertTag = Time[0];
    lastsignal=signal;
     }
     }
      if (MainCCI[i] < ErgoCCI[i]){
      {signal = "LONG";}
    if(lastsignal != signal && alertTag!=Time[0]){
    Alert("Sniper going LONG on ",Symbol()," i= ",i,"   ",MainCCI[i], "    " ,ErgoCCI[i]);
    alertTag = Time[0];
    lastsignal=signal;
     }}
      if (MainCCI[i] == ErgoCCI[i])
      {signal = "NEUTRAL";}
 
    IndicatorShortName("FX Sniper's Ergodic CCI & Trigger: "+signal);
   
    }
     return;
  }
//+--------


I AM TRYING TO CALL IT FROM THE EA TO SETUP BUY AND SELL ORDER depending ON the value of the ErgoCCI that has got 0 index buffer (SetIndexBuffer(0,ErgoCCI)).

IN THE EA I AM USING THIS DAMNED ICUSTOM FUNCTION ,passing the 4 parameters that the indicator needs, and passing the zero buffer and zero bar(

by the way I tryed many but many combinations). Hereby the code into the EA that Im using just to see if I get the indicator value into the sniper variable 


double sniper; //variable is correctly declared

void OnTick()
  {

   sniper = iCustom(Symbol(),0,"fx_snipers_ergodic_cci_trigger.exe",2,5,10,3,0,0);
 

  //MessageBox(sniper);
 
     Comment("sniper value is =" + sniper);// display the value
    
  }

I ALWAYS GOT ZERO VALUE VALUE, the variable sniper is Always = 0, regardless all the buffer index i put in the icustom passage parameters.

Damned ICUSTOM function.

DOES ANYBODY HAVE ANY IDEA OR EXPERIENCE TO SOLVE THIS PROBLEM?

I GOT STUCK. IT WILL BE REALLY A GREAT FAVOUR IF SOME OF YOU HAS GOT A SOLUTION

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
Millions of traders and hundreds of brokers cannot be wrong — they have chosen MetaTrader 5 for trading Forex and financial markets! Learn more
 
mautizzy31:

My dear collegues , I have a perfect custom indicator(fx_snipers_ergodic_cci_trigger.mq4) that works perfectly, hereby the indicator:

//+------------------------------------------------------------------+
//|                                       Louw Coetzer aka FX Sniper |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, Fx Sniper."
#property  link      "http://www.dunno.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red


// Ergo Variables

extern int pq =2;
extern int pr = 10;
extern int ps = 5;
extern int trigger =3;
double alertTag;

//---- indicator buffers

string signal;
string lastsignal;
double mtm[];
double absmtm[];
double ErgoCCI[];
double MainCCI[];
double var1[];
double var2[];
double var2a[];
double var2b[];
//double valor1[];
//double valor2[];
//double extvar[];
//double cciSignal[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(8);
  
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Blue);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Red);
  
   SetIndexBuffer(0,ErgoCCI);
   SetIndexLabel(0,"Ergodic CCI");
   SetIndexBuffer(1,MainCCI);
   SetIndexLabel(1,"Trigger Line");
   SetIndexBuffer(2,mtm);
   SetIndexBuffer(3,var1);
   SetIndexBuffer(4,var2);
   SetIndexBuffer(5,absmtm);
   SetIndexBuffer(6,var2a);
   SetIndexBuffer(7,var2b);
     
//---- name for DataWindow and indicator subwindow label

  
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int i;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
 
//---- main loop
  
//---- done

   for(i=0; i <= Bars; i++)
   {
   mtm[i]= Close[i]- Close[i +1];
   //absmtm[i] =  MathAbs(mtm[i]);
   }
   for(i=0; i <= Bars-1; i++)
   {
    absmtm[i] =  MathAbs(mtm[i]);
   }
   for(i=0; i <= Bars-1; i++)
   {  
    var1[i]= iMAOnArray(mtm,0,pq,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++)
   {
   var2[i]= iMAOnArray(var1,Bars,pr,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++)
   {
   var2a[i]= iMAOnArray(absmtm,0,pq,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++)
   {
   var2b[i]= iMAOnArray(var2a,0,pr,0,MODE_EMA,i);
   }
    for(i=0; i <= Bars-1; i++)
   {  
   ErgoCCI[i] = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,i))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,i)); //var2a[i]/var2b[i];
  
   }
   for(i=0; i<=Bars; i++)
   {
      MainCCI[i]=iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,i);
   }
  
   for(i=0; i<=Bars; i++)
   {
  
    
      if(MainCCI[i] > ErgoCCI[i]){
    
      {signal = "SHORT";}
    if(lastsignal != signal && alertTag!=Time[0]){
    Alert("Sniper going Short on ",Symbol()," i= ",i,"   ",MainCCI[i], "    " ,ErgoCCI[i] );
    alertTag = Time[0];
    lastsignal=signal;
     }
     }
      if (MainCCI[i] < ErgoCCI[i]){
      {signal = "LONG";}
    if(lastsignal != signal && alertTag!=Time[0]){
    Alert("Sniper going LONG on ",Symbol()," i= ",i,"   ",MainCCI[i], "    " ,ErgoCCI[i]);
    alertTag = Time[0];
    lastsignal=signal;
     }}
      if (MainCCI[i] == ErgoCCI[i])
      {signal = "NEUTRAL";}
 
    IndicatorShortName("FX Sniper's Ergodic CCI & Trigger: "+signal);
   
    }
     return;
  }
//+--------


I AM TRYING TO CALL IT FROM THE EA TO SETUP BUY AND SELL ORDER depending ON the value of the ErgoCCI that has got 0 index buffer (SetIndexBuffer(0,ErgoCCI)).

IN THE EA I AM USING THIS DAMNED ICUSTOM FUNCTION ,passing the 4 parameters that the indicator needs, and passing the zero buffer and zero bar(

by the way I tryed many but many combinations). Hereby the code into the EA that Im using just to see if I get the indicator value into the sniper variable 


double sniper; //variable is correctly declared

void OnTick()
  {

   sniper = iCustom(Symbol(),0,"fx_snipers_ergodic_cci_trigger.exe",2,5,10,3,0,0);
 

  //MessageBox(sniper);
 
     Comment("sniper value is =" + sniper);// display the value
    
  }

I ALWAYS GOT ZERO VALUE VALUE, the variable sniper is Always = 0, regardless all the buffer index i put in the icustom passage parameters.

Damned ICUSTOM function.

DOES ANYBODY HAVE ANY IDEA OR EXPERIENCE TO SOLVE THIS PROBLEM?

I GOT STUCK. IT WILL BE REALLY A GREAT FAVOUR IF SOME OF YOU HAS GOT A SOLUTION

Change "fx_snipers_ergodic_cci_trigger.exe" to "fx_snipers_ergodic_cci_trigger.ex4"

 
Mladen Rakic:

Change "fx_snipers_ergodic_cci_trigger.exe" to "fx_snipers_ergodic_cci_trigger.ex4"


GREATTTTTTTTTTTTTTTTTTTT, TANKSSSSSSSSSSSSSSS A LOTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT. 

GRAZIE Rakic, very kind of you . I owe you at least 10 bears ;-)

 

mautizzy31: I AM TRYING TO CALL IT FROM THE EA TO SETUP BUY AND SELL ORDER depending ON the value of the ErgoCCI that has got 0 index buffer (SetIndexBuffer(0,ErgoCCI)).

   sniper = iCustom(Symbol(),0,"fx_snipers_ergodic_cci_trigger.exe",2,5,10,3,0,0);

  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum


  2.    SetIndexBuffer(0,ErgoCCI);
       SetIndexBuffer(1,MainCCI);
    
          if(MainCCI[i] > ErgoCCI[i]){
          {signal = "SHORT";}
    The signal is between two buffers, not a single call.
  3. EXE has already been mentioned. Simply drop the .EXE and/or .EX4
  4. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
 
whroeder1:
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum


  2. The signal is between two buffers, not a single call.
  3. EXE has already been mentioned. Simply drop the .EXE and/or .EX4
  4. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

Is there a problem when comparing two buffers? Is it the same as calling two Indicators from an EA?