Hello,
Im trying to build an indicator for volume. This my first attempt at writing an indicator starting from scratch and basing myself on thee betterolume indicator. I've managed to compile it, but when I load it on the screen it just has a black window with no bars on it. Can someone take a quick look and tell me what I'm doing wrong. Like I said, I am very very new to programming languages (MQL4 would be the first one I learn)
What I want the indicator to do is basically to display 4 different color bars depending on it's position in relation to an MA and certain levels based on the MA. Like this;
If volume<MA*0.66 then vol is low
If volume>=MA*0.66 && volume <=MA*1.33 then vol is normal/average
If vol>MA*1.3 && vol<=MA*2 then vol is high
If vol>MA*2 then vol is ultra high
For each type of volume the bar would change color. Here's what I have so far and hope someone can help me out. It's very frusrating that once I am finally able to compile the indicator, the separate window only shows blackness. So here it is, any help ould be greatly appreciated:
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 White
#property indicator_color2 DeepSkyBlue
#property indicator_color3 Red
#property indicator_color4 Purple
#property indicator_color5 Gray
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
extern int Number_of_Bars = 500;
extern int MA_Period = 50;
extern double Low_Setting = 0.66;
extern double Normal_Setting = 1.33;
extern double High_Setting = 2.0;
extern int LookBack= 20;
double LowV[], NormalV[], HighV[], Ult_HghV[], Av[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,White);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexLabel(0,"Lw");
SetIndexBuffer(1,DeepSkyBlue);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexLabel(1,"Normal");
SetIndexBuffer(2,Red);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexLabel(2,"Hgh");
SetIndexBuffer(3,Purple);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexLabel(3,"Ult_Hgh");
SetIndexBuffer(4,Gray);
IndicatorShortName("VSA Volume" );
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deitinialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
double tempvol, Lwlevel, Normlevel, Hghlevel;
int CountedBars= IndicatorCounted();
int limit;
//---- last counted bar will be recounted
if(CountedBars>0) CountedBars--;
if ( Number_of_Bars == 0 )
Number_of_Bars = Bars-CountedBars;
limit=Number_of_Bars; //Bars-counted_bars;
for(int i=0; i<limit; i++)
{
Lwlevel= 0; Normlevel= 0; Hghlevel=0; LowV[i]=0; NormalV[i]= Volume[i];
HighV[i]= 0; Ult_HghV[i]= 0;
//-----------------------------Volume_MA-----------------------------
for ( int n=i;n<i+MA_Period;n++ )
{
tempvol= Volume[n] + tempvol;
}
Av[i] = NormalizeDouble(tempvol/MA_Period,0);
//-------------------------------------------------------------------
for ( n=i;n<i+LookBack;n++)
{
Lwlevel= Av[i]*Low_Setting;
Normlevel= Av[i]*Normal_Setting;
Hghlevel= Av[i]*High_Setting;
}
if (Volume[i] < Lwlevel)
{
LowV[i] = NormalizeDouble(Volume[i],0);
NormalV[i]= 0;
}
if (Volume[i] > Normlevel && Volume[i] <= Hghlevel)
{
LowV[i] = 0;
NormalV[i] = 0;
HighV[i] = NormalizeDouble(Volume[i],0);
}
if (Volume[i] > Hghlevel)
{
LowV[i] = 0;
NormalV[i] = 0;
HighV [i]= 0;
Ult_HghV[i] = NormalizeDouble(Volume[i],0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Im trying to build an indicator for volume. This my first attempt at writing an indicator starting from scratch and basing myself on thee betterolume indicator. I've managed to compile it, but when I load it on the screen it just has a black window with no bars on it. Can someone take a quick look and tell me what I'm doing wrong. Like I said, I am very very new to programming languages (MQL4 would be the first one I learn)
What I want the indicator to do is basically to display 4 different color bars depending on it's position in relation to an MA and certain levels based on the MA. Like this;
If volume<MA*0.66 then vol is low
If volume>=MA*0.66 && volume <=MA*1.33 then vol is normal/average
If vol>MA*1.3 && vol<=MA*2 then vol is high
If vol>MA*2 then vol is ultra high
For each type of volume the bar would change color. Here's what I have so far and hope someone can help me out. It's very frusrating that once I am finally able to compile the indicator, the separate window only shows blackness. So here it is, any help ould be greatly appreciated:
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 White
#property indicator_color2 DeepSkyBlue
#property indicator_color3 Red
#property indicator_color4 Purple
#property indicator_color5 Gray
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
extern int Number_of_Bars = 500;
extern int MA_Period = 50;
extern double Low_Setting = 0.66;
extern double Normal_Setting = 1.33;
extern double High_Setting = 2.0;
extern int LookBack= 20;
double LowV[], NormalV[], HighV[], Ult_HghV[], Av[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,White);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexLabel(0,"Lw");
SetIndexBuffer(1,DeepSkyBlue);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexLabel(1,"Normal");
SetIndexBuffer(2,Red);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexLabel(2,"Hgh");
SetIndexBuffer(3,Purple);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexLabel(3,"Ult_Hgh");
SetIndexBuffer(4,Gray);
IndicatorShortName("VSA Volume" );
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deitinialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
double tempvol, Lwlevel, Normlevel, Hghlevel;
int CountedBars= IndicatorCounted();
int limit;
//---- last counted bar will be recounted
if(CountedBars>0) CountedBars--;
if ( Number_of_Bars == 0 )
Number_of_Bars = Bars-CountedBars;
limit=Number_of_Bars; //Bars-counted_bars;
for(int i=0; i<limit; i++)
{
Lwlevel= 0; Normlevel= 0; Hghlevel=0; LowV[i]=0; NormalV[i]= Volume[i];
HighV[i]= 0; Ult_HghV[i]= 0;
//-----------------------------Volume_MA-----------------------------
for ( int n=i;n<i+MA_Period;n++ )
{
tempvol= Volume[n] + tempvol;
}
Av[i] = NormalizeDouble(tempvol/MA_Period,0);
//-------------------------------------------------------------------
for ( n=i;n<i+LookBack;n++)
{
Lwlevel= Av[i]*Low_Setting;
Normlevel= Av[i]*Normal_Setting;
Hghlevel= Av[i]*High_Setting;
}
if (Volume[i] < Lwlevel)
{
LowV[i] = NormalizeDouble(Volume[i],0);
NormalV[i]= 0;
}
if (Volume[i] > Normlevel && Volume[i] <= Hghlevel)
{
LowV[i] = 0;
NormalV[i] = 0;
HighV[i] = NormalizeDouble(Volume[i],0);
}
if (Volume[i] > Hghlevel)
{
LowV[i] = 0;
NormalV[i] = 0;
HighV [i]= 0;
Ult_HghV[i] = NormalizeDouble(Volume[i],0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
On a journey to consistency.