Download MetaTrader 5

Problems with indicator when changing periud

To add comments, please log in or register
Bro840
104
Bro840  
Hi there.

I'm having a little problem with my indicator. 

The indicator itslef it is working just fine. It's Separate window indicator with histogram style, and it's value can be only -1 or 1.

What happen is that when i change the periud for exemple from 1H to 5m the first time i do that, it does not shows any histogram. So i need to select again 1H and then 5m and then the indicator works fine again.


Any Ideia?

 

int OnInit()
{
   SetIndexBuffer(0,Indicador);                          
   SetIndexStyle (0,DRAW_HISTOGRAM,STYLE_SOLID,5);       
   
   int FirstBarIndex = iBars(NULL,0)-1;                    
   
                                                        
   Swing_Begin = FirstBarIndex;                          
   Swing_End = FirstBarIndex;                            
            
                                                                         
   if (iClose(NULL,0,FirstBarIndex-1) < iClose(NULL,0,FirstBarIndex))    
   {
      Swing = "DESC";                                                    
   }
   else                                                                  
   {
      Swing = "ASC";                                                        
   }

   return(INIT_SUCCEEDED);
}

 

whroeder1
15107
whroeder1  
bro840: Any Ideia?
  1. Event Handling Functions - MQL4 Documentation OnInit only runs on load and on chart change.
  2. The first time you have no M5 history, so you get nothing.
  3. What good is an indicator something about the oldest bar?
Bro840
104
Bro840  

Thank you for your reply but indeed when i first select 5m chart on the OnInit functin already there are information about bar history.

So your awnswer must no be correct. It must be something else.... 

Bro840
104
Bro840  
Very nice i had an idea and turns out that was correct.

The problem was on the array declaration Indicator[];

 

I have Tried Indicator [100000] and now the indicator runs perfectly :)

Now i must simply resize every time the Indicator[] on OnInit function and thats it.

Thank You again.
To add comments, please log in or register