Download MetaTrader 5

Help with iCustom

To add comments, please log in or register
Bro840
104
Bro840  

Hello.

 

I have made an Custom Indicator (SwingShow) that is working just fine.

 

Now i'm trying to make a ExpertAdvisor based on this Custom Indicator.

 

i have this code OnTick 

....

Swing = iCustom(Symbol(),PERIOD_CURRENT,"SwingShow",0,0); 

.... 

 

But when i check Swing it does not change, it keeps always the same.

 

Can anyone help please? 

whroeder1
16099
whroeder1  
Bro840
104
Bro840  

Here are the Indicator Code. It determines whether we are in Asc Swing  1 or Desc Swing - 1 just that.

 

SwingShow.

 

#property indicator_separate_window
#property indicator_buffers 1       // Number of buffers
#property indicator_color1 Blue     // Color of the line

double Buf_0[];
int i, swing_inicio, swing_fim;
string swing;

int OnInit()
{  
   SetIndexBuffer(0,Buf_0); 
   SetIndexStyle (0,DRAW_HISTOGRAM,STYLE_SOLID,5);
   
   int FirstBar = iBars(NULL,0) -1;
   
   swing_inicio = FirstBar; 
   swing_fim = FirstBar;
            
   if (iClose(NULL,0,FirstBar-1) < iClose(NULL,0,FirstBar)) swing = "desc";
   else swing = "asc";
      

   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 x = rates_total - 1 - prev_calculated;
           
      
      for (i=x; i > 0; i--)
         
  
         if (swing == "desc")
         { 
            
            Buf_0[i] = -1;
                        
                
                  if (close[i-1] > open[swing_fim])
                  {

                      swing_inicio = swing_fim;
                                               
                      swing_fim = i-1;
                           
                      swing = "asc";
                  }

                  if (close[i-1] < close[swing_fim]) 
                  {
                      swing_fim = i-1;
                  }  
               
         }    

         else if (swing == "asc")   
         { 
            
            Buf_0[i] = 1;
            
                  if (close[i-1] < open[swing_fim])
                  {
                     
                      swing_inicio = swing_fim;
                                               
                      swing_fim = i-1;
                           
                      swing = "desc";
                  }
            
                  if (close[i-1] > close[swing_fim]) 
                  {
                      swing_fim = i-1;
                  } 
                  
         }    


return(rates_total);

 

 

Now when i call it from the EA trhought iCustom function it dosen't return the expected value. Instead it shows always a very big number like 123215......


double Swing; 

Swing = iCustom(Symbol(),PERIOD_CURRENT,"SwingShow",0,0); 


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

  2. You never set element zero.
    for (i=x; i > 0; i--)
       :
       Buf_0[i] = -1;
    So why would you expect to read anything from element zero?
    Swing = iCustom(Symbol(),PERIOD_CURRENT,"SwingShow",0,0); 
Bro840
104
Bro840  

Thank you very much. 

Big blunder :) 

To add comments, please log in or register