PriceChannel_Signal_v1

Download script
Author: Copyright � 2007, TrendLaboratory Ltd.
PriceChannel_Signal_v1

This Price Channel Signal tool is designed to help traders identify the prevailing market trend and pinpoint specific moments for potential buy or sell actions. Rather than just looking at raw price movement, it calculates a dynamic "trading range" based on recent historical highs and lows to determine when the market is breaking out in a new direction.

Core Logic and Trend Detection

The script works by constantly analyzing a specific period of recent price data (defined by the "Length" setting). For every candle on the chart, it identifies the highest high and the lowest low. It then creates a sophisticated "signal zone" using a risk factor. This allows the tool to calculate upper and lower boundaries; if the price closes above the upper boundary, the logic recognizes an upward trend. Conversely, if the price closes below the lower boundary, it registers a downward trend.

Entry Signals

The indicator translates these trend shifts into visual markers on your chart:

  • Initial Signals: When the market flips from a downward trend to an upward trend (or vice versa), the script places a signal arrow. These arrows are positioned based on the volatility of the market (using ATR), ensuring they stay clear of the price action for better visibility.
  • Re-Entry Logic: For experienced traders who want to join an existing trend, there is a specialized "Re-Entry" feature. This looks for instances where the price briefly pulls back but then breaks back out of the signal zone in the direction of the original trend. It identifies these "second chances" to enter a trade without needing to wait for a completely new trend reversal.

Smart Alerts

To keep traders informed without requiring them to watch the screen constantly, the script includes an automated alert system. It monitors real-time data and triggers notifications for:

  1. New Trend Signals: Notifies you immediately when a brand new Buy or Sell opportunity appears.
  2. Re-Entry Opportunities: If the Re-Entry mode is active, it will also alert you when a trend "re-confirms" after a minor pullback.

To prevent repetitive notifications, the script includes internal checks to ensure it only alerts you once per trend change and manages timing to avoid multiple pings on the same price movement.

Indicators Used
Moving average indicatorIndicator of the average true range
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
PriceChannel_Signal_v1
//+------------------------------------------------------------------+
//|                                       PriceChannel_Signal_v1.mq4 |
//|                           Copyright © 2007, TrendLaboratory Ltd. |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                   E-mail: igorad2003@yahoo.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Gold
#property indicator_color2 Gold
#property indicator_color3 Gold
#property indicator_color4 Gold
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1

//---- indicator parameters
extern int     Length         =  9;    // Price Channel Period
extern int     Applied_Price  =  0;    // Applied Price:0-C,1-O,2-H,3-L,4-Median,5-Typical,6-Weighted 
extern double  Risk           =  3;    // Risk Factor in units (0...10) 
extern int     UseReEntry     =  0;    // Re-Entry Mode: 0-off,1-on
extern int     AlertMode      =  1;    // Alert Mode: 0-off,1-on

//---- indicator buffers
double UpSignal[];
double DnSignal[]; 
double UpEntry[];
double DnEntry[]; 
double smax[];
double smin[];
double trend[];

bool   UpTrendAlert=false, DownTrendAlert=false;
datetime prevTime; 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   string short_name;
//---- drawing settings
   IndicatorBuffers(7);
      
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,108);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,108);
   SetIndexStyle(2,DRAW_ARROW);
   //SetIndexArrow(2,108);
   SetIndexStyle(3,DRAW_ARROW);
   //SetIndexArrow(3,108);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- indicator short name
   IndicatorShortName("PriceChannel_Signal("+Length+")");
   SetIndexLabel(0,"UpSignal");
   SetIndexLabel(1,"DnSignal");
   SetIndexLabel(2,"UpRe-Entry");
   SetIndexLabel(3,"DnRe-Entry");
   SetIndexDrawBegin(0,Length);
   SetIndexDrawBegin(1,Length);
   SetIndexDrawBegin(2,Length);
   SetIndexDrawBegin(3,Length);
//---- indicator buffers mapping
   SetIndexBuffer(0,UpSignal);
   SetIndexBuffer(1,DnSignal);
   SetIndexBuffer(2,UpEntry);
   SetIndexBuffer(3,DnEntry);
   SetIndexBuffer(4,smax);
   SetIndexBuffer(5,smin);
   SetIndexBuffer(6,trend);
   
//---- initialization done
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int limit;
   if(Bars<=Length) return(0);
   int CountedBars=IndicatorCounted();
//---- check for possible errors
   if (CountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (CountedBars>0) CountedBars--;
   limit=Bars-CountedBars;
//---- 
   for(int i=limit; i>=0; i--)
   { 
   double price  = iMA(NULL,0,1,0,0,Applied_Price,i);
   double price1 = iMA(NULL,0,1,0,0,Applied_Price,i+1);
   double price2 = iMA(NULL,0,1,0,0,Applied_Price,i+2);
         
   double hi = High[iHighest(NULL,0,MODE_HIGH,Length,i)];   
   double lo = Low[iLowest(NULL,0,MODE_LOW,Length,i)];
   
   smax[i] = hi - (33-Risk)*(hi-lo)/100;
   smin[i] = lo + (33-Risk)*(hi-lo)/100;
   
   trend[i]=trend[i+1]; 
	   
	if ( price > smax[i])  trend[i]=1; 
	if ( price < smin[i])  trend[i]=-1;

      if(trend[i]>0)
	   {
	   if (trend[i+1]<0) UpSignal[i] = Low[i]-0.5*iATR(NULL,0,Length,i);
	   if (UseReEntry > 0 && price > smax[i] && price1 <= smax[i+1]) UpEntry[i] = Low[i]-0.5*iATR(NULL,0,Length,i); 
	   DnSignal[i]=EMPTY_VALUE; DnEntry[i]=EMPTY_VALUE;
	   }
	   else
	   if(trend[i]<0)
	   {
	   if (trend[i+1]>0) DnSignal[i] = High[i]+0.5*iATR(NULL,0,Length,i);
	   if (UseReEntry > 0 && price < smin[i] && price1 >= smin[i+1]) DnEntry[i] = High[i]+0.5*iATR(NULL,0,Length,i); 
	   UpSignal[i]=EMPTY_VALUE; UpEntry[i]=EMPTY_VALUE;
	   }
   	         
//----------   
      if (i==0 && AlertMode > 0)
      {
         if (trend[i+1] > 0 && Volume[0]>1)
         {
            if (trend[i+2]<0 && !UpTrendAlert)
	         {
	         string Message = " "+Symbol()+" M"+Period()+": Signal for BUY";
	         Alert (Message); 
	         UpTrendAlert=true; DownTrendAlert=false;
	         } 
	      
	         if (UseReEntry>0 && trend[i+2]>0 && price1 > smax[i+1] && price2 < smax[i+2] && Time[i]!=prevTime)
	         {
	         Message = " "+Symbol()+" M"+Period()+": Re-Entry for BUY";
	         Alert (Message);
	         prevTime = Time[i];
	         }
	      }
	      else
	      if (trend[i+1] < 0 && Volume[0]>1)
	      {
            if ( trend[i+2]>0 && !DownTrendAlert)
	         {
	         Message = " "+Symbol()+" M"+Period()+": Signal for SELL";
	         Alert (Message); 
	         DownTrendAlert=true; UpTrendAlert=false;     
	         }
	         
	         if (UseReEntry>0 && trend[i+2]<0 && price1 < smin[i+1] && price2 > smin[i+2] && Time[i]!=prevTime)
	         {
	         Message = " "+Symbol()+" M"+Period()+": Re-Entry for SELL";
	         Alert (Message);
	         prevTime = Time[i];
	         }
	      } 	  
      }	
	} 	         

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

Comments