BuySellIndicators
Download scriptThis tool is designed as a visual trading assistant for the MetaTrader platform, specifically built to identify potential entry points by analyzing two distinct market momentum indicators simultaneously. Instead of relying on a single data source, it looks for "confluence"—a situation where multiple technical signals align to suggest a higher probability of a price move.
Core Logic and Functionality
The script operates by monitoring the relationship between the RVI (Relative Volatility Index) and the MACD (Moving Average Convergence Divergence). It treats these as two separate layers of confirmation:
1. Individual Signal Detection The script constantly scans the price history to identify specific "crossovers" for both indicators:
- RVI Signals: It monitors the RVI Main line against its Signal line. When the Main line crosses above the Signal line, it identifies a potential upward move (Buy); when it crosses below, it identifies a potential downward move (Sell).
- MACD Signals: Similarly, it monitors the MACD Main line against its Signal line. A cross upward suggests bullish momentum, while a cross downward suggests bearish momentum.
2. Visual Markers When these individual signals occur, the script places specific visual markers (arrows) directly on your trading chart:
- Blue arrows appear below the price to highlight RVI buy signals and MACD buy signals.
- Red arrows appear above the price to highlight RVI sell signals and MACD sell signals.
3. Confluence Logic (Strong Signals) The most advanced feature of this script is its ability to identify "Strong" signals. It looks for instances where both the RVI and the MACD produce a signal in the same direction at the exact same time.
- When both indicators agree on a Buy, it identifies a Strong Buy.
- When both indicators agree on a Sell, it identifies a Strong Sell.
4. Automated Alerts To ensure you don't miss these high-probability moments, the script includes an automated notification system. If a "Strong" signal (confluence of both indicators) occurs on a timeframe of 60 minutes or higher, the script will:
- Generate a text alert in the platform's log.
- Trigger an audible sound notification to grab your attention immediately.
Summary for Traders
Essentially, this script filters out the "noise" of the market by requiring multiple technical conditions to be met before highlighting a major opportunity. By focusing on the agreement between RVI and MACD, it helps traders identify moments of high momentum where the trend is confirmed by two different mathematical models simultaneously.
//+------------------------------------------------------------------+
//| BuySellIndicators.mq4 |
//| Copyright © 2005, Eli Hayun |
//| http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Eli Hayun"
#property link "http://www.elihayun.com"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Red
//---- input parameters
//---- buffers
double dUpRviBuffer[];
double dDownRviBuffer[];
double dUpMacdBuffer[];
double dDownMacdBuffer[];
double dUpBothBuffer[];
double dDownBothBuffer[];
int RowNum = 0;
int LastTrend = -1;
int UP_IND = 1;
int DOWN_IND = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0,dUpRviBuffer);
SetIndexBuffer(1,dDownRviBuffer);
SetIndexBuffer(2,dUpMacdBuffer);
SetIndexBuffer(3,dDownMacdBuffer);
SetIndexBuffer(4,dUpBothBuffer);
SetIndexBuffer(5,dDownBothBuffer);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,241);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,242);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,252);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,252);
//----
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexEmptyValue(2,0.0);
SetIndexEmptyValue(3,0.0);
SetIndexEmptyValue(4,0.0);
SetIndexEmptyValue(5,0.0);
//---- name for DataWindow
SetIndexLabel(0,"Rvi Buy");
SetIndexLabel(1,"Rvi Sell");
SetIndexLabel(2,"Macd Buy");
SetIndexLabel(3,"Macd Sell");
SetIndexLabel(4,"Strong Buy");
SetIndexLabel(5,"Strong Sell");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int nBars,nCountedBars;
nCountedBars=IndicatorCounted();
//---- check for possible errors
if(nCountedBars<0) return(-1);
//---- last counted bar will be recounted
if(nCountedBars<=2)
nBars=Bars-nCountedBars-3;
if(nCountedBars>2)
{
nCountedBars--;
nBars=Bars-nCountedBars-1;
}
for (int ii=0; ii<nBars; ii++)
{
dUpMacdBuffer[ii]=0;
dDownMacdBuffer[ii] = 0;
dUpRviBuffer[ii]=0;
dDownRviBuffer[ii] = 0;
dUpBothBuffer[ii] = 0;
dDownBothBuffer[ii] = 0;
// Check if RVI has been changed
double val0=iRVI(NULL, 0, 10,MODE_MAIN,ii);
double sig0=iRVI(NULL, 0, 10,MODE_SIGNAL,ii);
double val1=iRVI(NULL, 0, 10,MODE_MAIN,ii+1);
double sig1=iRVI(NULL, 0, 10,MODE_SIGNAL,ii+1);
if ((val0 > sig0) && (val1 < sig1))
{
dUpRviBuffer[ii] = Low[ii] - 2 * MarketInfo(Symbol(),MODE_POINT);
}
if ((val0 < sig0) && (val1 > sig1))
{
dDownRviBuffer[ii] = High[ii] + 2 * MarketInfo(Symbol(),MODE_POINT);
}
// Check if MACD has been changed
double valm0=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,ii);
double sigm0=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,ii);
double valm1=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,ii+1);
double sigm1=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,ii+1);
if ((valm0 > sigm0) && (valm1 < sigm1))
{
dUpMacdBuffer[ii] = Low[ii] - 0.0004;
}
if ((valm0 < sigm0) && (valm1 > sigm1))
{
dDownMacdBuffer[ii] = High[ii] + 2 * MarketInfo(Symbol(),MODE_POINT);
}
if ((dUpRviBuffer[ii] != 0) && (dUpMacdBuffer[ii]))
{
dUpMacdBuffer[ii] = 0;
dUpRviBuffer[ii] = 0;
dUpBothBuffer[ii] = Low[ii] - 2 * MarketInfo(Symbol(),MODE_POINT);
if ((Period() >= 60) && (ii == 0))
{
Print("Buy alert");
PlaySound("alert2.wav");
}
}
if ((dDownRviBuffer[ii] != 0) && (dDownMacdBuffer[ii]))
{
dDownMacdBuffer[ii] = 0;
dDownRviBuffer[ii] = 0;
dDownBothBuffer[ii] = High[ii] + 2 * MarketInfo(Symbol(),MODE_POINT);
if ((Period() >= 60) && (ii == 0))
{
Print("Sell alert");
PlaySound("alert2.wav");
}
}
}
}
Comments