AltrTrend_Signal_v2_2_v2

Download script
AltrTrend_Signal_v2_2_v2

This tool is designed to identify significant shifts in market momentum by detecting when the price breaks out of specific established trading ranges. Rather than just following every minor price fluctuation, the logic focuses on identifying "trend reversals"—moments where the market transitions from a period of consolidation into a clear upward or downward movement.

How the Logic Works

The script operates through a multi-step calculation process to determine where the "ceiling" and "floor" of the current price action lie:

1. Dynamic Range Measurement The tool first looks at the Average Directional Index (ADX) to understand the current strength of the market trend. Based on this strength, it calculates a dynamic look-back period. It then measures the historical volatility within that timeframe to establish a "Range" value. This ensures that the signals adapt to different market conditions—tightening during stable periods and widening during highly volatile ones.

2. Identifying Support and Resistance Zones Within the calculated look-back window, the script identifies the highest price reached (the peak) and the lowest price reached (the trough). It then uses these two points to create a "buffer zone." By applying a specific percentage offset, the tool defines a threshold for what constitutes a breakout:

  • The Upper Boundary: A price level slightly below the recent peak.
  • The Lower Boundary: A price level slightly above the recent trough.

3. Detecting Trend Transitions The script constantly monitors whether the current closing price has breached these boundaries.

  • If the price closes above the high-side threshold, it registers a potential Uptrend.
  • If the price closes below the low-side threshold, it registers a potential Downtrend.

Visual Signals

To keep the chart clean and actionable, the tool does not provide a constant line or color. Instead, it only places a visual marker (an arrow) at the exact moment a trend shift is confirmed.

  • Green Markers: Appear when the price breaks out to the upside, signaling a transition into an upward trend.
  • Crimson Markers: Appear when the price breaks out to the downside, signaling a transition into a downward trend.

Summary for the User

Essentially, this script filters out "market noise" by calculating the relative highs and lows of recent price action. It waits for the price to decisively break out of those boundaries before notifying you with a visual signal, helping you identify when a new trend is officially beginning.

Indicators Used
Movement directional index
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
AltrTrend_Signal_v2_2_v2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| 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);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| AltrTrend_Signal_v2_2                                            |
//+------------------------------------------------------------------+
int start()
  {   
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+PerADX);
   SetIndexDrawBegin(1,Bars-CountBars+PerADX);
   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