PerkyAsctrend1
Download scriptThis script is a technical analysis tool designed to identify significant shifts in market momentum and price direction. Instead of simply looking at current prices, it analyzes historical price behavior to distinguish between active trends and "noise," providing visual signals (arrows) and alerts on your trading chart.
Core Logic Overview
The indicator operates by scanning through historical price data to calculate three main components: volatility, price movement intensity, and momentum levels.
1. Volatility & Range Assessment The script first establishes a baseline for "normal" price movement. It looks at a window of the most recent 10 bars to calculate an average range (the typical distance between highs and lows). This allows the tool to adapt to different market conditions—for example, it recognizes what a "big" move looks like during a quiet period versus a volatile one.
2. Momentum & Movement Filtering To filter out minor price fluctuations, the script uses two specific checks:
- Movement Intensity: It looks for instances where the price gap between consecutive bars is significantly larger than the average range (specifically double the average).
- Directional Strength: It analyzes whether the price is moving consistently in one direction over a set number of bars.
Based on these checks, the script dynamically adjusts its sensitivity. If it detects strong, high-intensity movement, it "tightens" its focus; if the market is drifting slowly, it maintains a wider perspective.
3. Overbought and Oversold Detection The tool utilizes a momentum oscillator (similar to a Williams Percent Range) to measure how far the price has moved relative to its recent highs and lows. It translates this data into a percentage-style scale:
- It identifies when the market is stretched too far in one direction (overextended).
- By monitoring these "stretched" levels, it waits for the moment the momentum begins to exhaust or reverse.
4. Signal Generation The final step is the generation of trading signals. The script looks for specific "breakout" behaviors:
- Sell Signals: When the price enters an overextended upper zone and then shows a clear sign of weakening momentum, it places a signal on the chart.
- Buy Signals: When the price enters an overextended lower zone and shows signs of strengthening upward momentum, it places a signal on the chart.
User Experience Features
- Visual Cues: The script plots arrows directly on your candles to indicate where these trend shifts are identified.
- Dynamic Alerts: In addition to visual arrows, the script is programmed to send a pop-up alert on your screen when a new "Buy" or "Sell" signal is detected in real-time.
- Adjustable Risk: The logic includes a "Risk" parameter that allows users to modify the sensitivity of the filters, effectively widening or narrowing the criteria for what constitutes a significant price movement.
//+------------------------------------------------------------------+
//| PerkyAsctrend1.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Magenta
//----
extern int RISK = 4;
extern int AllBars = 250;
//----
double val1buffer[];
double val2buffer[];
int up = 0, dn = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 108);
SetIndexBuffer(0, val1buffer);
//----
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 108);
SetIndexBuffer(1, val2buffer);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double value2;
double value3;
double value10 = 10;
double value11;
double x1 = 70;
double x2 = 30;
int TrueCount;
int counter;
int MRO1;
int MRO2;
int i1;
double Range;
double AvgRange;
double val1;
double val2;
double Table_value2[500][2];
int counted_bars = IndicatorCounted();
value10 = 3 + RISK*2;
x1 = 67 + RISK;
x2 = 33 - RISK;
value11 = value10;
//----
if(counted_bars < 0)
return (-1);
//----
if(counted_bars > 0)
counted_bars--; //last bar recounted
int i;
int shift = Bars - counted_bars - 1;
if(shift > AllBars)
shift = AllBars;
for(i = shift; i > 0; i--)
{
counter = i;
Range = 0;
AvgRange = 0;
//----
for(counter = i; counter <= i + 9; counter++)
AvgRange = AvgRange + MathAbs(High[counter] - Low[counter]);
Range = AvgRange / 10;
counter = i;
TrueCount = 0;
//----
while(counter < i + 9 && TrueCount < 1)
{
if(MathAbs(Open[counter] - Close[counter+1]) >= Range*2.0)
TrueCount++;
counter++;
}
//----
if(TrueCount >= 1)
MRO1 = counter ;
else
MRO1 = -1;
counter = i;
TrueCount = 0;
//----
while(counter < i + 6 && TrueCount < 1)
{
if(MathAbs(Close[counter+3] - Close[counter]) >= Range*4.6)
{
TrueCount++;
}
counter++;
}
//----
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, i));
Table_value2[i][0] = i;
Table_value2[i][1] = value2;
val1 = 0;
val2 = 0;
value3 = 0;
//----
if(value2 < x2 ) // x2 = 30
{
i1 = 1;
//----
while(Table_value2[i+i1][1] >= x2 && Table_value2[i+i1][1] <= x1)
i1++;
//----
if(Table_value2[i+i1][1] > x1)
{
value3 = High[i] + Range*0.5;
val1 = value3;
}
}
//----
if(value2>x1) // x1 = 70
{
i1 = 1;
//----
while(Table_value2[i+i1][1] >= x2 && Table_value2[i+i1][1] <= x1)
{
i1++;
}
//----
if(Table_value2[i+i1][1] < x2)
{
value3 = Low[i]-Range*0.5;
val2 = value3;
}
}
//----
if(val2 != 0 && up == 0)
{
val1buffer[i] = val2 - 1*Point;
up = 1;
dn = 0;
//----
if(shift <= 2)
Alert(Symbol(), " ", Period(), "M Asctrend BUY ");
}
//----
if(val1 !=0 && dn == 0)
{
val2buffer[i] = val1 + 1*Point;
dn = 1;
up = 0;
//----
if(shift <= 2)
Alert(Symbol(), " ", Period(), "M Asctrend SELL ");
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments