13008d1155015516-indicators-alert-signal-shi_silvertrendsigalert_001
Download scriptThis script is a technical analysis tool designed for the MetaTrader platform to identify potential trend reversal points on a price chart. It functions by monitoring specific price action patterns and plotting visual signals (arrows) to notify the user of potential trading opportunities.
Core Logic and Mechanics
1. Volatility and Range Analysis The script calculates the "momentum" or volatility of the market by looking at the price range (the difference between the highest and lowest prices) over a specific rolling window. It uses a weighted calculation, giving more importance to recent price movements than older ones, to determine how much the market is currently fluctuating.
2. Support and Resistance Identification The tool continuously scans historical data to identify key price extremes—specifically the highest highs and lowest lows over a user-defined period. These extremes act as dynamic boundaries for the current price action.
3. Signal Generation (Entry Logic) The script looks for specific conditions where the price interacts with these identified boundaries:
- Buy Signals: When the closing price of a candle moves significantly toward the lower boundary of the recent range, and meets a specific "buffer" or "offset" threshold, the script identifies a potential upward reversal. It then plots an arrow on the chart to signal a buying opportunity.
- Sell Signals: Conversely, when the closing price moves significantly toward the upper boundary of the recent range and meets its respective offset threshold, the script identifies a potential downward reversal, plotting an arrow for a selling opportunity.
4. Filtering and Noise Reduction To prevent the tool from providing constant, overlapping signals, the logic includes a state-checker. It ensures that it won't trigger a new signal of the same type consecutively (e.g., it won't give two "Buy" signals in a row without an intervening "Sell" signal). This helps filter out market noise and focuses on major trend shifts.
5. User Notifications The script includes an automated alert system. When a valid signal is detected, it checks if a new candle has formed to avoid repetitive alerts. If the "Use Alert" setting is enabled, it triggers a pop-up notification on the screen, providing the user with real-time information on whether a "Buy" or "Sell" condition has been met.
Summary of User Experience
For a trader, this script acts as a visual scout. It automatically monitors the highs and lows of the market, calculates current volatility, and places markers on the chart when price action suggests the trend is about to exhaust itself and reverse. It transforms complex mathematical calculations into simple visual cues and audible/pop-up alerts.
//+------------------------------------------------------------------+
//| 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 Blue
#property indicator_color2 Red
#define SH_BUY 1
#define SH_SELL -1
//---- Âõîäíûå ïàðàìåòðû
extern int AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int Otstup=30;//Îòñòóï.
extern double Per=9;//Ïåðèîä.
extern bool UseAlert = true;
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) { BufU[SH]=Low[SH]-R*0.5; UD=SH_SELL; DoAlert(UD);}
if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100 && UD!=SH_BUY) { BufD[SH]=High[SH]+R*0.5; UD=SH_BUY; DoAlert(UD);}
}
return(0);
}
void DoAlert(int UD)
{
if (!NewBar() || !UseAlert)
return;
string sAction = "Buy";
if (UD == SH_BUY) // Think there is a problem in the indicator. using Buy instead of sell
sAction = "Sell";
Alert(Symbol(), " ",Period()," alert!! ", sAction);
}
bool NewBar()
{
static datetime dt = 0;
if (dt != Time[0])
{
dt = Time[0];
return(true);
}
return(false);
}
Comments