iCustom Question

 

Can anyone tell / show me how to import the value of a buffer into an EA which is normally 0.0, becomes a certain value throughout the code, then returns to 0.0.  I've been using iCustom to bring the value of each buffer into my EA, but only get either 0.0 or empty value ( 2147483647.00000 )  The states of " on or off " are not enough, for my calculations.  Below is the code, who's values I've tried to import.  Basically, I need to bring the values of ZigZag, lasthigh, lastlow , curhigh, curlow and whatlookfor out of the code and store them in buffers so that they can be imported into the EA.

Thanks!


//+------------------------------------------------------------------+
//|                                                       ZigZag.mq4 |
//|                   Copyright 2006-2014, MetaQuotes Software Corp. |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "2006-2014, MetaQuotes Software Corp."
#property link      "https://www.mql4.com"
#property strict

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1  White
//---- indicator parameters
input int InpDepth=12;     // Depth
input int InpDeviation=5;  // Deviation
input int InpBackstep=3;   // Backstep
//---- indicator buffers
double ZigzagBuffer[];
double HighBuffer[];
double LowBuffer[];
double whatlookforBuffer[];






//--- globals
int    Level=3; // recounting's depth of remums
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(InpBackstep>=InpDepth)
     {
      Print("Backstep cannot be greater or equal to Depth");
      return(INIT_FAILED);
     }
//--- 2 additional buffers

   IndicatorBuffers(4);
   
//---- drawing settings

   SetIndexStyle(0,DRAW_SECTION);
   
//---- indicator buffers

   SetIndexBuffer(0,ZigzagBuffer);
   SetIndexBuffer(1,HighBuffer);
   SetIndexBuffer(2,LowBuffer);
   SetIndexBuffer(3,whatlookforBuffer);   //  I added this buffer to import state of whatlookfor Buffer
   
 
   
   SetIndexEmptyValue(0,0.0);
   
//---- indicator short name

   IndicatorShortName("ZigZag("+string(InpDepth)+","+string(InpDeviation)+","+string(InpBackstep)+")");
   
//---- initialization done

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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    i,limit,counterZ,whatlookfor=0;
   int    back,pos,lasthighpos=0,lastlowpos=0;
   double remum, ZigzagBuff;
   double curlow=0.0,curhigh=0.0,lasthigh=0.0,lastlow=0.0;
   string t;
   
   
   
//--- check for history and inputs

   if(rates_total<InpDepth || InpBackstep>=InpDepth)
      return(0);
      
//--- first calculations

   if(prev_calculated==0)
      limit=InitializeAll();
   else 
     {
     
      //--- find first remum in the depth Level or 100 last bars
      
      i=counterZ=0;
      while(counterZ<Level && i<100)
        {
         if(ZigzagBuffer[i]!=0.0)
            counterZ++;
         i++;
        }
        
      //--- no remum found - recounting all from begin
      
      if(counterZ==0)
         limit=InitializeAll();
      else
        {
         //--- set start position to found remum position
         
         limit=i-1;
         
         //--- what kind of remum?
         
         if(LowBuffer[i]!=0.0) 
           {
           
            //--- low remum
            
            curlow=LowBuffer[i];
            
            //--- will look for the n high remum
            
            whatlookfor=1; whatlookforBuffer[i] = whatlookfor;
           }
         else
           {
           
            //--- high remum
            
            curhigh=HighBuffer[i];
            
            //--- will look for the n low remum
            
            whatlookfor=-1; whatlookforBuffer[i] = whatlookfor;
           }
           
         //--- clear the rest data
         
         for(i=limit-1; i>=0; i--)  
           {
            ZigzagBuffer[i]=0.0;  
            LowBuffer[i]=0.0;
            HighBuffer[i]=0.0;
           }
        }
     }
     
//--- main loop      

   for(i=limit; i>=0; i--)
     {
     
      //--- find lowest low in depth of bars
      
      remum=low[iLowest(NULL,0,MODE_LOW,InpDepth,i)];
      
      //--- this lowest has been found previously
      
      if(remum==lastlow)
         remum=0.0;
      else 
        { 
        
         //--- new last low
         
         lastlow=remum; 
         
         //--- discard remum if current low is too high
         
         if(low[i]-remum>InpDeviation*Point)
            remum=0.0;
         else
           {
           
            //--- clear previous remums in backstep bars
            
            for(back=1; back<=InpBackstep; back++)
              {
               pos=i+back;
               if(LowBuffer[pos]!=0 && LowBuffer[pos]>remum)
                  LowBuffer[pos]=0.0; 
              }
           }
        } 
        
      //--- found remum is current low
      
      if(low[i]==remum)
         LowBuffer[i]=remum;
      else
         LowBuffer[i]=0.0;
         
      //--- find highest high in depth of bars
      
      remum=high[iHighest(NULL,0,MODE_HIGH,InpDepth,i)];
      
      //--- this highest has been found previously
      
      if(remum==lasthigh)
         remum=0.0;
      else 
        {
        
         //--- new last high
         
         lasthigh=remum;
         
         //--- discard remum if current high is too low
         
         if(remum-high[i]>InpDeviation*Point)
            remum=0.0;
         else
           {
           
            //--- clear previous remums in backstep bars
            
            for(back=1; back<=InpBackstep; back++)
              {
               pos=i+back;
               if(HighBuffer[pos]!=0 && HighBuffer[pos]<remum)
                  HighBuffer[pos]=0.0; 
              } 
           }
        }
        
      //--- found remum is current high
      
      if(high[i]==remum)
         HighBuffer[i]=remum;
      else
         HighBuffer[i]=0.0;
     }
     
//--- final cutting 

   if(whatlookfor==0)
     {
      lastlow=0.0;
      lasthigh=0.0;  
     }
   else
     {
      lastlow=curlow;
      lasthigh=curhigh;
     }
   for(i=limit; i>=0; i--)
     {
      switch(whatlookfor)
        {
        
         case 0: // look for peak or lawn 
         
            if(lastlow==0.0 && lasthigh==0.0)
              {
               if(HighBuffer[i]!=0.0)
                 {
                  lasthigh=High[i];
                  lasthighpos=i;
                  whatlookfor=-1; whatlookforBuffer[i] = whatlookfor;
                  ZigzagBuffer[i]=lasthigh;; ZigzagBuff = ZigzagBuffer[i];
                 }
               if(LowBuffer[i]!=0.0)
                 {
                  lastlow=Low[i];
                  lastlowpos=i;
                  whatlookfor=1; whatlookforBuffer[i] = whatlookfor;
                  ZigzagBuffer[i]=lastlow;; ZigzagBuff = ZigzagBuffer[i];
                 }
              }
             break;  
             
         case 1: // look for peak
         
            if(LowBuffer[i]!=0.0 && LowBuffer[i]<lastlow && HighBuffer[i]==0.0)
              {
               ZigzagBuffer[lastlowpos]=0.0;
               lastlowpos=i;
               lastlow=LowBuffer[i];// LowBuffer[i] = lastlow;
               ZigzagBuffer[i]=lastlow;; ZigzagBuff = ZigzagBuffer[i];
              }
            if(HighBuffer[i]!=0.0 && LowBuffer[i]==0.0)
              {
               lasthigh=HighBuffer[i];// HighBuffer[i] = lasthigh;
               lasthighpos=i;
               ZigzagBuffer[i]=lasthigh;; ZigzagBuff = ZigzagBuffer[i];
               whatlookfor=-1; whatlookforBuffer[i] = whatlookfor;
              }   
            break;               
            
         case -1: // look for lawn
         
            if(HighBuffer[i]!=0.0 && HighBuffer[i]>lasthigh && LowBuffer[i]==0.0)
              {
               ZigzagBuffer[lasthighpos]=0.0;
               lasthighpos=i;
               lasthigh=HighBuffer[i];// HighBuffer[i] = lasthigh;
               ZigzagBuffer[i]=lasthigh; ZigzagBuff = ZigzagBuffer[i];
              }
            if(LowBuffer[i]!=0.0 && HighBuffer[i]==0.0)
              {
               lastlow=LowBuffer[i];// LowBuffer[i] = lastlow;
               lastlowpos=i;
               ZigzagBuffer[i]=lastlow; ; ZigzagBuff = ZigzagBuffer[i];
               whatlookfor=1; whatlookforBuffer[i] = whatlookfor;
              }   
            break;               
        }
     }
     
     if(whatlookfor == (-1))
     {t = "UP";}
     
     if(whatlookfor == (1))
     {t = "DOWN";}
     

     
     
     Alert("Cur High =  ",DoubleToStr(curhigh,Digits),"   Last High =  ",DoubleToStr(lasthigh,Digits),"   Cur Low =  ",DoubleToStr(curlow,Digits),"   Last Low =  ",DoubleToStr(lastlow,Digits),"  remum =  ",remum);
    Alert("lasthighpos =  ",lasthighpos,"   lastlowpos =  ",lastlowpos,"   whatlookfor =  ",whatlookfor,"   Back =  ",back,"   Pos =  ",pos,"   Direction =  ",t);
     Alert("ZigzagBuffer[i] =  ",DoubleToStr(ZigzagBuff,Digits));
  
  
      Alert("ZigzagBuffer =  ",DoubleToStr(ZigzagBuff,Digits),"   HighBuffer =  ",DoubleToStr(lasthigh,Digits),"   LowBuffer =  ",DoubleToStr(lastlow,Digits),"   whatlookforBuffer =  ",DoubleToStr(whatlookfor,Digits));

      Alert("   ");
     
     
//--- done

   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int InitializeAll()
  {
   ArrayInitialize(ZigzagBuffer,0.0);
   ArrayInitialize(HighBuffer,0.0);
   ArrayInitialize(LowBuffer,0.0);
   
//--- first counting position

   return(Bars-InpDepth);
  }
//+------------------------------------------------------------------+
 

search it ?  unsigned data type

                          

            short int    2      16          -32,768 -> +32,767          (16kb)
   unsigned short int    2      16                0 -> +65,535          (32Kb)
         unsigned int    4      16                0 -> +4,294,967,295   ( 4Gb)
                  int    4      32   -2,147,483,648 -> +2,147,483,647   ( 2Gb)
             long int    4      32   -2,147,483,648 -> +2,147,483,647   ( 2Gb)
          signed char    1       8             -128 -> +127
        unsigned char    1       8                0 -> +255
                float    4      32
               double    8      64
           long double   12      96
 

Thanks!  Not sure how this fits.  My question is, "  How can I get the values , of an indicator, which are not stored in the buffers, into my EA.  iCustom only, as far as I can tell, imports the values of the buffers.


Thanks, again!

 
akose:

search it ?  unsigned data type

                          


What do you mean by that ? Buffers are doubles their values can only be doubles.
 
Yellowbeard:

Thanks!  Not sure how this fits.  My question is, "  How can I get the values , of an indicator, which are not stored in the buffers, into my EA.  iCustom only, as far as I can tell, imports the values of the buffers.


Thanks, again!


You can't. You will have to make more buffers to hold any values you want to pass to the EA.
 
SDC:

You can't. You will have to make more buffers to hold any values you want to pass to the EA.

Or possibly pass them via GlobalVariables, file or Object properties  . . .
 
I created a buffer, whatlookforBuffer[], to pass the value of whatlookfor, which is -1 for high, 1 for low.      Assigned it as buffer #4.      double WhatlookFor = iCustom(NULL,0,"ZigZag",3,0);        //---- whatlookforBuffer[]    This produced the output of either 0.0 or 2147483647.00000 ( empty value ).   2147483647.00000 = (-1).    For the purpose of determining whether we're looking for a high or low, this was fine.   I added the following code in my EA to establish these states. 
        if(WhatlookFor == 2147483647.00000)
        {WhatlookFor = (-1.0);}            
        else
        {WhatlookFor = (1.0);}

This works for a while, then, for some reason, the states reverse.  Positive becomes negative.  Negative becomes positive.  I have alerts within the indicator and the EA, so that I can see if the values match up.  Output vs Input.  2147483647.00000 will equal (-1) then it equals (1).  Perhaps there's a state within the indicator that changes this or maybe I'm not using the buffers the right way.   The buffers within the indicator use i as the basis of the stored value.  Should I use 0 instead?  Any thoughts would be greatly appreciated!


Thanks!


Yellowbeard

 

Not having much luck importing buffer values from indicator.  Even when I create additional buffers to store the values that I need from the indicator.  Values are stored in additional buffers within the indicator, as I need, but only get either 0.00000 or 2147483647.00000 in EA.  Any suggestions would be greatly appreciated.


Thanks!







 

Reason: