R2_Arrows_v4
Download scriptThis script is a technical analysis tool designed for the MetaTrader platform to identify specific market trends and potential entry or exit points using a combination of moving averages and momentum oscillators. It visualizes these signals directly on your trading chart in the form of arrows and markers.
Core Logic Overview
The indicator operates by analyzing two primary components: a Trend Filter (the Moving Average) and a Momentum Sequence (the RSI). By combining these, the script seeks to identify moments where price action aligns with both the broader trend and specific short-term momentum shifts.
Key Components of the Logic
1. Trend Identification
The tool first establishes whether the market is in an overall "uptrend" or "downtrend." It does this by calculating a moving average line. Depending on your settings, it can use a standard moving average or a more advanced calculation (Hull Moving Average).
- If the price is currently above this trend line, the tool considers the environment bullish.
- If the price is below the trend line, it considers the environment bearish.
2. Signal Generation (Buy and Sell Arrows)
The script does not just look at where the price is; it looks for a specific three-day sequence of momentum using the Relative Strength Index (RSI).
-
Sell Signals: For a sell arrow to appear, two conditions must be met simultaneously:
- Trend: The price must be closing below the trend line.
- Momentum: The RSI must show a specific "climbing" pattern over three consecutive periods, staying above a user-defined threshold. This indicates that while the trend is down, there is a specific type of momentum building that the script identifies as a high-probability entry point.
-
Buy Signals: For a buy arrow to appear, the inverse logic applies:
- Trend: The price must be closing above the trend line.
- Momentum: The RSI must show a specific "falling" pattern over three consecutive periods, staying below a user-defined threshold. This identifies a momentum shift that aligns with an upward trend.
3. Trade Management (Close Markers)
In addition to entry signals, the script provides visual cues for when a position might need to be exited. It monitors the RSI levels to identify "overextended" conditions:
- If the momentum becomes too high (exceeding a top threshold), it places a marker above the price to suggest closing a Buy trade.
- If the momentum becomes too low (dropping below a bottom threshold), it places a marker below the price to suggest closing a Sell trade.
Visual Representation
To keep the chart clean for the user, the logic translates these mathematical conditions into visual symbols:
- Arrows: Placed at the top or bottom of the candles to highlight potential entry points.
- Markers: Placed specifically to signal "Take Profit" or "Exit" zones based on momentum exhaustion.
- Trend Line: A visible line that helps the user instantly distinguish between bullish and bearish market structures.
//+------------------------------------------------------------------+
//| R2_Arrows_v4.mq4 |
//| Copyright © 2007 , transport_david , David W Honeywell |
//| hellonwheels.trans@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007 , transport_david , David W Honeywell"
#property link "hellonwheels.trans@gmail.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Coral
#property indicator_color3 White
#property indicator_color4 SlateGray
extern bool Use_Hull = false;
extern string s1 = "---------------";
extern int Ma_Periods = 200;
extern int Ma_Type_if_not_Hull = 0; // only if Use_Hull = false
extern int Ma_Applied_Price = 0;
extern string s2 = "---------------";
extern int RsiPeriods = 2;
extern int Rsi_Applied_Price = 0;
extern string s3 = "---------------";
extern int BuyIfDay1RsiBelow = 65; // 1st day of tracking must be < this setting
extern int BuyIfDay3RsiBelow = 65; // 3rd day must be < this setting
extern string s4 = "---------------";
extern int SellIfDay1RsiAbove = 35; // 1st day of tracking must be > this setting
extern int SellIfDay3RsiAbove = 35; // 3rd day must be > this setting
extern string s5 = "---------------";
extern int CloseBuyIfRsiAbove = 75;
extern int CloseSellIfRsiBelow = 25;
extern string s6 = "---------------";
extern int ShowBars = 10000;
double Trend_Ma[];
double Sell_Arrow[];
double Buy_Arrow[];
double Close_Trade_Marker[];
double Calc[];
double prevtime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(5);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexEmptyValue(0,0.0);
SetIndexBuffer(0,Trend_Ma);
SetIndexLabel(0,"Trend_Ma_Periods ( "+Ma_Periods+" )");
SetIndexEmptyValue(1,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(1,Sell_Arrow);
SetIndexLabel(1,"Sell_Arrow ( RsiPeriods "+RsiPeriods+" )");
SetIndexEmptyValue(2,0.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,233);
SetIndexBuffer(2,Buy_Arrow);
SetIndexLabel(2,"Buy_Arrow ( RsiPeriods "+RsiPeriods+" )");
SetIndexEmptyValue(3,0.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,172);
SetIndexBuffer(3,Close_Trade_Marker);
SetIndexLabel(3,"Close_Trade_Marker");
SetIndexEmptyValue(4,0.0);
SetIndexBuffer(4,Calc);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int shift = ShowBars;
if (ShowBars > Bars) ShowBars = Bars;
for ( shift = ShowBars; shift >= 0; shift-- )
{
double Exp = 2;
double firstwma = iMA(Symbol(),0,MathFloor(Ma_Periods/2),0,MODE_LWMA,Ma_Applied_Price,shift);
double secondwma = iMA(Symbol(),0,Ma_Periods,0,MODE_LWMA,Ma_Applied_Price,shift);
Calc[shift] = (Exp*firstwma)-secondwma;
}
if (Use_Hull)
{
for ( shift = ShowBars; shift >= 0; shift-- )
{
Trend_Ma[shift] = iMAOnArray(Calc,0,MathFloor(MathSqrt(Ma_Periods)),0,MODE_LWMA,shift);
if (prevtime != Time[0]) { RefreshRates(); prevtime=Time[0]; }
double Day1 = iRSI(Symbol(),0,RsiPeriods,Rsi_Applied_Price,shift+3);
double Day2 = iRSI(Symbol(),0,RsiPeriods,Rsi_Applied_Price,shift+2);
double Day3 = iRSI(Symbol(),0,RsiPeriods,Rsi_Applied_Price,shift+1);
//- Sell Arrows ---
if ( (iClose(Symbol(),0,shift+1) < Trend_Ma[shift+1]) && (Day1 > SellIfDay1RsiAbove) && (Day2 > Day1) && (Day3 > Day2) && (Day3 > SellIfDay3RsiAbove) )
Sell_Arrow[shift] = iHigh(Symbol(),0,shift) + (20*Point);//High arrow Sell
//- Buy Arrows ---
if ( (iClose(Symbol(),0,shift+1) > Trend_Ma[shift+1]) && (Day1 < BuyIfDay1RsiBelow) && (Day2 < Day1) && (Day3 < Day2) && (Day3 < BuyIfDay3RsiBelow) )
Buy_Arrow[shift] = iLow(Symbol(),0,shift) - (20*Point);//Low arrow Buy
//- Close Trades Marker ---
if (Day3 < CloseSellIfRsiBelow)
Close_Trade_Marker[shift] = iLow(Symbol(),0,shift) - (50*Point);
if (Day3 > CloseBuyIfRsiAbove)
Close_Trade_Marker[shift] = iHigh(Symbol(),0,shift) + (50*Point);
}
return(0);
}
if (!Use_Hull)
{
for ( shift = ShowBars; shift >= 0; shift-- )
{
Trend_Ma[shift] = iMA( Symbol(), 0, Ma_Periods, 0, Ma_Type_if_not_Hull, Ma_Applied_Price, shift);
if (prevtime != Time[0]) { RefreshRates(); prevtime=Time[0]; }
Day1 = iRSI(Symbol(),0,RsiPeriods,Rsi_Applied_Price,shift+3);
Day2 = iRSI(Symbol(),0,RsiPeriods,Rsi_Applied_Price,shift+2);
Day3 = iRSI(Symbol(),0,RsiPeriods,Rsi_Applied_Price,shift+1);
//- Sell Arrows ---
if ( (iClose(Symbol(),0,shift+1) < Trend_Ma[shift+1]) && (Day1 > SellIfDay1RsiAbove) && (Day2 > Day1) && (Day3 > Day2) && (Day3 > SellIfDay3RsiAbove) )
Sell_Arrow[shift] = iHigh(Symbol(),0,shift) + (20*Point); // High arrow Sell
//- Buy Arrows ---
if ( (iClose(Symbol(),0,shift+1) > Trend_Ma[shift+1]) && (Day1 < BuyIfDay1RsiBelow) && (Day2 < Day1) && (Day3 < Day2) && (Day3 < BuyIfDay3RsiBelow) )
Buy_Arrow[shift] = iLow(Symbol(),0,shift) - (20*Point); // Low arrow Buy
//- Close Trades Marker ---
if (Day3 < CloseSellIfRsiBelow)
Close_Trade_Marker[shift] = iLow(Symbol(),0,shift) - (50*Point);
if (Day3 > CloseBuyIfRsiAbove)
Close_Trade_Marker[shift] = iHigh(Symbol(),0,shift) + (50*Point);
}
return(0);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments