AltrTrend_Signal_v2_2_v4
Download scriptThis tool is designed to identify key trend reversals by analyzing price volatility and market strength. Instead of simply following the current price, it calculates specific "breakout zones" based on historical data to determine when a trend is likely shifting from bullish to bearish, or vice versa.
How the Logic Works
1. Measuring Market Strength The script begins by evaluating the current momentum of the market. It uses a specialized calculation to determine how "strong" the current trend is. Based on this strength, it dynamically decides how far back into the past it needs to look to find relevant price data. This ensures that in fast-moving markets, it looks at a smaller window of time, while in slow markets, it expands its view to maintain accuracy.
2. Defining Volatility and Price Ranges Once it knows the appropriate timeframe, the script calculates the "Average Range"—the average distance between the highest and lowest prices over that period. It then identifies the absolute highest and lowest points reached within that specific window. These figures establish the boundaries of the current price action.
3. Creating Breakout Thresholds The tool doesn't trigger a signal just because the price moves slightly. Instead, it creates two invisible "thresholds" (a maximum and a minimum) based on a user-defined percentage of the price range.
- Upper Threshold: A level above the recent highs.
- Lower Threshold: A level below the recent lows.
4. Signal Generation The script constantly monitors whether the closing price breaks through these thresholds:
- Bullish Signal (Green): When the price closes above the upper threshold, indicating a transition into an upward trend, a signal is generated.
- Bearish Signal (Crimson): When the price closes below the lower threshold, indicating a transition into a downward trend, a signal is generated.
5. Visual Execution To keep the chart clean and easy to read, the script identifies the exact moment these trend shifts occur. It places visual markers (arrows) at a specific distance from the price candle—calculated based on the volatility of the market—ensuring that the signals are clearly visible and not cluttered by the price bars themselves.
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2.mq4 |
//| Ramdass - Conversion only |
//+------------------------------------------------------------------+
#property copyright "Author - OlegVS, GOODMAN"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Crimson
//---- input parameters
extern int K = 30;
extern double Kstop = 0.5;
extern int Kperiod = 150;
extern int PerADX = 14;
extern int CountBars = 350;
//---- buffers
double val1[];
double val2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,108);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,108);
SetIndexBuffer(0,val1);
SetIndexBuffer(1,val2);
if(CountBars>=Bars)
CountBars=Bars;
SetIndexDrawBegin(0, Bars - CountBars + PerADX);
SetIndexDrawBegin(1, Bars - CountBars + PerADX);
//----
return(0);
}
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2 |
//+------------------------------------------------------------------+
int start()
{
int i, shift, counted_bars = IndicatorCounted();
int i1, i2;
double Range, AvgRange, smin, smax, SsMax, SsMin, SSP, price;
bool uptrend, old;
//----
if(Bars <= PerADX + 1)
return(0);
//---- initial zero
if(counted_bars < PerADX + 1)
{
for(i = 1; i <= PerADX; i++)
val1[CountBars - i] = 0.0;
for(i = 1; i <= PerADX; i++)
val2[CountBars-i] = 0.0;
}
//----
for(shift = CountBars - PerADX; shift >= 0; shift--)
{
SSP = MathCeil(Kperiod / iADX(NULL, 0, PerADX, PRICE_CLOSE, MODE_MAIN, 1));
Range = 0;
AvgRange = 0;
for(i1 = shift; i1 <= shift + SSP; i1++)
{
AvgRange = AvgRange + MathAbs(High[i1] - Low[i1]);
}
Range = AvgRange / (SSP + 1);
//----
SsMax = High[shift];
SsMin = Low[shift];
for(i2 = shift; i2 <= shift + SSP - 1; i2++)
{
price = High[i2];
if(SsMax < price)
SsMax = price;
price = Low[i2];
if(SsMin >= price)
SsMin = price;
}
//----
smin = SsMin + (SsMax - SsMin)*K / 100;
smax = SsMax - (SsMax - SsMin)*K / 100;
val1[shift] = 0;
val2[shift] = 0;
if(Close[shift] < smin)
{
uptrend = false;
}
if(Close[shift] > smax)
{
uptrend = true;
}
if(uptrend != old && uptrend == true)
{
val1[shift] = Low[shift] - Range*Kstop;
}
if(uptrend != old && uptrend == false)
{
val2[shift] = High[shift] + Range*Kstop;
}
old = uptrend;
}
return(0);
}
//+------------------------------------------------------------------+
Comments