PriceChannel_Stop_v1.3

Download script
Author: Copyright � 20006-08, Forex-TSD.com
PriceChannel_Stop_v1.3

This tool is designed to help traders identify the prevailing market trend and pinpoint specific entry signals by monitoring price movements within a defined range. Instead of simply looking at where the price is now, it analyzes the relationship between high and low prices over a set period to create a "dynamic corridor."

How the Logic Works

1. Defining the Price Corridor The script looks back at a specific number of candles (the "Channel Period") to identify the highest peak and the lowest valley reached during that time. It then uses a "Risk" factor to calculate two internal boundary lines. Think of these as safety zones; they are positioned based on how much the price has fluctuated recently, creating a corridor that adjusts automatically as market volatility changes.

2. Trend Detection The script determines the direction of the market by comparing the current closing price against the boundaries established in the previous period:

  • Bullish Trend: If the price closes above the upper boundary of the previous period, the system recognizes an upward trend.
  • Bearish Trend: If the price closes below the lower boundary of the previous period, the system recognizes a downward trend.

3. Dynamic Price Tracking Once a trend is established, the script tracks it continuously. For example, in an uptrend, it monitors the "floor" of the price movement. It ensures that these lines only move in a direction that confirms the trend (e.g., during an uptrend, it will hold onto a higher floor rather than letting it drop), providing a visual trailing stop-loss effect on your chart.

4. Signal Generation and Alerts The core utility of this script is its ability to identify "trend flips." When the price breaks from a downward trend into an upward trend (or vice versa), the script generates a specific signal.

To keep you informed without needing to watch the screen constantly, the logic includes several notification layers:

  • Visual Cues: It can display arrows or lines directly on your chart to mark exactly where a trend shift occurred.
  • Real-time Alerts: It can trigger an instant pop-up alert on your trading platform.
  • Email Notifications: If enabled, it can send an automated email to your inbox the moment a "Buy" or "Sell" signal is confirmed, based on a confirmed trend reversal and active trading volume.

Summary for the User

In simple terms, this script filters out market "noise" by focusing on sustained price action. It tells you when the market has moved far enough in one direction to be considered a new trend and warns you immediately when that trend reverses, allowing for more disciplined entries and exits.

Price Data Components
Series array that contains open time of each bar
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
PriceChannel_Stop_v1.3
//+------------------------------------------------------------------+
//|                                       PriceChannel_Stop_v1.3.mq4 |
//|                               Copyright © 2006-08, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 20006-08, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Magenta
#property indicator_color3 Aqua
#property indicator_color4 Magenta

//---- input parameters
extern int    ChannelPeriod=     9; //Price Channel Period
extern double Risk         =  0.30; //Channel narrowing factor (0...0,5)
extern int    SignalMode   =     1; //0-Signal off,1-on
extern int    AlertMode    =     0; //0-alert off,1-on
extern int    VisualMode   =     0; //0-lines,1-dots 
extern int    EmailMode    =     0; //0-Email off,1-on 

//extern int Nbars=1000;
//---- indicator buffers
double UpBuffer[];
double DnBuffer[];
double UpSignal[];
double DnSignal[];
double smin[];
double smax[];
double trend[];

bool UpTrendAlert=false, DnTrendAlert=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(7);
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
   SetIndexBuffer(2,UpSignal);
   SetIndexBuffer(3,DnSignal);
   SetIndexBuffer(4,smin);
   SetIndexBuffer(5,smax);
   SetIndexBuffer(6,trend);
      if(VisualMode==0)
      {
      SetIndexStyle(0,DRAW_LINE);
      SetIndexStyle(1,DRAW_LINE);
      }
      else
      {
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(0,159);
      SetIndexArrow(1,159);
      }
   
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(2,108);
   SetIndexArrow(3,108);
//---- name for DataWindow and indicator subwindow label
   short_name="PriceChannel_Stop_v1.3("+ChannelPeriod+","+DoubleToStr(Risk,3)+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"UpTrend");
   SetIndexLabel(1,"DnTrend");
   SetIndexLabel(2,"UpSignal");
   SetIndexLabel(3,"DnSignal");
//----
   SetIndexDrawBegin(0,ChannelPeriod);
   SetIndexDrawBegin(1,ChannelPeriod);
   SetIndexDrawBegin(2,ChannelPeriod);
   SetIndexDrawBegin(3,ChannelPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| PriceChannel_Stop_v1.3                                             |
//+------------------------------------------------------------------+
int start()
  {
   int    i,shift, counted_bars=IndicatorCounted(),limit;
   double hi, lo, price;
  
   string Message;
   
   if ( counted_bars > 0 )  limit=Bars-counted_bars;
   if ( counted_bars < 0 )  return(0);
   if ( counted_bars ==0 )  limit=Bars-ChannelPeriod-1; 
   
   if ( counted_bars < 1 ) 
   for(i=1;i<ChannelPeriod;i++)
   { 
   UpBuffer[shift]=EMPTY_VALUE;
   DnBuffer[shift]=EMPTY_VALUE;
   UpSignal[shift]=EMPTY_VALUE;
   DnSignal[shift]=EMPTY_VALUE;
   }
   
   for (shift=limit;shift>=0;shift--)
   {	
   lo = Low[iLowest(NULL,0,MODE_LOW,ChannelPeriod,shift)];    
   hi = High[iHighest(NULL,0,MODE_HIGH,ChannelPeriod,shift)];
     
   smax[shift] = hi - (hi-lo)*Risk;
   smin[shift] = lo + (hi-lo)*Risk;
     
   trend[shift]=trend[shift+1];
   if (Close[shift] > smax[shift+1]) trend[shift]= 1; 
	if (Close[shift] < smin[shift+1]) trend[shift]=-1;
		  		
      if(trend[shift] > 0)
      {
         if(smin[shift] < smin[shift+1]) smin[shift] = smin[shift+1];
      UpBuffer[shift] = smin[shift];
	      if (SignalMode > 0 && trend[shift+1] != trend[shift]) UpSignal[shift] = smin[shift];
	      else UpSignal[shift] = EMPTY_VALUE;
	      if (SignalMode == 2) UpBuffer[shift] = EMPTY_VALUE;
	   DnBuffer[shift] = EMPTY_VALUE;
	   DnSignal[shift] = EMPTY_VALUE;
	   }
	   else
	   if(trend[shift] < 0)
	   {
         if(smax[shift] > smax[shift+1]) smax[shift] = smax[shift+1];
      DnBuffer[shift] = smax[shift];
         if(SignalMode > 0 && trend[shift+1] != trend[shift]) DnSignal[shift] = smax[shift];
	      if(SignalMode == 2) DnBuffer[shift] = EMPTY_VALUE;
	   UpBuffer[shift] = EMPTY_VALUE;
	   UpSignal[shift] = EMPTY_VALUE;
	   }
   }

   if(trend[2]<0 && trend[1]>0 && Volume[0]>1 && !UpTrendAlert)
	{
	Message = " "+Symbol()+" M"+Period()+": Signal for BUY";
      if(AlertMode > 0) Alert (Message); 
      if(EmailMode > 0) SendMail ("Signal from PriceChannel_Stop",TimeToStr(CurTime())+Message);
	UpTrendAlert=true; DnTrendAlert=false;
	} 
	else 	  
	if(trend[2]>0 && trend[1]<0 && Volume[0]>1 && !DnTrendAlert)
	{
	Message = " "+Symbol()+" M"+Period()+": Signal for SELL";
      if ( AlertMode > 0) Alert (Message); 
	   if ( EmailMode > 0) SendMail ("Signal from PriceChannel_Stop",TimeToStr(CurTime())+Message);
	DnTrendAlert=true; UpTrendAlert=false;
	} 
	 
   
   return(0);
}
//+------------------------------------------------------------------+

Comments