Stalin
Download scriptThis technical script is designed as a visual trading assistant for the MetaTrader platform. Its primary purpose is to identify specific "Buy" and "Sell" opportunities by analyzing price momentum and trend shifts in real-time. Instead of just looking at one piece of data, it combines three different market layers to filter out noise and pinpoint high-probability entries.
How the Logic Works
The script follows a multi-layered verification process to decide when to signal a trade:
1. Trend Detection (Moving Averages) The core of the logic relies on comparing two different Moving Averages (Fast and Slow).
- A Buy Signal is primed when the Fast average crosses from below to above the Slow average, indicating upward momentum.
- A Sell Signal is primed when the Fast average crosses from above to below the Slow average, indicating downward momentum.
2. Momentum Filtering (RSI) To ensure the trend isn't just a "fake-out," the script checks the Relative Strength Index (RSI).
- For a Buy signal, it verifies that the RSI is currently positioned in the upper half of its range (above 50), confirming bullish strength.
- For a Sell signal, it verifies that the RSI is in the lower half (below 50), confirming bearish pressure.
3. Price Action Confirmation Once the trend and momentum conditions are met, the script doesn't immediately place a signal. It waits for specific price action:
- Confirmation Zone: If you set a specific "Confirm" value, the script waits for the price to move a certain distance away from the entry point before marking the signal.
- Candle Validation: The script checks the actual shape of the candles. For a Buy, it looks for a bullish candle (closing higher than it opened); for a Sell, it looks for a bearish candle (closing lower than it opened).
4. Noise Reduction (The "Flat" Buffer) To prevent the chart from becoming cluttered with signals that are too close together, the script includes a "Flat" buffer. This logic ensures that a new signal is only displayed if it occurs at a significant distance from the previous one. It effectively forces the script to wait for a meaningful price move before showing another opportunity.
Visual and Audio Feedback
When the logic successfully validates both the trend, momentum, and price confirmation, the script performs three actions:
- Visual Markers: It places distinct colored arrows on your chart (Light Sky Blue for Buy, Light Pink for Sell).
- Audio Alerts: It can trigger a sound notification.
- Email Notifications: It can send an automated email alert directly to your device with the specific symbol name and time of the signal.
//+-----------------------------------------------------------------------+
//| Stalin.mq4 |
//+-----------------------------------------------------------------------+
#property copyright "Copyright © 2011, Andrey Vassiliev (MoneyJinn), v1.0"
#property link "http://www.vassiliev.ru/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightSkyBlue
#property indicator_width1 2
#property indicator_color2 LightPink
#property indicator_width2 2
extern int MAMethod=1;
extern int MAShift=0;
extern int Fast=14;
extern int Slow=21;
extern int RSI=17;
extern double Confirm=0.0;
extern double Flat=0.0;
extern bool SoundAlert=false;
extern bool EmailAlert=false;
double B1[],B2[];
double IUP,IDN,E1,E2,Confirm2,Flat2;
int init()
{
CLR();
if(Digits==3||Digits==5){Confirm2=Confirm*10;Flat2=Flat*10;}else{Confirm2=Confirm;Flat2=Flat;}
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexBuffer(0,B1);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(1,B2);
return(0);
}
void CLR(){if(ArraySize(B1)>0){ArrayInitialize(B1,0);ArrayInitialize(B2,0);}IUP=0;IDN=0;E1=0;E2=0;}
double MA(int per,int bar){return(iMA(NULL,0,per,MAShift,MAMethod,PRICE_CLOSE,bar));}
int start()
{
int IndCounted=IndicatorCounted();
if(IndCounted<0){return(-1);}
if(IndCounted==0){CLR();}
int pos=0;
if(Bars>IndCounted+1){pos=(Bars-IndCounted)-1;}
for(int i=pos;i>0;i--)
{
if(MA(Fast,i+1)<MA(Slow,i+1)&&MA(Fast,i)>MA(Slow,i)&&(iRSI(NULL,0,RSI,PRICE_CLOSE,i)>50||RSI==0)){if(Confirm2==0){BU(i);}else{IUP=Low[i];IDN=0;}}
if(MA(Fast,i+1)>MA(Slow,i+1)&&MA(Fast,i)<MA(Slow,i)&&(iRSI(NULL,0,RSI,PRICE_CLOSE,i)<50||RSI==0)){if(Confirm2==0){BD(i);}else{IDN=High[i];IUP=0;}}
if(IUP!=0){if(((High[i]-IUP)>=(Confirm2*Point))&&(Open[i]<=Close[i])){BU(i);IUP=0;}}
if(IDN!=0){if(((IDN-Low[i])>=(Confirm2*Point))&&(Open[i]>=Close[i])){BD(i);IDN=0;}}
}
return(0);
}
void BU(int i){if(Low[i]>=(E1+Flat2*Point)||Low[i]<=(E1-Flat2*Point)){B1[i]=Low[i];E1=B1[i];Alerts(i,"UP "+Symbol()+" "+TimeToStr(Time[i]));}}
void BD(int i){if(High[i]>=(E2+Flat2*Point)||High[i]<=(E2-Flat2*Point)){B2[i]=High[i];E2=B2[i];Alerts(i,"DN "+Symbol()+" "+TimeToStr(Time[i]));}}
void Alerts(int pos,string txt)
{
if (SoundAlert==true&&pos==1){PlaySound("alert.wav");}
if (EmailAlert==true&&pos==1){SendMail("Stalin alert signal: "+txt,txt);}
}
Comments