BeginnerAlert
Download scriptThis tool is designed as a visual trading indicator for the MetaTrader 4 platform. Its primary purpose is to analyze price action and provide clear visual signals—represented by arrows on your chart—to help identify potential "Buy" and "Sell" opportunities based on price momentum and range boundaries.
Core Logic and Functionality
1. Data Analysis & Range Identification The script works by constantly scanning historical price data (Highs, Lows, and Closing prices) over a specific timeframe defined by the user. It calculates two key components to determine market behavior:
- Volatility Measurement: It calculates a specific value based on the difference between the highs and lows of recent candles to understand how much the price is currently moving.
- Dynamic Boundaries: The tool identifies the highest high and the lowest low within a set period. It then calculates "thresholds" based on these boundaries using a customizable percentage (the "Otstup" or Gap parameter).
2. Signal Generation The logic looks for specific price actions relative to those boundaries:
- Buy Signals: If the closing price drops near the bottom boundary of the identified range, the script triggers a signal. This suggests that the price has reached a potential "floor."
- Sell Signals: If the closing price rises near the top boundary of the identified range, the script triggers a signal. This suggests the price has reached a potential "ceiling."
3. Visual and Audible Alerts To ensure traders do not miss these moments, the script includes several notification features:
- On-Chart Markers: It places visual arrows on the chart at the exact point where a signal is detected.
- Real-Time Alerts: When a new signal appears on the very latest candle, the tool can trigger an audible alert and a pop-up message box. These alerts provide comprehensive information, including the current Ask/Bid prices, the specific time of the occurrence, the currency symbol, and the timeframe being used.
Key Customization Options
- Sound Settings: You can choose whether or not you want to receive audible notifications for new signals.
- Lookback Period: You can define how many bars of historical data the indicator should analyze at one time.
- Sensitivity (Gap): By adjusting the distance from the high/low boundaries, you can control how "aggressive" the tool is in identifying signals.
- Range Period: This allows you to set the window of time the tool looks at to determine what the recent high and low were.
//+------------------------------------------------------------------+
//| 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