IINWMARROWS_002
Download scriptThis script is designed as a visual trading tool for the MetaTrader platform to help identify specific momentum shifts in price action. Instead of showing constant lines on your chart, it acts as a signaling system that places distinct markers (arrows) at key moments when two different moving averages interact with each other.
How the Logic Works
The core logic relies on comparing two different types of "Moving Averages." You can think of a moving average as a smoothed line that represents the general trend of the price over a specific period. The script tracks a "Faster" moving average and a "Slower" moving average simultaneously.
1. Trend Detection The script constantly calculates where these two averages are positioned relative to one another. By comparing the current values against previous candles, it looks for a "crossover"—a moment where the faster trend line cuts through the slower trend line.
- Bullish Signals (Upward Movement): When the Faster Moving Average moves from being below the Slower Moving Average to above it, the script identifies a potential upward shift in momentum. It then places a marker below the price candle to highlight this "Cross Up."
- Bearish Signals (Downward Movement): Conversely, when the Faster Moving Average drops from above the Slower Moving Average to below it, the script identifies a potential downward shift. It places a marker above the price candle to highlight this "Cross Down."
2. Precision and Positioning To ensure the visual markers aren't cluttered directly on top of the price bars, the script performs a small amount of extra calculation regarding the "Range" of the market. It looks at the recent volatility (the distance between the highs and lows of the last 10 candles) and uses that data to offset the arrows. This ensures that the signals appear clearly in the empty space above or below the price action, making them easier for a trader to see at a glance.
Summary of Behavior
In simple terms, this tool filters out the "noise" of constant price fluctuations to show you only the significant moments where the short-term trend meets the long-term trend. It automates the observation of these intersections, providing clear visual cues on your chart to help identify potential entry or exit points based on moving average crossovers.
//+------------------------------------------------------------------+
//| IINWMARROWS.mq4 |
//| Based on EMA_CROSS.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//| Last little modified by Iin Zulkarnain |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1
//----
double CrossUp[];
double CrossDown[];
extern int FasterMode=3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA= 3;
extern int SlowerMode=3; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA= 3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, counter;
double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//----
limit=Bars-counted_bars;
for(i=0; i<=limit; i++)
{
counter=i;
Range=0;
AvgRange=0;
for(counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
fasterMAnow=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i);
fasterMAprevious=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1);
fasterMAafter=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1);
//----
slowerMAnow=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i);
slowerMAprevious=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i+1);
slowerMAafter=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_OPEN, i-1);
if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter))
{
CrossUp[i]=Low[i] - Range*0.5;
}
else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter))
{
CrossDown[i]=High[i] + Range*0.5;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments