Hi Guys,
I have modified an indicator but have managed to muck it up. It is essentially a 3 MA indicator that plots a green histogram if the 3 MAs are in up trend order, plots red if thethree indicators are in down trend order and gray if they arent lined up for an up or down trend.
All it does now is print some green bars, could someone please have a look for me and let me know what I have done wrong.
Thanks
Steve
//+------------------------------------------------------------------+
//| iMAOnArray.mq4 |
//| Coders Guru |
//| http://www.metatrader.info |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link "http://www.metatrader.info"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1.1
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Gray
///From the other
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
double ma55[];
double ma89[];
double ma233[];
int init()
{
IndicatorBuffers(6);
SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexBuffer(0, g_ibuf_120);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexBuffer(1, g_ibuf_124);
SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexBuffer(2, g_ibuf_128);
SetIndexBuffer(3,ma55);
SetIndexBuffer(4,ma89);
SetIndexBuffer(5,ma233);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
int bar, limit;
int counted_bars=IndicatorCounted();
//int counted_bars = 50;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-IndicatorCounted();
//limit = 50;
for(bar=0; bar<limit; bar++)
{
ma55[bar] = iMA(NULL,0,55,0,MODE_EMA,PRICE_MEDIAN,bar);
ma89[bar] = iMA(NULL,0,89,0,MODE_EMA,PRICE_MEDIAN,bar);
ma233[bar] = iMA(NULL,0,233,0,MODE_EMA,PRICE_MEDIAN,bar);
}
for(bar=0; bar<limit; bar++)
{
if(ma55[bar]>ma89[bar] && ma233[bar]>ma233[bar])
{
g_ibuf_120[bar] = 1;
}
else
{
if(ma89[bar]<ma89[bar] && ma89[bar]<ma233[bar])
{
g_ibuf_124[bar] = 1;
}
else
{
g_ibuf_128[bar] = 1;
}
}
}
return(0);
}
I have modified an indicator but have managed to muck it up. It is essentially a 3 MA indicator that plots a green histogram if the 3 MAs are in up trend order, plots red if thethree indicators are in down trend order and gray if they arent lined up for an up or down trend.
All it does now is print some green bars, could someone please have a look for me and let me know what I have done wrong.
Thanks
Steve
//+------------------------------------------------------------------+
//| iMAOnArray.mq4 |
//| Coders Guru |
//| http://www.metatrader.info |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link "http://www.metatrader.info"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1.1
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Gray
///From the other
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
double ma55[];
double ma89[];
double ma233[];
int init()
{
IndicatorBuffers(6);
SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexBuffer(0, g_ibuf_120);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexBuffer(1, g_ibuf_124);
SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexBuffer(2, g_ibuf_128);
SetIndexBuffer(3,ma55);
SetIndexBuffer(4,ma89);
SetIndexBuffer(5,ma233);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
int bar, limit;
int counted_bars=IndicatorCounted();
//int counted_bars = 50;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-IndicatorCounted();
//limit = 50;
for(bar=0; bar<limit; bar++)
{
ma55[bar] = iMA(NULL,0,55,0,MODE_EMA,PRICE_MEDIAN,bar);
ma89[bar] = iMA(NULL,0,89,0,MODE_EMA,PRICE_MEDIAN,bar);
ma233[bar] = iMA(NULL,0,233,0,MODE_EMA,PRICE_MEDIAN,bar);
}
for(bar=0; bar<limit; bar++)
{
if(ma55[bar]>ma89[bar] && ma233[bar]>ma233[bar])
{
g_ibuf_120[bar] = 1;
}
else
{
if(ma89[bar]<ma89[bar] && ma89[bar]<ma233[bar])
{
g_ibuf_124[bar] = 1;
}
else
{
g_ibuf_128[bar] = 1;
}
}
}
return(0);
}