BIAS Indicator

 

//+------------------------------------------------------------------------+
//| BIAS.mq4 |
//| Copyright ?2011, MetaQuotes Software Corp. |
//| http://www.sedofx.com/ |
//+----------------------------------------------------------------------------+
#property copyright "Copyright ?2011, MetaQuotes Software Corp."
#property link "http://www.sedofx.com/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Magenta
#property indicator_color3 Yellow

//---- input parameters
extern int Day1st=6;
extern int Day2nd=12;
extern int Day3rd=24;


//---- buffers
double ExtShortBuffer[];
double ExtMedBuffer[];
double ExtLongBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtShortBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMedBuffer);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtLongBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+

int start()
{


int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
int posi=Bars-Day3rd;
//----
if(counted_bars>0) counted_bars--;
posi=Bars-counted_bars;

for(int i=0;i<posi;i++)
{
double val1=iMA(NULL,0,Day1st,0,MODE_SMMA,PRICE_MEDIAN,i);
double val2=iMA(NULL,0,Day2nd,0,MODE_SMMA,PRICE_MEDIAN,i);
double val3=iMA(NULL,0,Day3rd,0,MODE_SMMA,PRICE_MEDIAN,i);

ExtShortBuffer[i]=(Close[i]-val1)/val1*100;
ExtMedBuffer[i]=(Close[i]-val2)/val2*100;
ExtLongBuffer[i]=(Close[i]-val3)/val3*100;

}
//----
return(0);
}
//+------------------------------------------------------------------+

Files:
 

Please use this to post code . . . it makes it easier to read.

Did you have a question ?

Reason: