PriceChannel_Stop_v1_v1

Download script
Author: Copyright � 2005, TrendLaboratory Ltd.
PriceChannel_Stop_v1_v1

The PriceChannel_Stop_v1 is a technical analysis tool designed to help traders identify the prevailing market direction and pinpoint specific price levels where a trend might be considered "broken" or reversed. By analyzing price movement over a defined period, it creates a dynamic boundary that adjusts as the market moves.

Core Logic and Functionality

The script operates by monitoring the highest highs and lowest lows within a specific window of recent price bars (defined by the "ChannelPeriod"). Based on these extremes, it calculates a mathematical "risk zone" to establish boundaries for both upward and downward trends.

1. Trend Detection The tool constantly evaluates whether the current market price is breaking above or below its calculated risk boundaries:

  • Bullish Trend: Triggered when the price closes above a specific upper threshold.
  • Bearish Trend: Triggered when the price closes below a specific lower threshold.

2. Dynamic Boundary Management Unlike static lines, these boundaries are "sticky" and intelligent. When the market is in an uptrend, the tool looks for the strongest floor; if a new potential floor is higher than the previous one, it holds that higher level. Conversely, in a downtrend, it tracks the strongest ceiling. This ensures that the trend line remains relevant to the most significant price levels rather than fluctuating wildly with minor noise.

3. Visual Signals and Line Mapping The script provides three distinct visual outputs on your chart:

  • Trend Lines: These provide a continuous visual of the current "Stop" level—essentially the price point where a trend would be considered invalidated.
  • Trend Stops (Arrows): The tool identifies specific points where the trend is established or confirmed.
  • Signals: Depending on your settings, the script can highlight specific entries or alerts when the price interacts with these boundaries in a way that suggests a potential reversal or a continuation of the current move.

How it Helps the Trader

Essentially, this tool acts as an automated "trend guard." It filters out minor price fluctuations and focuses on significant structural shifts. By providing clear visual cues for both Upward and Downward trends, it helps you:

  • Identify the current market bias at a glance.
  • Determine logical areas to place stop-loss orders.
  • Visualize where a trend is likely to end if the price fails to maintain its momentum.
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
PriceChannel_Stop_v1_v1
//+------------------------------------------------------------------+
//|                                         PriceChannel_Stop_v1.mq4 |
//|                           Copyright © 2005, TrendLaboratory Ltd. |
//|                                       E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link      "E-mail: igorad2004@list.ru"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Red
//---- input parameters
extern int ChannelPeriod=9;
extern double Risk=0.30;
extern int Signal=1;
extern int Line=1;
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);
//---- name for DataWindow and indicator subwindow label
   short_name="PriceChannel_Stop_v1("+ChannelPeriod+")";
   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,ChannelPeriod);
   SetIndexDrawBegin(1,ChannelPeriod);
   SetIndexDrawBegin(2,ChannelPeriod);
   SetIndexDrawBegin(3,ChannelPeriod);
   SetIndexDrawBegin(4,ChannelPeriod);
   SetIndexDrawBegin(5,ChannelPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| PriceChannel_Stop_v1                                             |
//+------------------------------------------------------------------+
int start()
  {
   int    i,shift,trend;
   double high, low, price;
   double smax[5000],smin[5000],bsmax[5000],bsmin[5000];
   
   for (shift=Nbars-1;shift>=0;shift--)
   {
   UpTrendBuffer[shift]=EMPTY_VALUE;
   DownTrendBuffer[shift]=EMPTY_VALUE;
   UpTrendSignal[shift]=EMPTY_VALUE;
   DownTrendSignal[shift]=EMPTY_VALUE;
   UpTrendLine[shift]=EMPTY_VALUE;
   DownTrendLine[shift]=EMPTY_VALUE;
   }
   for (shift=Nbars-ChannelPeriod-1;shift>=0;shift--)
   {	
      high=High[shift]; low=Low[shift]; i=shift-1+ChannelPeriod;
      while(i>=shift)
        {
         price=High[i];
         if(high<price) high=price;
         price=Low[i];
         if(low>price)  low=price;
         i--;
        } 
     smax[shift]=high;
     smin[shift]=low;
     
     bsmax[shift]=smax[shift]-(smax[shift]-smin[shift])*Risk;
	  bsmin[shift]=smin[shift]+(smax[shift]-smin[shift])*Risk;
     
     if (Close[shift]>bsmax[shift+1])  trend=1; 
	  if (Close[shift]<bsmin[shift+1])  trend=-1;
		  		
	  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 (Signal>0 && UpTrendBuffer[shift+1]==-1.0)
	     {
	     UpTrendSignal[shift]=bsmin[shift];
	     if(Line>0) UpTrendLine[shift]=bsmin[shift];
	     }
	     else
	     {
	     UpTrendBuffer[shift]=bsmin[shift];
	     if(Line>0) UpTrendLine[shift]=bsmin[shift];
	     UpTrendSignal[shift]=-1;
	     }
	  if (Signal==2) UpTrendBuffer[shift]=0;   
	  DownTrendBuffer[shift]=-1.0;
	  DownTrendLine[shift]=EMPTY_VALUE;
	  }
	  if (trend<0) 
	  {
	  if (Signal>0 && DownTrendBuffer[shift+1]==-1.0)
	     {
	     DownTrendSignal[shift]=bsmax[shift];
	     if(Line>0) DownTrendLine[shift]=bsmax[shift];
	     }
	     else
	     {
	     DownTrendBuffer[shift]=bsmax[shift];
	     if(Line>0)DownTrendLine[shift]=bsmax[shift];
	     DownTrendSignal[shift]=-1;
	     }
	  if (Signal==2) DownTrendBuffer[shift]=0;    
	  UpTrendBuffer[shift]=-1.0;
	  UpTrendLine[shift]=EMPTY_VALUE;
	  }
	  
	 
   }
   return(0);
  }
//+------------------------------------------------------------------+

Comments