iCustom Call for indicator not working as planned

To add comments, please log in or register
victor21
24
victor21  

Hello,


So im trying to call iCustom on an indicator i found here : 

https://www.mql5.com/en/code/19153


As you can see this indicator was adjusted from another to add some improvement including being able to call iCustom to have a signal when a divergence is spotted (4th buffer : Signal)

But when i call this buffer i only get the 0 value even when  a signal is spotted.

Anyone of you have an idea on how to solve this ?


Best regards

All In One Divergence
All In One Divergence
  • www.mql5.com
This indicator is based on code from the original author Petr, published by Aleh Sasonka. As per users' requests in comments, some improvements were made, specifically: Trading alerts (Alerts in MetaTrader 4 terminal, Email notifications, Push notifications). Inputs to enable/disable each alert type separately. Dropdown list of 30 indicators...
Files:
victor21
24
victor21  

here's some part of the code : The 4Th buffer is declared here


//---- buffers
double Oscil[],t3_Oscil[];
double Buf1[];
double Buf2[];
double Signal[];
string Col[]={"Red","DeepSkyBlue","Coral","Aqua","SaddleBrown","MediumSeaGreen"};
int ColNum[]={Red,DeepSkyBlue,Coral,Aqua,SaddleBrown,MediumSeaGreen};
//----
int qPoint=0; // variable to normalize prices
int qBars; double qTime=0; // variables to eliminate glitches when loading
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if(BackStep>0)
     {BackSteph=BackStep;  BackStepl=BackStep;}
   string short_name;
   IndicatorBuffers(4);
   qBars=Bars;
   qSteps=MathMin(3,qSteps);
   while(NormalizeDouble(Point,qPoint)==0)qPoint++;

   string Rem="Arrows";
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,t3_Oscil);
   SetIndexDrawBegin(0,2*T3_Period);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_ARROW);

   SetIndexArrow(1,code);
   SetIndexArrow(2,code);
   SetIndexBuffer(1,Buf1);
   SetIndexBuffer(2,Buf2);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexLabel(1,"1. Upper Arrow");
   SetIndexLabel(2,"2. Lower Arrow");

   SetIndexBuffer(3,Oscil);
   SetIndexLabel(3,"3. Oscilator");
   SetIndexStyle(3,DRAW_LINE);

   SetIndexLabel(4,"4. Signal (-1: sell; 1: buy)");
   SetIndexBuffer(4,Signal);
   SetIndexStyle(4,DRAW_NONE);
   SetIndexEmptyValue(4,0.0);

Then its filled with data here : i trunked some of the code

string TDMain(int Step)
  {
   Signal[Step]=0.0;
   
   int H1,H2,H3,H4,H5,H6,H7,H8,H9,H10,H11,H12,H13,H14,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,L13,L14,qExt,col; // ,i,Ls,Hb
   double qTL; // ,qLevel
   string Comm="»—»—» Step "+Step+" из "+qSteps+" (BackStep "+BackStep+")\n",Rem,Rem1,Rem2,Rem3,Rem4,Rem5,Rem6,Rem7,Rem8; // ,qp,Text
   string Short_name;
   switch(Osc)
     {
      case  1 : Short_name="AC";  break;
      case  2 : Short_name="A/D"; break;
      case  3 : Short_name="ADX"; break;
      case  4 : Short_name="ATR";  break;
      case  5 : Short_name="AO"; break;
      case  6 : Short_name="Bears"; break;
      case  7 : Short_name="Bulls";  break;
      case  8 : Short_name="CCI"; break;
      case  9 : Short_name="DeM"; break;
      case 10 : Short_name="Force";  break;
      case 11 : Short_name="Momentum"; break;
      case 12 : Short_name="MFI"; break;
      case 13 : Short_name="MACD";  break;
      case 14 : Short_name="OsMA"; break;
      case 15 : Short_name="OBV"; break;
      case 16 : Short_name="RVI"; break;
      case 17 : Short_name="StdDev"; break;
      case 18 : Short_name="Stoch";  break;
      case 19 : Short_name="Volume"; break;
      case 20 : Short_name="Close";  break;
      case 21 : Short_name="Open";  break;
      case 22 : Short_name="High"; break;
      case 23 : Short_name="Low"; break;
      case 24 : Short_name="Median Price";  break;
      case 25 : Short_name="Typical Price"; break;
      case 26 : Short_name="Weighted Close Price"; break;
      case 27 : Short_name="(O+C+H+L)/4";  break;
      case 29 : Short_name="RSI"; break;
      case 30 : Short_name="WPR"; break;
      default : Short_name="RSI";
     }
//--- for DownTrendLines
   if(Trend<=0)
     {
      Comm=Comm+"» "+Col[Step*2-2]+" DownTrendLine ";
      if(HandyColour) col=Highline; else col=ColNum[Step*2-2];
      H1=GetTD(Step+BackSteph,Buf1);
      H2=GetNextHighTD(H1);
      H3=GetNextHighTD(H2);
      H4=GetNextHighTD(H3);
      H5=GetNextHighTD(H4);
      H6=GetNextHighTD(H5);
      H7=GetNextHighTD(H6);
      H8=GetNextHighTD(H7);
      H9=GetNextHighTD(H8);
      H10=GetNextHighTD(H9);
      H11=GetNextHighTD(H10);
      H12=GetNextHighTD(H11);
      H13=GetNextHighTD(H12);
      H14=GetNextHighTD(H13);

      qTL=(t3_Oscil[H2]-t3_Oscil[H1])/(H2-H1);
      int nn,sn,r,result; // n->nn
      for(nn=1,r=H1+1; nn<H2-H1-1; nn++) // n->nn
        {
         sn=H1+1+nn; // n->nn
         if(t3_Oscil[r]<t3_Oscil[sn]) result=r;
         else result=sn;
         r=result;
        }
      double Complect1,Complect2,Complect3,Complect4,Complect5,Complect6,Complect7,Complect8,buy,sell; // ,sell1,buy1
      if(Complect>0)
        {
         Complect1=Complect+Complect10;
         Complect2=Complect+Complect20;
         Complect3=Complect+Complect30;
         Complect4=Complect+Complect40;
         Complect5=Complect+Complect50;
         Complect6=Complect+Complect60;
         Complect7=Complect+Complect70;
         Complect8=Complect+Complect80;
        }

      qExt=r; // local minimum between points

      Comm=Comm+"\n";
      int indicatorWindow=WindowFind(Short_name);
      Rem="HL("+Complect+")_"+Step;
      Rem1="HL("+Complect8+")_"+Step;
      Rem2="HL("+Complect1+")_"+Step;
      Rem3="HL("+Complect2+")_"+Step;
      Rem4="HL("+Complect3+")_"+Step;
      Rem5="HL("+Complect4+")_"+Step;
      Rem6="HL("+Complect5+")_"+Step;
      Rem7="HL("+Complect6+")_"+Step;
      Rem8="HL("+Complect7+")_"+Step;
      if(BuyStop==true && SellLimit==false)
        {
         Rem="BuyStop   "+Step+Step;
           }else if(BuyStop==false && SellLimit==true){

         Rem="SellLimit   "+Step+Step;

        }
      else Rem="Trendh   "+Step+Step;

      if(trend==1 && Oscil[H2]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H2]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H2]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H3]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H3]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H3]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H4]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H4]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H4]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H5]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H5]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H5]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H6]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H6]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H6]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H7]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H7]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H7]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H8]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H8]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H8]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H9]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H9]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H9]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H10]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H10]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H10]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H11]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H11]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H11]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H12]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H12]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H12]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H13]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H13]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H13]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H14]>Oscil[H1]) // the actual trend line
        {
         ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem,OBJPROP_TIME1,Time[H14]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H14]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
         ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

        }

      else if(trend==1 && Oscil[H2]<Oscil[H1] && Oscil[H3]<Oscil[H1] && Oscil[H4]<Oscil[H1] && Oscil[H5]<Oscil[H1] && 
         Oscil[H6]<Oscil[H1] && Oscil[H7]<Oscil[H1] && Oscil[H8]<Oscil[H1] && Oscil[H9]<Oscil[H1] && Oscil[H10]<Oscil[H1] && 
         Oscil[H11]<Oscil[H1] && Oscil[H12]<Oscil[H1] && Oscil[H13]<Oscil[H1] && Oscil[H14]<Oscil[H1]) // собственно линия тренда
           {
            ObjectCreate(Rem,OBJ_TREND,indicatorWindow,0,0,0,0);
            ObjectSet(Rem,OBJPROP_TIME1,Time[H1]);ObjectSet(Rem,OBJPROP_TIME2,Time[H1]);
            ObjectSet(Rem,OBJPROP_PRICE1,t3_Oscil[H1]);ObjectSet(Rem,OBJPROP_PRICE2,t3_Oscil[H1]);
            ObjectSet(Rem,OBJPROP_COLOR,DarkOliveGreen);
            ObjectSet(Rem,OBJPROP_WIDTH,3-MathMax(4,Step));

           }

         else    ObjectDelete(Rem);

      if(TrendLine && Oscil[H2]>Oscil[H1] && High[H2]<High[H1])// OSCILLATOR DOWNTREND && PRICE UPTREND (STANDARD BEARISH DIVERGENCE)
        {
         ObjectCreate(Rem1,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem1,OBJPROP_TIME1,Time[H2]);
         ObjectSet(Rem1,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem1,OBJPROP_PRICE1,t3_Oscil[H2]);
         ObjectSet(Rem1,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem1,OBJPROP_COLOR,Red);
         ObjectSet(Rem1,OBJPROP_WIDTH,2);
         ObjectSet(Rem1,OBJPROP_RAY,false);
         sell=true;
         SellSignal(Step);
        }else if(convergen==1 && TrendLine && Oscil[H2]<Oscil[H1] && High[H2]>High[H1]) //OSCILLATOR UPTREND && PRICE DOWNTREND (HIDDEN BEARISH DIVERGENCE)
        {
         ObjectCreate(Rem1,OBJ_TREND,indicatorWindow,0,0,0,0);
         ObjectSet(Rem1,OBJPROP_TIME1,Time[H2]);ObjectSet(Rem1,OBJPROP_TIME2,Time[H1]);
         ObjectSet(Rem1,OBJPROP_PRICE1,t3_Oscil[H2]);ObjectSet(Rem1,OBJPROP_PRICE2,t3_Oscil[H1]);
         ObjectSet(Rem1,OBJPROP_COLOR,Gold);
         ObjectSet(Rem1,OBJPROP_WIDTH,2);
         ObjectSet(Rem1,OBJPROP_RAY,false);
         sell=true;
         SellSignal(Step);
        }

      else    ObjectDelete(Rem1);

      //////////////////////////////

     


   return(Comm);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetTD(int P,const double &Arr[])
  {
   int i=0,j=0;
   while(j<P){ i++; while(Arr[i]==0){i++;if(i>showBars-2)return(-1);} j++;}
   return (i);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetNextHighTD(int P)
  {
   int i=P+1;
   while(Buf1[i]==0){i++;if(i>showBars-2)return(-1);}
   return (i);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetNextLowTD(int P)
  {
   int i=P+1;
   while(Buf2[i]==0){i++;if(i>showBars-2)return(-1);}
   return (i);
  }
//+------------------------------------------------------------------+

void SellSignal(int sStep)
  {
   Signal[sStep]=-1;
   if(Alerts)Alert("SELL SIGNAL ON "+Symbol());
   if(Email)SendMail("SELL SIGNAL ON "+Symbol(),"Signal Sent From AIO Divergence Indicator");
   if(Push)SendNotification("AIO Divergence: SELL SIGNAL ON "+Symbol());
   Print("SELLSIGNAL"," ",Signal[sStep]," ",sStep);
  }
//+------------------------------------------------------------------+

void BuySignal(int sStep)
  {
   Signal[sStep]=1;
   if(Alerts)Alert("BUY SIGNAL ON "+Symbol());
   if(Email)SendMail("BUY SIGNAL ON "+Symbol(),"Signal Sent From AIO Divergence Indicator");
   if(Push)SendNotification("AIO Divergence: BUY SIGNAL ON "+Symbol());
   Print("BUYSIGNAL"," ",Signal[sStep]," ",sStep);
  }
//+------------------------------------------------------------------+

The Functions BuySignal and SellSignal are used to fill the buffer when the signal appear.

If i attach the indicator to the charts, the alerts pop and everyting work as planned, but when i call the 4th buffer in an EA no data is extracted, we only get ampty value : 0.

Or we shoud have -1 or 1 as value when we get a signal


Any ideas ?

Naguisa Unada
265
Naguisa Unada  

Signals appear very rarely.

I think that it needs to review the program, but I do not have the time.

You can test it with the following. (You can see signals on the chart)


//line 177
SetIndexStyle(4,DRAW_HISTOGRAM); //SetIndexStyle(4,DRAW_NONE);

//line 1452
Signal[sStep]=-10;  //Signal[sStep]=-1;

//line 1462
Signal[sStep]=10;  //Signal[sStep]=1;

//insert line 18-21
#property indicator_color5 clrMagenta
#property indicator_width5 2
#property indicator_minimum -10
#property indicator_maximum 100

And also try the following program on which signals are called with "iCustom".

EURUSD_H1

EURUSD_H1

 
Files:
Sample_4.mq4 6 kb
victor21
24
victor21  

So i did your mods


The indicator display the histogram with the signals.

I asked the EA to :

for (int rech=15;rech>=0;rech--){
   Print (rech," ",iCustom(NULL,0,"AIO Divergencev2",4,rech));
   }

But all i get is 0.

Your sample 4 does display the signal when it comes, but for some reason the EA cant get it


Just give me a bone to chew on, i tried everything ...

Weird thing the original indicator withour the 4th buffer display the indicator that we chose, but this one only diplays the divergence, it's like the buffer storing the indicator source is not rendering the data.

victor21
24
victor21  

Nevermind

I was asking the loop every hour, but for some reason if i ask the loop each tick it finnally gave me the result expected.

So the signal didnt work at the beginning of the hour but was displayed right after ...

I cant understand why but now i can work with that


Thanks a lot !

To add comments, please log in or register