ASCTrend1_v1
Download scriptThis script is a visual technical analysis tool designed to identify and highlight potential trend shifts in financial markets. Rather than relying on simple price movement, it uses a sophisticated logic that combines volatility measurement with momentum tracking to determine when the market is entering a "trend" state.
Core Logic Overview
The indicator operates by analyzing the relationship between current price action and historical extremes over a specific window of time. Here is how it processes information:
1. Volatility and Range Analysis The script first calculates the "Average Range" of the market. It looks at the difference between the highest and lowest prices over the most recent 10 candles. This establishes a baseline for what constitutes "normal" movement in the current environment.
2. Identifying Significant Price Action Once the average range is established, the script searches for two specific types of significant movements:
- Gap/Jump Detection: It looks for instances where the price "jumps" significantly (specifically, a gap larger than double the average range) between consecutive candles.
- Momentum Bursts: It looks for rapid price surges where the price closes significantly higher or lower than it was several bars prior (specifically, a move larger than 4.6 times the average range).
3. Dynamic Sensitivity Adjustment The "Risk" and "CountBars" settings allow the user to tune how aggressive the indicator is. Based on whether the script detects those significant jumps or momentum bursts mentioned above, it dynamically adjusts its internal sensitivity. If the market is calm, the indicator stays in a "waiting" mode; if it detects a sudden burst of energy, it narrows its focus to react more quickly.
4. Momentum Filtering (WPR Integration) To filter out "noise," the script utilizes a Weighted Price Ratio (WPR) calculation. This helps determine where the current price sits relative to its recent highs and lows. By taking the inverse of this value, the indicator can tell if the market is overextended or moving with strength.
Visual Output
The final result is displayed on your chart as two distinct color-coded histograms (Magenta and Aqua):
- Trend Identification: When the momentum reaches a specific threshold defined by the risk parameters, the script "locks in" a trend direction.
- Dynamic Highs and Lows: Depending on whether the momentum is bullish or bearish, the script will flip which price point it highlights. For example, in an upward trend, it focuses on one set of extremes; if the trend flips, it instantly switches to highlight the opposite extreme.
Essentially, this tool acts as a filter that ignores minor market fluctuations and only highlights the "true" highs and lows once the market has proven it has enough momentum to sustain a meaningful move.
//+------------------------------------------------------------------+
//| ASCTrend1
//| Ramdass - Conversion only
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Aqua
//---- input parameters
extern int RISK=3;
extern int CountBars=300;
//---- buffers
double val1[];
double val2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_HISTOGRAM,0,2);
SetIndexStyle(1,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(0,val1);
SetIndexBuffer(1,val2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| ASCTrend1 |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars+11+1);
SetIndexDrawBegin(1,Bars-CountBars+11+1);
int i,shift,counted_bars=IndicatorCounted();
int Counter,i1,value10,value11;
double value1,x1,x2;
double value2,value3;
double TrueCount,Range,AvgRange,MRO1,MRO2;
value10=3+RISK*2;
x1=67+RISK;
x2=33-RISK;
value11=value10;
//----
if(Bars<=value11+1) return(0);
//---- initial zero
if(counted_bars<value11+1)
{
for(i=1;i<=0;i++) val1[CountBars-i]=0.0;
for(i=1;i<=0;i++) val2[CountBars-i]=0.0;
}
//----
shift=CountBars-11-1;
while(shift>=0)
{
Counter=shift;
Range=0.0;
AvgRange=0.0;
for (Counter=shift; Counter<=shift+9; Counter++) AvgRange=AvgRange+MathAbs(High[Counter]-Low[Counter]);
Range=AvgRange/10;
Counter=shift;
TrueCount=0;
while (Counter<shift+9 && TrueCount<1)
{if (MathAbs(Open[Counter]-Close[Counter+1])>=Range*2.0) TrueCount=TrueCount+1;
Counter=Counter+1;
}
if (TrueCount>=1) {MRO1=Counter;} else {MRO1=-1;}
Counter=shift;
TrueCount=0;
while (Counter<shift+6 && TrueCount<1)
{if (MathAbs(Close[Counter+3]-Close[Counter])>=Range*4.6) TrueCount=TrueCount+1;
Counter=Counter+1;
}
if (TrueCount>=1) {MRO2=Counter;} else {MRO2=-1;}
if (MRO1>-1) {value11=3;} else {value11=value10;}
if (MRO2>-1) {value11=4;} else {value11=value10;}
value2=100-MathAbs(iWPR(NULL,0,value11,shift)); // PercentR(value11=9)
val1[shift]=0;
val2[shift]=0;
if (value2>x1)
{
val1[shift]=Low[shift]; val2[shift]=High[shift];
}
if (value2<x2)
{
val1[shift]=High[shift]; val2[shift]=Low[shift];
}
shift--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments