VoltyChannel_Stop_v1M





//+------------------------------------------------------------------+
//|                                         VoltyChannel_Stop_v1.mq4 |
//|                           Copyright © 2005, TrendLaboratory Ltd. |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                       E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
//mod2008txtsd
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 LawnGreen
#property indicator_color2 Gold
#property indicator_color3 Chartreuse
#property indicator_color4 Orange
#property indicator_color5 SpringGreen
#property indicator_color6 DarkOrange

//---- input parameters
extern int    ATRLength =10;      // Length,Volatility(ATR)Period
extern double Kv =1.00;           // Sensivity Factor
extern double MoneyRisk =1.00;    // Offset Factor
extern bool   ShowSignal =true;         
extern bool   ShowStops  =true;          
extern bool   ShowLine   =true;          

extern int    Nbars =1000;

//---- indicator buffers
double UpTrendBuffer[];
double DownTrendBuffer[];
double UpTrendSignal[];
double DownTrendSignal[];
double UpTrendLine[];
double DownTrendLine[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   
   SetIndexBuffer(0,UpTrendBuffer);
   SetIndexBuffer(1,DownTrendBuffer);
   SetIndexBuffer(2,UpTrendSignal);
   SetIndexBuffer(3,DownTrendSignal);
   SetIndexBuffer(4,UpTrendLine);
   SetIndexBuffer(5,DownTrendLine);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);
   SetIndexArrow(2,108);
   SetIndexArrow(3,108);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   short_name="VoltyChannel Stop("+ATRLength+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"UpTrend Stop");
   SetIndexLabel(1,"DownTrend Stop");
   SetIndexLabel(2,"UpTrend Signal");
   SetIndexLabel(3,"DownTrend Signal");
   SetIndexLabel(4,"UpTrend Line");
   SetIndexLabel(5,"DownTrend Line");
//----
   SetIndexDrawBegin(0,ATRLength);
   SetIndexDrawBegin(1,ATRLength);
   SetIndexDrawBegin(2,ATRLength);
   SetIndexDrawBegin(3,ATRLength);
   SetIndexDrawBegin(4,ATRLength);
   SetIndexDrawBegin(5,ATRLength);
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| VoltyChannel_Stop_v1                                             |
//+------------------------------------------------------------------+
int start()
  {
   int    i,shift,trend;
   double smax[25000],smin[25000],bsmax[25000],bsmin[25000];
   
   for (shift=Nbars;shift>=0;shift--)
   {
   UpTrendBuffer[shift]=0;
   DownTrendBuffer[shift]=0;
   UpTrendSignal[shift]=0;
   DownTrendSignal[shift]=0;
   UpTrendLine[shift]=EMPTY_VALUE;
   DownTrendLine[shift]=EMPTY_VALUE;
   }
   
   for (shift=Nbars-ATRLength-1;shift>=0;shift--)
   {	
     smax[shift]=Close[shift]+Kv*iATR(NULL,0,ATRLength,shift);
	  smin[shift]=Close[shift]-Kv*iATR(NULL,0,ATRLength,shift);
	
	  if (Close[shift]>smax[shift+1]) trend=1; 
	  if (Close[shift]<smin[shift+1]) trend=-1;
		 	
	  if(trend>0 && smin[shift]<smin[shift+1]) smin[shift]=smin[shift+1];
	  if(trend<0 && smax[shift]>smax[shift+1]) smax[shift]=smax[shift+1];
	  	  
	  bsmax[shift]=smax[shift]+(MoneyRisk-1)*iATR(NULL,0,ATRLength,shift);
	  bsmin[shift]=smin[shift]-(MoneyRisk-1)*iATR(NULL,0,ATRLength,shift);
		
	  if(trend>0 && bsmin[shift]<bsmin[shift+1]) bsmin[shift]=bsmin[shift+1];
	  if(trend<0 && bsmax[shift]>bsmax[shift+1]) bsmax[shift]=bsmax[shift+1];
	  


	  if (trend>0) 
	  {
	     if (UpTrendBuffer[shift+1]==-1.0)
	        {
	        if(ShowSignal) UpTrendSignal[shift]=bsmin[shift];
	        if(ShowStops)  UpTrendBuffer[shift]=bsmin[shift];
	        if(ShowLine)   UpTrendLine[shift]=  bsmin[shift];
	        }
	     else
	        {
	        if(ShowSignal) UpTrendSignal[shift]=-1;
	        if(ShowStops)  UpTrendBuffer[shift]=bsmin[shift];
	        if(ShowLine)   UpTrendLine[shift]=  bsmin[shift];
	        }
    
         DownTrendSignal[shift]=-1;
         DownTrendBuffer[shift]=-1.0;
         DownTrendLine[shift]=EMPTY_VALUE;
	   }


	  if (trend<0) 
      {
	     if (DownTrendBuffer[shift+1]==-1.0)
	        {
	        if(ShowSignal) DownTrendSignal[shift]=bsmax[shift];
	        if(ShowStops)  DownTrendBuffer[shift]=bsmax[shift];
	        if(ShowLine)   DownTrendLine[shift]=  bsmax[shift];
	        }
	     else 	     
	        {
	        if(ShowSignal) DownTrendSignal[shift]=-1;
	        if(ShowStops)  DownTrendBuffer[shift]=bsmax[shift];
	        if(ShowLine)   DownTrendLine[shift]=  bsmax[shift];
	        }
	     
         UpTrendSignal[shift]=-1;
         UpTrendBuffer[shift]=-1.0;
         UpTrendLine[shift]=EMPTY_VALUE;
      }
	  

	 }
	return(0);	
 }





Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:


Implements a curve of type DRAW_ARROW
Implements a curve of type DRAW_LINE

Indicators Used:

Indicator of the average true range


Custom Indicators Used:

Order Management characteristics:

Other Features: