VoltyChannel_Stop_v1M
Download scriptThis technical indicator is designed to help traders identify market trends and establish dynamic support and resistance levels based on market volatility. Instead of using fixed price points, it adapts to the "breath" of the market, making it useful for navigating different trading environments where price movements can vary significantly in intensity.
Core Logic and Mechanics
1. Volatility-Based Boundaries The script calculates a "channel" around the current price using the Average True Range (ATR). The ATR measures how much an asset typically moves over a specific period. By multiplying this value by a sensitivity factor, the tool creates upper and lower boundaries that expand during high volatility and contract during calm periods.
2. Trend Detection The logic determines the direction of the market by comparing the current closing price against these volatility boundaries:
- Upward Trend: Triggered when the price breaks above the previous upper boundary.
- Downward Trend: Triggered when the price breaks below the previous lower boundary.
3. Dynamic Trailing Stops One of the primary functions of this script is its "ratchet" logic for stops. When the market is in a trend, the indicator tracks the trailing stop level:
- In an Upward Trend, the stop level moves up but never moves down. It acts like a floor that only rises as new highs are reached.
- In a Downward Trend, the stop level moves down but never moves up. It acts like a ceiling that only drops as new lows are reached. This ensures that once a trend is identified, the "safety net" follows the price progress without being reset by minor temporary retracements.
4. Risk Offsetting The script includes a specific calculation to create a safety buffer (an offset) between the actual trend boundary and the visual stop line. This allows traders to separate the "active" trend zone from their intended exit point, providing an extra layer of protection based on the user's risk preference.
Visual Outputs
The tool provides three distinct layers of information on the chart:
- Trend Lines: Continuous lines that show the current "floor" or "ceiling" for the price action.
- Stop Levels: Visual markers showing where a trade might need to be closed if the trend reverses.
- Signals: Specific visual cues (arrows) that appear at the exact moment the trend shifts from bullish to bearish (or vice versa), highlighting the entry point of a new market move.
//+------------------------------------------------------------------+
//| 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);
}
Comments