//+------------------------------------------------------------------+
//| Percentage Crossover Channel.mq4 |
//| Copyright © 2009, Vic2008 |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Vic2008"
#property link ""
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red
extern double percent=1.0;
extern bool channel=True;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double PREV=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
PREV=0; //Close[0];
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i;
double var1;
int t=Bars-counted_bars;
if (t>1){ t=Bars-3; }
//----
var1=percent/100;
for( i=t; i>=0; i-- ){
if( (Close[i]*(1-var1)) > PREV ){ ExtMapBuffer1[i]=Close[i]*(1-var1); }
else{
if( (Close[i]*(1+var1)) < PREV ){ ExtMapBuffer1[i]=Close[i]*(1+var1); }
else{ ExtMapBuffer1[i]=PREV; }
}
PREV=ExtMapBuffer1[i];
if( channel==True ){
ExtMapBuffer2[i]=ExtMapBuffer1[i] + (ExtMapBuffer1[i]/100) * percent;
ExtMapBuffer3[i]=ExtMapBuffer1[i] - (ExtMapBuffer1[i]/100) * percent;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments