AltrTrend_v1

Download script
AltrTrend_v1

This script is designed as a visual trend-following tool for trading charts. Its primary purpose is to identify the prevailing direction of the market by analyzing price action and volatility relative to historical data.

Core Logic Overview

The indicator operates by evaluating how current prices relate to a dynamic "zone" of high and low values within a specific timeframe. Here is a breakdown of how it processes this information:

1. Dynamic Time Window Adjustment Rather than using a fixed number of bars for every calculation, the script uses an Average Directional Index (ADX) logic to determine a variable look-back period. This means the indicator adapts to market conditions; when the market is trending strongly or weakly, it adjusts how much historical data it looks at to define the current trend.

2. Price Range and Volatility Analysis For every point on the chart, the script calculates the average price range (the distance between the highest and lowest prices) over the determined look-back period. By understanding the "normal" volatility of the asset, the tool can better distinguish between standard market noise and significant trend movements.

3. Dynamic Support and Resistance Boundaries The logic identifies the highest high and the lowest low within that variable window. It then calculates two specific threshold values:

  • A lower boundary (smin) based on the bottom of the range.
  • An upper boundary (smax) based on the top of the range.

These boundaries are not static; they are influenced by a sensitivity percentage (the K parameter), which allows the user to define how "aggressive" or "conservative" the trend detection should be.

4. Trend Identification and Visual Output The final decision-making step compares the current closing price against these calculated boundaries:

  • Bearish Signal: If the price closes below the lower boundary, the script identifies a downward move and reflects this visually on the chart using Crimson colors.
  • Bullish Signal: If the price closes above the upper boundary, it identifies an upward move and reflects this using Green colors.

Summary for Traders

Essentially, this tool filters out minor price fluctuations to highlight significant breakouts. By checking if the price has broken outside of a dynamically calculated "normal" range, it provides a visual representation of when the market is entering a sustained trend, helping traders stay on the right side of the momentum.

Indicators Used
Movement directional index
Miscellaneous
Implements a curve of type %1
17 Views
0 Downloads
0 Favorites
AltrTrend_v1
//+------------------------------------------------------------------+
//| AltrTrend.mq4 
//| Ramdass - Conversion only
//+------------------------------------------------------------------+
#property  copyright "Author - OlegVS, GOODMAN"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Crimson
#property indicator_color3 Green
#property indicator_color4 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[];
double val3[];
double val4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM,0,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,2);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,2);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,2);
   SetIndexBuffer(0,val1);
   SetIndexBuffer(1,val2);
   SetIndexBuffer(2,val3);
   SetIndexBuffer(3,val4);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| AltrTrend                                                        |
//+------------------------------------------------------------------+
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;
//----
   if(Bars<=PerADX+1) return(0);
//---- initial zero
   if(counted_bars<SSP+1)
   {
      for(i=1;i<=PerADX;i++) val1[CountBars-i]=0.0;
      for(i=1;i<=PerADX;i++) val2[CountBars-i]=0.0;
      for(i=1;i<=PerADX;i++) val3[CountBars-i]=0.0;
      for(i=1;i<=PerADX;i++) val4[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;
	val3[shift]=0;
	val4[shift]=0;
	if (Close[shift]<smin)
		{
		val1[shift]=Low[shift]; val2[shift]=High[shift];
		}
	if (Close[shift]>smax)
		{
		val3[shift]=High[shift]; val4[shift]=Low[shift];
		}

}
   return(0);
  }
//+------------------------------------------------------------------+

Comments