This is my trial to draw the difference between two moving averages as a histogram on H1 time frame. The problem is that it does not change when I change a time frame, especially to lower ones. I am a beginner at MQL4, with no experience or programming background, so please explain to me the mistake.
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Gray
#property indicator_width1 2
extern int maperiod1 = 25;
extern int maperiod2 = 55;
extern int timefr = 60;
double mainbuffer[];
int init(){
SetIndexBuffer( 0, mainbuffer );
SetIndexStyle( 0, DRAW_HISTOGRAM );
return(0);
}
int start(){
int counted_bars = IndicatorCounted();
if ( counted_bars < 0) return(-1);
if ( counted_bars > 0) return( 0);
int limit = ( Bars - counted_bars );
for ( int i = limit; i >= 0; i-- ){
int shift = iBarShift( NULL, timefr, Time[i] );
double maB = iMA( NULL, timefr, maperiod1, 0, MODE_EMA, 0, shift );
double maR = iMA( NULL, timefr, maperiod2, 0, MODE_EMA, 0, shift );
mainbuffer[shift]= ( maB - maR );
}
return(0);
}
@halferor make a better edit. Please do not roll back, for the reasons I have already given. Apologies for the fuss on your question OP! - halfer