TP_ChannelWidth

Author: Ron Mauldin
TP_ChannelWidth
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
TP_ChannelWidth
//+------------------------------------------------------------------+
//|                                               TP_CcwnnelWidth.mq4 |
//|                                                      Ron Mauldin |
//|                                                  http://fx41.com |
//+------------------------------------------------------------------+
#property copyright "Ron Mauldin"
#property link      "http://fx41.com"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_width1 3
#property indicator_width2 1
#property indicator_width3 1
#property  indicator_minimum 0.0

//----
extern int CW_Periods=7;
extern int CW_PipMultiplier=10000;
//---- buffers
double cwPeriodPips[];
double cwUP[];
double cwDN[];

int init(){
 SetIndexStyle(0,DRAW_HISTOGRAM);
 SetIndexBuffer(0, cwPeriodPips);
 SetIndexDrawBegin(0,10);
 SetIndexStyle(1,DRAW_HISTOGRAM);
 SetIndexBuffer(1, cwUP);
 SetIndexDrawBegin(1,10);
 SetIndexStyle(2,DRAW_HISTOGRAM);
 SetIndexBuffer(2, cwDN);
 SetIndexDrawBegin(2,10);
 return(0);
}
int deinit(){return(0);}
int start(){
 double cwOpen, cwHigh, cwLow, cwClose,cwPeriodMax,cwPeriodMin,cwChannelWidth;
 int counted_bars = IndicatorCounted();
 if(counted_bars<0) counted_bars=0;
 if(counted_bars>0) counted_bars--;
 int limit = (Bars - 1 - counted_bars);
 for(int bar = limit; bar >= 0; bar--){  
  cwPeriodMax=0;
  cwPeriodMin=0;
  cwOpen=((((((Open[bar+3]+High[bar+3]+Low[bar+3]+Close[bar+3])/4)+((Open[bar+2]+High[bar+2]+Low[bar+2]+Close[bar+2])/4))/2)+((Open[bar+1]+High[bar+1]+Low[bar+1]+Close[bar+1])/4))/2);
  cwClose=(Open[bar]+High[bar]+Low[bar]+Close[bar])/4;
  cwHigh=High[bar];
  cwLow=Low[bar];
  cwChannelWidth=CW_PipMultiplier*(cwHigh-cwLow);  
  if(cwOpen<cwClose){
   cwUP[bar]=cwChannelWidth;
   cwDN[bar]=0;
  }else{
   cwUP[bar]=0;
   cwDN[bar]=cwChannelWidth;
  }
  cwPeriodMax = High[Highest(NULL,0,MODE_HIGH,CW_Periods,bar)];
  cwPeriodMin = Low[Lowest(NULL,0,MODE_LOW,CW_Periods,bar)];
  cwPeriodPips[bar]=CW_PipMultiplier*(cwPeriodMax-cwPeriodMin);  
 }
 return(0);
}

Comments