rsi_ma_trade_sist

Download script
Author: Yuriy Tokman (YTG)
rsi_ma_trade_sist

Technical Logic Overview: RSI & Moving Average Trading System

This script is a custom technical indicator designed for the MetaTrader 4 platform. It serves as a visual and automated signaling tool that combines three distinct types of market analysis: Trend Direction, Momentum Strength, and Volatility Adjustments.

The logic operates through the following primary components:

1. Core Indicators Used

  • Exponential Moving Averages (EMA): The script tracks two different speeds of moving averages (Fast and Slow). By comparing these, the system identifies the current trend of the market.
  • Relative Strength Index (RSI): This is used to measure the speed and change of price movements. It helps the script determine if the market is gaining strength or becoming overextended.
  • Average True Range (ATR): The script utilizes this to calculate "buffer zones" for signals, helping to place visual markers at a distance relative to current market volatility.

2. Signal Generation Logic

The script identifies specific entry points based on the interaction between the moving averages and the RSI. It looks for "crossovers" accompanied by momentum confirmation:

  • Buy Signals: A Buy signal is triggered when the Fast EMA crosses above the Slow EMA while the RSI is simultaneously above the 50-level midpoint. The script checks both the current state and the previous candle to ensure a definitive crossover has occurred.
  • Sell Signals: A Sell signal is triggered when the Fast EMA crosses below the Slow EMA while the RSI is simultaneously below the 50-level midpoint.

3. Visual and Alert Features

To make the data actionable for a trader, the script provides several layers of feedback:

  • On-Chart Marking: When a signal condition is met, the script places visual arrows (Buy/Sell) on the chart at specific price levels adjusted by volatility (ATR).
  • Dynamic Text Labels: The script generates real-time text labels on the screen, displaying the specific "Buy" or "Sell" instruction along with the opening price of that signal.
  • Multi-Channel Notifications: The system is equipped to notify the user through three different methods depending on user settings:
    1. Pop-up Alerts: Immediate visual/audio alerts within the trading platform.
    2. Email Notifications: Sending a summary to a registered email address.
    3. Push Notifications: Sending alerts directly to mobile devices.

4. Smart Filtering Logic

To prevent "signal noise" (multiple overlapping signals in the same direction), the script contains a logic gate that ensures it only fires one Buy signal at a time until a Sell signal is confirmed, and vice versa. Additionally, it includes a New Bar check to ensure that notifications are only sent once per candle, preventing the system from spamming alerts during high-frequency price fluctuations.

Indicators Used
Moving average indicatorRelative strength indexIndicator of the average true range
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
12 Views
0 Downloads
0 Favorites
rsi_ma_trade_sist
//+------------------------------------------------------------------+
//|                                            RSI_MA_Trade_Sist.mq4 |
//|                                               Yuriy Tokman (YTG) |
//|                                               http://ytg.com.ua/ |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman (YTG)"
#property link      "http://ytg.com.ua/"
#property version   "1.00"
#property strict
#property indicator_separate_window

#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Lime

extern int       FastEMA   = 5;
extern int       SlowEMA   = 12;
extern int       RSIPeriod = 21;
input  int       shift     = 1;

extern bool   Alerts=true;
extern string Text_BUY="BUY signal text";
extern string Text_SELL = "SELL signals text";
extern bool   Send_Mail = false;
extern string subject="subject text";
extern bool Send_Notification=false;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];

bool metka_buy=false;
bool metka_sell=false;
string text="",name="";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   name="RSI_MA_Trade_Sist";
   IndicatorShortName(name);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"Fast EMA ");
   SetIndexDrawBegin(0,FastEMA);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"Slow EMA ");
   SetIndexDrawBegin(1,SlowEMA);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,217);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexEmptyValue(2,0.0);
   SetIndexLabel(2,"BUY Signal ");
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,218);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexEmptyValue(3,0.0);
   SetIndexLabel(3,"SELL Signal ");
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexLabel(4,"RSI ");
   SetIndexDrawBegin(4,RSIPeriod);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   GetDellName();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   double rsi_sig=0,fast_sig=0,slow_sig=0,price_OP=0;
   double rsi_sig_prev=0,fast_sig_prev=0,slow_sig_prev=0;
   string txt=WindowExpertName()+" "+Symbol()+"  "+GetNameTF()+"  ";
//---
   int limit=rates_total-prev_calculated;
   if(prev_calculated==0)limit--;
   else  limit++;
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      ExtMapBuffer1[i] = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i);
      ExtMapBuffer2[i] = iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
      ExtMapBuffer5[i] = iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i) - (50 - iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE,i))*Point;

      fast_sig = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+shift);
      slow_sig = iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+shift);
      rsi_sig  = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE,i+shift);

      fast_sig_prev = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i+shift+1);
      slow_sig_prev = iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i+shift+1);
      rsi_sig_prev  = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE,i+shift+1);

      if(((fast_sig>slow_sig && rsi_sig>50 && fast_sig_prev<=slow_sig_prev)
         || (fast_sig>slow_sig && rsi_sig>50 && rsi_sig_prev<=50)) && !metka_buy)
        {
         metka_sell= false;
         metka_buy = true;
         ExtMapBuffer3[i]=slow_sig-iATR(Symbol(),0,10,i)/2;
         price_OP=Bid;
         text=" Price Open = "+DoubleToStr(price_OP,Digits);
         Label("ytg_name_label","Buy,"+text,1,3,15,10,"Arial",Green,name);
         if(i==0 && NewBar())
           {
            if(Alerts)Alert(txt+Text_BUY+text);
            if(Send_Mail)SendMail(txt+subject,Text_BUY+text);
            if(Send_Notification)SendNotification(txt+Text_BUY+text);
           }
        }
      if(((fast_sig<slow_sig && rsi_sig<50 && fast_sig_prev>=slow_sig_prev)
         || (fast_sig<slow_sig && rsi_sig<50 && rsi_sig_prev>=50)) && !metka_sell)
        {
         metka_sell= true;
         metka_buy = false;
         ExtMapBuffer4[i]=slow_sig+iATR(Symbol(),0,10,i)/2;
         price_OP=Ask;
         text=" Price Open = "+DoubleToStr(price_OP,Digits);
         Label("ytg_name_label","Sell,"+text,3,3,15,10,"Arial",Red,name);
         if(i==0 && NewBar())
           {
            if(Alerts)Alert(txt+Text_SELL+text);
            if(Send_Mail)SendMail(txt+subject,Text_SELL+text);
            if(Send_Notification)SendNotification(txt+Text_SELL+text);
           }
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
bool NewBar(int TF=0)
  {
   static datetime NewTime=0;
   if(NewTime!=iTime(Symbol(),TF,0))
     {
      NewTime=iTime(Symbol(),TF,0);
      return(true);
     }
   return(false);
  }
//----
string GetNameTF(int TimeFrame=0) 
  {
   if(TimeFrame==0) TimeFrame=Period();
   switch(TimeFrame) 
     {
      case PERIOD_M1:  return("M1");
      case PERIOD_M5:  return("M5");
      case PERIOD_M15: return("M15");
      case PERIOD_M30: return("M30");
      case PERIOD_H1:  return("H1");
      case PERIOD_H4:  return("H4");
      case PERIOD_D1:  return("Daily");
      case PERIOD_W1:  return("Weekly");
      case PERIOD_MN1: return("Monthly");
      default:         return("UnknownPeriod");
     }
  }
//+----------------------------------------------------------------------+
//| Îïèñàíèå: Ñîçäàíèå òåêñòîâîé ìåòêè                                   | 
//| Àâòîð:    Þðèé Òîêìàíü                                               |
//| e-mail:   yuriytokman@gmail.com                                      |
//+----------------------------------------------------------------------+
void Label(string name_label,           //Èìÿ îáúåêòà.
           string text_label,           //Òåêñò îáüåêòà. 
           int corner = 2,              //Hîìåð óãëà ïðèâÿçêè 
           int x = 3,                   //Pàññòîÿíèå X-êîîðäèíàòû â ïèêñåëÿõ 
           int y=15,                    //Pàññòîÿíèå Y-êîîðäèíàòû â ïèêñåëÿõ 
           int font_size = 10,          //Ðàçìåð øðèôòà â ïóíêòàõ.
           string font_name = "Arial",  //Íàèìåíîâàíèå øðèôòà.
           color text_color = LimeGreen,//Öâåò òåêñòà.
           string Window_Find="NULL"
           )
  {
   if(ObjectFind(name_label)!=-1) ObjectDelete(name_label);
   ObjectCreate(name_label,OBJ_LABEL,WindowFind(Window_Find),0,0,0,0);
   ObjectSet(name_label,OBJPROP_CORNER,corner);
   ObjectSet(name_label,OBJPROP_XDISTANCE,x);
   ObjectSet(name_label,OBJPROP_YDISTANCE,y);
   ObjectSetText(name_label,text_label,font_size,font_name,text_color);
  }
//----
void GetDellName(string name_n="ytg_")
  {
   string vName;
   for(int i=ObjectsTotal()-1; i>=0;i--)
     {
      vName=ObjectName(i);
      if(StringFind(vName,name_n)!=-1) ObjectDelete(vName);
     }
  }
//+------------------------------------------------------------------+

Comments