Dyn_tr
Download scriptThis indicator is designed to help traders visualize market trends and identify potential entry points by tracking price movements relative to a dynamic price channel. Rather than using a static moving average, it creates a responsive "ceiling" and "floor" based on recent price extremes.
How the Logic Works
1. Trend Detection (The Dynamic Line) The core of this tool is a dynamic trend line that adjusts automatically based on whether the market is currently moving up or down. It looks back at a specific number of past candles (defined by the "MaxPeriod" setting) to identify the highest and lowest prices reached in that timeframe.
- In an Uptrend: If the current price falls below the previous trend line, the script identifies a shift. It then establishes a new "floor" based on the lowest price reached during the lookback period, adjusted by a small percentage offset.
- In a Downtrend: Conversely, if the price rises above the previous trend line, the script recognizes a move upward and sets a new "ceiling" based on the highest price reached in the lookback period, also adjusted by that same percentage offset.
2. Signal Generation (Buy and Sell Alerts) The indicator places visual markers on the chart to alert you when the price breaks through these dynamic levels. It looks for specific "crosses" where the price moves from one side of the trend line to the other:
- Buy Signals: These appear when the price was previously above the trend line but then drops significantly below it. The script detects this "breakdown" of the trend and places a marker to indicate a potential selling opportunity or a shift in momentum.
- Sell Signals: These appear when the price was previously below the trend line but then breaks upward through it. This identifies a "breakout" from the bottom, suggesting a potential buying opportunity or a new upward trend.
Summary for Traders
In simple terms, this script acts like a smart boundary tracker. It follows the "path of least resistance" in the market. When the price stays within the boundaries, the trend is considered intact. When the price punches through those boundaries, the indicator triggers an arrow to notify you that the trend may be changing or breaking out, allowing for quicker decision-making based on price action rather than just raw numbers.
// +------------------------------------------------------------------+
// | The percentage indicator basis on break |
// | of the dynamic price channel |
// | BDPC_Percent.mq4 |
// | Copyright © 2004, OfficeFX Group |
// | http: // officefx.nm.ru |
// +------------------------------------------------------------------+
#property copyright " Copyright © 2004, OfficeFX Group "
#property link " http:// officefx.nm.ru "
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 MediumOrchid // BUY signal
#property indicator_color2 Blue // BUY signal
#property indicator_color3 Red // SELL signal
//----Indicator Buffers--------------------------------------------+
double DynamicLineTrend []; // Data buffer for dynamic line trend
double BUYSignals []; // Data buffer for BUY signals
double SELLSignals []; // Data buffer for SELL signals //----User defines-------------------------------------------------
extern int Percent=1; // Percent dynamic channel 15 Main Trend 10
extern int MaxPeriod=14; // 12 FOR H1 Maximal period for calculate trend 50 Main Trend 89
//----Variables----------------------------------------------------+
int Shift=0; // Current bar for calculate trend //
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init ()
{
SetIndexStyle (0, DRAW_LINE);
SetIndexBuffer(0, DynamicLineTrend);
SetIndexStyle (1, DRAW_ARROW);
SetIndexArrow (1,233);
SetIndexBuffer(1, BUYSignals);
SetIndexStyle (2, DRAW_ARROW);
SetIndexArrow (2,234);
SetIndexBuffer(2, SELLSignals);
return (0);
}
//-------------------------------------------------------------------+
// +------------------------------------------------------------------+
// | Custom indicator iteration function |
// +------------------------------------------------------------------+
int start ()
{
// Get digits of Symbol
double point=MarketInfo (Symbol (), MODE_POINT);
// Set count bars for calculate trend
int Counted_Bars=IndicatorCounted ()-MaxPeriod;
//----Calculation DynamicLineTrend---------------------------------+
for ( Shift = Counted_Bars; Shift>=0; Shift--)
{
// Calculate of maximal period
if (Close [Shift] <DynamicLineTrend [Shift+1])
{
// Calculate Upper trend
DynamicLineTrend [Shift] =Close [Highest (NULL, 0, MODE_CLOSE, MaxPeriod, Shift+1)]-Percent*point;
}
if (Close [Shift]>=DynamicLineTrend [Shift+1])
{
// Calculate Down trend
DynamicLineTrend [Shift] =Close [Lowest (NULL, 0, MODE_CLOSE, MaxPeriod, Shift+1)] +Percent*point;
}
// Checkcrosses DynamicLineTrend and Price
if (Close [Shift+3]> DynamicLineTrend [Shift+2])
if (Close [Shift+2] <DynamicLineTrend [Shift+3])
BUYSignals [Shift] =Low [Shift]-10*point;
else
BUYSignals [Shift] =0;
else
BUYSignals [Shift] =0;
if (Close [Shift+2] <DynamicLineTrend [Shift+1])
if (Close [Shift+2]> DynamicLineTrend [Shift+3])
SELLSignals [Shift] =High [Shift]-10*point;
else
SELLSignals [Shift] =0;
else
SELLSignals [Shift] =0;
}
//-------------------------------------------------------------------+
return (0);
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comments