dex_2Trales_V1
Download scriptThis indicator is designed to provide visual guidance for traders by plotting two dynamic boundary lines on a price chart. These lines act as a "map" of price action, helping to identify the prevailing trend and potential volatility shifts in real-time.
Core Logic Overview
The tool functions by calculating a baseline range based on historical daily data and then adjusting that range dynamically as new price information becomes available. It focuses on two main components:
1. The Daily Foundation At the start of each new day (specifically at midnight), the script looks back at previous daily candles to determine the overall market "swing." It calculates the distance between the highest highs and lowest lows for several preceding periods (specifically 1, 5, 10, and 20 days). By averaging these values, the tool establishes a foundational range. This range is then split in half to create two starting points: an upper boundary and a lower boundary relative to the current closing price.
2. Dynamic Adjustments Throughout the rest of the trading day, the indicator does not remain static. It constantly monitors three specific conditions to decide whether to move the boundaries:
- Price Movement: It checks if the current candle's high and low are lower than the previous candle (indicating downward momentum) or higher (indicating upward momentum).
- Volatility Expansion: It measures market volatility using either Standard Deviation or the Average True Range (ATR). It specifically looks for moments where volatility is increasing compared to the previous period.
- Cumulative Tracking: If both a specific price direction and an increase in volatility are detected, the boundaries "stretch" or "contract" to follow that movement.
Visual Interpretation
- Upper Boundary (Blue): This line tracks the upper limits of the market's reach. It will move downward if the price shows aggressive bearish momentum combined with rising volatility.
- Lower Boundary (Red): This line tracks the lower limits. It will move upward if the price shows aggressive bullish momentum combined with rising volatility.
In simpler terms, the script creates a "cushion" around the price. When the market is stable, these boundaries remain relatively consistent. However, when the market begins to move aggressively in a specific direction with high energy, the boundaries shift to reflect that new reality, providing a visual representation of the market's stretching limits.
//+------------------------------------------------------------------+
//| dex_2TralesV1.mq4 |
//| Copyright © 2007, akadex. |
//| tohell |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, akadex"
#property link "tohell"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue //up
#property indicator_color2 Red //down
extern int PerDev=12;
extern bool StdDev_Atr=true;
extern int CountBars=3000;
double ExtMapBuffer1[]; // up
double ExtMapBuffer2[]; // down
double Amp[],AmpTemp[],D,D1,D5,D10,D20,Dev,Dev1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
IndicatorBuffers(4);
//---- drawing settings
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(0,0,0,1);
SetIndexLabel(0,"Up");
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(1,0,0,1);
SetIndexLabel(1,"Down");
SetIndexBuffer(2,Amp);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(3,AmpTemp);
SetIndexStyle(3,DRAW_NONE);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars);
SetIndexDrawBegin(1,Bars-CountBars);
int i;
int counted_bars=IndicatorCounted();
i=CountBars-1;
int loopbegin = Bars-1;
for(i = loopbegin; i >= 0; i--)
{
if (TimeHour(Time[i])==1 && TimeMinute(Time[i])==00) {
D1=(iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1));
D5=(iHigh(NULL,PERIOD_D1,5)-iLow(NULL,PERIOD_D1,5));
D10=(iHigh(NULL,PERIOD_D1,10)-iLow(NULL,PERIOD_D1,10));
D20=(iHigh(NULL,PERIOD_D1,20)-iLow(NULL,PERIOD_D1,20));
D=(D1+D5+D10+D20)/4;
ExtMapBuffer1[i]=Close[i]+(D/2);
ExtMapBuffer2[i]=Close[i]-(D/2);
}
else
{
if (StdDev_Atr){
Dev=iStdDev(NULL,0,PerDev,MODE_EMA,0,PRICE_CLOSE,i);
Dev1=iStdDev(NULL,0,PerDev,MODE_EMA,0,PRICE_CLOSE,i+1);
} else {
Dev=iATR(NULL,0,PerDev,i);
Dev1=iATR(NULL,0,PerDev,i+1);
}
if (High[i]<High[i+1] && Low[i]<Low[i+1] && Dev>Dev1) {ExtMapBuffer1[i]=ExtMapBuffer1[i+1]-((High[i+1]-High[i]));}
else {ExtMapBuffer1[i]=ExtMapBuffer1[i+1];}
if (Low[i]>Low[i+1] && High[i]>High[i+1] && Dev>Dev1) {ExtMapBuffer2[i]=ExtMapBuffer2[i+1]+((Low[i]-Low[i+1]));}
else {ExtMapBuffer2[i]=ExtMapBuffer2[i+1];}
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments