BeginnerAlert_v2
Download scriptThis script is a technical analysis tool designed for the MetaTrader platform to identify potential trend reversals or entry points by analyzing price action patterns. It functions as a visual indicator that places markers (arrows) on your trading chart to signal "Buy" and "Sell" opportunities based on specific volatility and price movement logic.
Core Logic and Functionality
1. Trend Detection via Price Extremes The tool constantly monitors the high and low price points over a user-defined period. It calculates the range (the difference between the highest peak and the lowest valley) to understand the recent "swing" of the market. By comparing current closing prices against these peaks and valleys, it determines if the price is pushing into an overextended zone.
2. Volatility Calculation Beyond just looking at highs and lows, the script incorporates a weighted calculation of the "range" of individual candles. This helps the indicator understand the intensity of price movements. It uses this data to set a dynamic distance for its signals, ensuring that the markers are placed logically relative to the current market volatility.
3. Signal Filtering (The "Otstup" Logic) To prevent the tool from providing too many "fake" signals during minor price fluctuations, it uses an offset parameter. A signal is only triggered if the price closes significantly close to the established highs or lows of the recent period—specifically, when it enters a percentage-based buffer zone near those extremes.
4. Directional Memory The script features a "memory" component to ensure it doesn't spam the user with repetitive signals in the same direction. It tracks the last confirmed move; for example, if it has already issued a Buy signal, it will remain "locked" and ignore further Buy signals until a Sell condition is met. This helps smooth out the visual output on the chart.
5. User Alerts and Visuals
- Visual Markers: The script automatically plots upward arrows for potential buys and downward arrows for potential sells directly on the price candles.
- Real-time Notifications: If enabled, the tool can trigger an instant audio alert and a pop-up notification on your screen the moment a new signal is detected. This includes specific details such as the current Ask/Bid prices, the exact time of the move, and the currency pair being traded.
Summary for the User
In simple terms, this tool acts like a "boundary guard." It looks at how far the market has moved recently and waits for the price to hit a "wall" (a high or low point). When the price interacts with that wall in a way that suggests a reversal is likely, it marks the chart with an arrow and alerts you, while filtering out minor noise to help you focus on significant movements.
//+------------------------------------------------------------------+
//| Beginner.mq4 |
//| Copyright © 2007 |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Heaven"
#property link "http://Beginner.com"
//----
#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 bool SoundON=true;
extern int AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int Otstup=30;//Îòñòóï.
extern double Per=9;//Ïåðèîä.
//----
int SH,NB,i,UD;
double R,SHMax,SHMin;
double BufD[];
double BufU[];
int flagval1=0;
int flagval2=0;
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè |
//+------------------------------------------------------------------+
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)
{
// Pop an Alert
if (SH==1 && flagval1==0)
{
flagval1=1;
flagval2=0;
if (SoundON) Alert("BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
}
BufU[SH]=Low[SH]-R*0.5; UD=SH_SELL;
}
if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100 && UD!=SH_BUY)
{
// pop an Alert
if (SH==1 && flagval2==0)
{
flagval2=1;
flagval1=0;
if (SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
}
BufD[SH]=High[SH]+R*0.5; UD=SH_BUY;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments