SHI_SilverTrendSig1_v1
Download scriptThis script functions as a visual trading signal indicator designed to identify potential trend reversals or shifts in price momentum on a trading chart. Instead of creating a continuous line, it places specific arrow markers (Red and Blue) to notify the user of actionable price conditions.
Core Logic Overview
The tool operates by analyzing historical price data—specifically the relationship between the current closing price and the recent "High" and "Low" price extremes. It filters out minor market noise to focus on significant movements, ensuring that signals are only generated when the price reaches specific zones of interest.
How the Analysis Works
-
Volatility & Range Calculation: The script calculates a dynamic value based on the recent price movement (the "Range"). It looks at the distance between the highest and lowest prices over a short sequence to determine how much the market is currently fluctuating. This helps the indicator scale its logic according to current market conditions.
-
Identifying Extreme Zones: The script identifies the highest peak and the lowest valley over a user-defined period. It then establishes a "buffer zone" based on a percentage offset. Essentially, it creates a boundary near the top and bottom of the recent price action.
-
Signal Generation:
- Sell Signals (Red Arrows): A sell signal is triggered when the price closes near the bottom of its recent range (falling into the "low" buffer zone). This suggests that the price may have reached an oversold state or a potential floor.
- Buy Signals (Blue Arrows): A buy signal is triggered when the price closes near the top of its recent range (entering the "high" buffer zone). This suggests the price may have reached an overbought state or a potential ceiling.
-
Signal Filtering: To prevent the chart from being cluttered with repeated signals during a single move, the script includes logic to ensure it doesn't trigger multiple consecutive signals of the same type. It looks for a clear transition between states before placing a new arrow.
Visual Output
- Buy Signals: Displayed as arrows positioned slightly below the candle to indicate a potential upward movement.
- Sell Signals: Displayed as arrows positioned slightly above the candle to indicate a potential downward movement.
By focusing on these specific price boundaries, the script aims to highlight moments where the market trend may be exhausting itself and preparing for a reversal.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| SHI_SilverTrendSig.mq4 |
//| Copyright © 2003, VIAC.RU, OlegVS, GOODMAN, © 2005, Shurka |
//| shforex@narod.ru |
//| |
//| |
//| Ïèøó ïðîãðàììû íà çàêàç |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Shurka"
#property link "http://shforex.narod.ru"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#define SH_BUY 1
#define SH_SELL -1
//---- Âõîäíûå ïàðàìåòðû
extern int AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int Otstup=30;//Îòñòóï.
extern int Per=9;//Ïåðèîä.
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("SHI_SilverTrendSig");
SetIndexStyle(0,DRAW_ARROW,0,1);
SetIndexStyle(1,DRAW_ARROW,0,1);
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);
return(0);
}
//+------------------------------------------------------------------+
//| Ôóíêöèÿ äåèíèöèàëèçàöèè |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Ñîáñíà èíäèêàòîð |
//+------------------------------------------------------------------+
int start()
{
int CB=IndicatorCounted();
/* Òóò âîò òà ñàìàÿ îïòèìèçàöèîííàÿ ôèøêà.  ÿçûê ââåäåíà ôóíêöèÿ, êîòîðàÿ âîçâðàùàåò êîëè÷åñòâî
ïîñ÷èòàííûõ áàðîâ, ïðè÷¸ì î÷åíü õèòðî. Ïðè ïåðâîì âûçîâå èíäèêàòîðà ýòî 0, âñ¸ ïîíÿòíî, åù¸ íè÷åãî
íå ñ÷èòàëîñü, à çàòåì âûäà¸ò êîëè÷åñòâî îáñ÷èòàííûõ áàðîâ ìèíóñ îäèí. Ò.å. åñëè âñåãî áàðîâ 100,
òî ôóíêöèÿ âåðí¸ò 99. ß ââ¸ë òàêîé êîä, âûøå ó ìåíÿ îïðåäåëÿëàñü NB - êîë-âî áàðîâ ïîäëåæàùèõ
îáñ÷¸òó.  ïðèíöèïå ýòîò ïàðàìåòð ìîæíî è âûêèíóòü, îäíàêî äëÿ òåõ êòî â òàíêå (I80286) ìîæíî
è îñòàâèòü. Òàê âîò, çäåñü, ïðè ïåðâîì âûçîâå 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) { BufD[SH]=High[SH]+R*0.5; UD=SH_SELL; }
if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100 && UD!=SH_BUY) { BufU[SH]=Low[SH]-R*0.5; UD=SH_BUY; }
}
return(0);
}
Comments