SRCx2MA_arr
Download scriptThis script is a specialized technical analysis tool designed for the MetaTrader platform. It functions as a visual signal generator that identifies potential turning points in market trends by comparing different sets of moving average data.
Core Logic Overview
The script operates by pulling data from a secondary source—an external indicator known as "SRCma." It takes specific values from this source and performs a multi-layered calculation to filter out market noise and highlight significant price shifts.
How the Calculation Works
- Data Comparison: The tool looks at two different time periods provided by the source indicator. By subtracting one value from the other, it calculates a "difference" value. This represents the velocity or momentum of the price movement.
- Smoothing: To ensure that the signals are not triggered by minor, insignificant price flickers, the script applies a Simple Moving Average (SMA) to that difference. This creates a smoothed line that represents the prevailing trend more reliably.
- Trend Identification: The script then measures the distance between the raw momentum and this smoothed average.
- If the current momentum is significantly higher than the average, it suggests an upward push.
- If it falls below the average, it suggests a downward push.
Visual Signals
The primary purpose of the script is to plot clear visual cues directly on your trading chart:
- Buy Signals (Upward): When the momentum crosses from negative to positive, the script places an arrow at the bottom of the price candle. This indicates that the trend may be shifting in favor of the buyers.
- Sell Signals (Downward): When the momentum crosses from positive to negative, the script places an arrow at the top of the price candle. This indicates that the trend may be shifting in favor of the sellers.
Summary for the Trader
Instead of forcing you to monitor complex mathematical differences manually, this script automates the process. It acts as a "filter" that only highlights moments where the momentum successfully breaks away from its average, aiming to provide you with clear entry or exit points based on momentum shifts.
//+------------------------------------------------------------------+
//| arrSRCx2MA.mq4 |
//+------------------------------------------------------------------+
// Íåîáõîäèìî íàëè÷èå SRCma.mq4
// Presence SRCma.mq4 is necessary
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Bookkeeper"
#property link "yuzefovich@gmail.com"
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
//----
extern int IndPeriod1=3;
extern int IndPeriod2=10;
extern int CalculatedBars=500;
extern int rangeN=14;
extern int MAPeriod=13;
double up_buffer1[];
double dn_buffer1[];
double up_buffer2[];
double dn_buffer2[];
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(7);
SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexArrow(1,234);
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,2);
SetIndexStyle(3,DRAW_HISTOGRAM,EMPTY,2);
SetIndexBuffer(0,up_buffer1);
SetIndexBuffer(1,dn_buffer1);
SetIndexBuffer(2,up_buffer2);
SetIndexBuffer(3,dn_buffer2);
SetIndexBuffer(4,ind_buffer1);
SetIndexBuffer(5,ind_buffer2);
SetIndexBuffer(6,ind_buffer2);
return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
int start()
{
int limit, i, counted_bars = IndicatorCounted();
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
if(CalculatedBars<500) CalculatedBars=500;
if(limit>CalculatedBars) limit=CalculatedBars;
for(i=limit;i>=0;i--)
{
double Ind1=iCustom(NULL,0,"SRCma",CalculatedBars+IndPeriod2+1,rangeN,IndPeriod1,1,i);
double Ind2=iCustom(NULL,0,"SRCma",CalculatedBars+IndPeriod2+1,rangeN,IndPeriod2,1,i);
ind_buffer2[i]=Ind1-Ind2;
ind_buffer3[i]=iMAOnArray(ind_buffer2,0,MAPeriod,0,MODE_SMA,i);
ind_buffer1[i]=ind_buffer2[i]-ind_buffer3[i];
if(ind_buffer1[i]>0 && ind_buffer1[i+1]<=0)
{
dn_buffer1[i]=0;
dn_buffer2[i]=0;
up_buffer1[i]=Low[i];
up_buffer2[i]=0;
}
if(ind_buffer1[i]<0 && ind_buffer1[i+1]>=0)
{
up_buffer1[i]=0;
up_buffer2[i]=0;
dn_buffer1[i]=High[i];
dn_buffer2[i]=0;
}
if((ind_buffer1[i]>0 && ind_buffer1[i+1]>0) ||
(ind_buffer1[i]<0 && ind_buffer1[i+1]<0))
{
dn_buffer1[i]=0;
dn_buffer2[i]=0;
up_buffer1[i]=0;
up_buffer2[i]=0;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments