SHI_SilverTrendSigAlert
Download scriptThis script is a specialized technical analysis tool designed to identify specific momentum shifts and trend reversals in financial markets. Instead of providing a continuous line, it acts as a signaling system that marks precise entry points on your chart using visual arrows and real-time notifications.
Core Logic and Mechanics
Dynamic Price Volatility Calculation The script does not rely solely on fixed price levels. It calculates a unique "range" value by analyzing the relationship between the high and low prices of recent candles. By weighing these price fluctuations, it determines the intensity of the current market movement, ensuring that signals are adjusted based on how much the market is actually moving at that specific moment.
Trend Boundary Detection The tool identifies the "trading zone" by scanning a user-defined period of historical data to find the highest peak and the lowest valley. It then establishes a dynamic boundary based on these extremes.
- Support Identification: If the current price drops toward the lower boundary (based on a specific sensitivity percentage), the script identifies a potential "oversold" condition.
- Resistance Identification: If the current price climbs toward the upper boundary, it identifies a potential "overbought" condition.
Signal Filtering and Execution To prevent the tool from providing constant, repetitive signals during a single trend, it includes a logic gate that ensures only one direction is signaled at a time. It will only trigger a new signal if the market has successfully flipped its orientation (e.g., it won't provide another "Buy" signal until a "Sell" condition has been met).
Visual and Audio Alerts When the price crosses these calculated boundaries and the logic confirms a trend shift, the script performs three actions simultaneously:
- Visual Plotting: It places distinct arrows on the chart (Yellow for Buy signals, Red for Sell signals) at the exact candle where the logic was triggered.
- Pop-up Notifications: It generates an immediate alert window on your screen to notify you of the trend change.
- Execution Prevention: It includes a "New Bar" check, which ensures that you only receive one notification per candle, preventing your workspace from being overwhelmed by multiple alerts for the same price movement.
User Customization Options
The logic is governed by four primary adjustable parameters:
- AllBars: Controls how far back into the history the script should look to calculate data.
- Otstup (Distance): Adjusts how close to the boundary the price must reach before a signal is triggered (higher numbers require a closer touch).
- Per (Period): Defines the look-back window used to determine the highest highs and lowest lows.
- UseAlert: A simple toggle to turn the pop-up notifications on or off.
//+------------------------------------------------------------------+
//| 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 Yellow
#property indicator_color2 Red
#property indicator_width1 5
#property indicator_width2 5
#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);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexArrow(1,234);
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 = "SHI SilverTrend Buy ";
if (UD == SH_BUY) // Think there is a problem in the indicator. using Buy instead of sell
sAction = "SHI SilverTrend Sell ";
Alert("Alert!! ", sAction,Symbol(), " ",Period());
}
bool NewBar()
{
static datetime dt = 0;
if (dt != Time[0])
{
dt = Time[0];
return(true);
}
return(false);
}
Comments