Srev
Download scriptThis trading tool is designed to identify potential reversal points in price action by analyzing historical price extremes and current momentum. Rather than simply following every minor movement, the logic focuses on identifying "overextended" price conditions where the market shows signs of exhaustion or a shift in trend.
Core Logic Overview
The indicator functions by scanning through previous price candles to establish two main categories of data: volatility/range and local price boundaries.
1. Range and Volatility Analysis The tool calculates a specific value based on the distance between the highest and lowest prices over a set number of recent candles. This represents the "energy" or "spread" of the current market move. By calculating this average range, the tool can determine how much the price is typically moving in a given timeframe, which helps it distinguish between normal market noise and significant price swings.
2. Identifying Extremes (Highs and Lows) The indicator looks back over a user-defined period to find the highest high and the lowest low reached during that time. These two points create a "boundary" for the current trading zone. It essentially maps out the territory the market has covered recently.
Signal Generation
The tool generates signals (visualized as arrows on the chart) when the price closes near these boundaries, provided that certain mathematical conditions are met:
- Sell Signals: If the current closing price falls near the bottom of the recent range (based on a user-defined percentage of the total boundary), and the previous signal was not already a sell, it marks a potential downward reversal.
- Buy Signals: Conversely, if the current closing price closes near the top of the recent range (within a specific proximity to the highest point), it marks a potential upward reversal.
Smart Filtering Mechanisms
To prevent the indicator from giving redundant or "noisy" signals in a fast-moving market, it employs two primary filters:
- Directional Locking: The logic includes a tracking mechanism that ensures the tool doesn't repeat the same signal type consecutively. For example, it will not fire another buy arrow until a sell condition has been met (and vice versa), helping to smooth out the visual output.
- Dynamic Offset: By using a percentage-based offset relative to the highest/lowest peaks, the indicator adapts to the current market volatility. This means the "trigger zone" expands or contracts depending on how much the price is swinging, making it more flexible than tools that rely on fixed point values.
Summary for the User
In simple terms, this script looks for moments when the price pushes to the very edge of its recent territory and begins to stall. When the price "exhausts" itself at these extremes, the tool highlights a potential turning point, allowing traders to identify where a trend might be reaching its limit and potentially reversing.
//+------------------------------------------------------------------+
//| Srev.mq4 |
//| Copyright © 2008 Stajer59 |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, http://www.stajer59.ucoz.ru"
#property link " Srev "
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
#define SH_BUY 1
#define SH_SELL -1
//---- Âõîäíûå ïàðàìåòðû
extern int AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int Otstup=30;//Îòñòóï.
extern double Per=34;//Ïåðèîä.
int SH,NB,i,UD;
double R,SHMax,SHMin;
double BufD[];
double BufU[];
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè |
//+------------------------------------------------------------------+
int init()
{
// NB çàïèñûâàåì êîëè÷åñòâî áàðîâ, äëÿ êîòîðûõ ñ÷èòàåì èíäèêàòîð
if (Bars<AllBars+Per || AllBars==0) NB=Bars-Per; else NB=AllBars;
IndicatorBuffers(2);
IndicatorShortName("Srev");
SetIndexStyle(0,DRAW_ARROW,0,3);
SetIndexStyle(1,DRAW_ARROW,0,3);
SetIndexArrow(0,159);
SetIndexArrow(1,159);
SetIndexBuffer(0,BufU);
SetIndexBuffer(1,BufD);
SetIndexDrawBegin(0,Bars-NB);//Èíäèêàòîð áóäåò îòîáðàæàòüñÿ òîëüêî äëÿ NB áàðîâ
SetIndexDrawBegin(1,Bars-NB);
ArrayInitialize(BufD,0.0);//Çàáü¸ì îáà áóôåðà íîëèêàìè. Èíà÷å áóäåò ìóñîð ïðè ñìåíå òàéìôðåéìà.
ArrayInitialize(BufU,0.0);
Print("NB:", NB);
return(0);
}
//+------------------------------------------------------------------+
//| Ôóíêöèÿ äåèíèöèàëèçàöèè |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Ñîáñòâåííî èíäèêàòîð |
//+------------------------------------------------------------------+
int start()
{
int CB=IndicatorCounted();
/* Îïòèìèçàöèîííàÿ ôèøêà.  ÿçûê ââåäåíà ôóíêöèÿ, êîòîðàÿ âîçâðàùàåò êîëè÷åñòâî
ïðîñ÷èòàííûõ áàðîâ. Ïðè ïåðâîì âûçîâå èíäèêàòîðà ýòî 0, åù¸ íè÷åãî
íå ñ÷èòàëîñü, à çàòåì êîëè÷åñòâî îáñ÷èòàííûõ áàðîâ ìèíóñ îäèí. Ò.å. åñëè âñåãî áàðîâ 100,
òî ôóíêöèÿ âåðí¸ò 99. Ïðè ïåðâîì âûçîâå NB îñòà¸òñÿ ïðåæíåé, à ïðè ïîñëåäóþùèõ óìåíüøàåòñÿ
äî ïîñëåäíåãî áàðà, ò.å. 1 èëè 2 */
if(CB<0) return(-1); else if(NB>Bars-CB) NB=Bars-CB;
for (SH=1;SH<NB;SH++)//Ïðîñ÷èòûâàåì ãðàôèê îò 1 äî NB
{
for (R=0,i=SH;i<SH+10;i++) {R+=(10+SH-i)*(High[i]-Low[i]);} R/=55;
SHMax = High[Highest(NULL,0,MODE_HIGH,Per,SH)];
SHMin = Low[Lowest(NULL,0,MODE_LOW,Per,SH)];
if (Close[SH]<SHMin+(SHMax-SHMin)*Otstup/100 && UD!=SH_SELL) { BufU[SH]=Low[SH]-R*0.5; UD=SH_SELL; }
if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100 && UD!=SH_BUY) { BufD[SH]=High[SH]+R*0.5; UD=SH_BUY; }
}
return(0);
}
Comments