MA_Angle_v1
Download scriptThis script is designed to measure and visualize the "steepness" or angle of a Moving Average (MA) on a trading chart. Rather than just showing you where the price average is, it calculates how aggressively that average is moving in relation to the market's current volatility.
Core Logic Overview
The tool works by comparing the current position of a Moving Average against its position several periods back. It then adjusts this difference based on the market's "noise" (volatility) to produce a consistent reading of the trend's momentum.
Here is the step-by-step breakdown of how the logic processes your data:
1. Establishing Reference Points The script looks at two specific points in time to determine movement:
- Current Position: It identifies the value of the Simple Moving Average at the present moment.
- Past Position: It looks back a specific distance (determined by the ATR Period) to see where that same Moving Average was previously.
2. Measuring Volatility To ensure that a price move in a "calm" market isn't treated the same as a move in a "wild" market, the script calculates the Average True Range (ATR). This represents the current volatility of the asset. By including this, the script can normalize the data, ensuring that the "angle" stays meaningful even when market conditions change drastically.
3. The Angle Calculation The final calculation combines these three elements:
- It subtracts the past Moving Average value from the current one to find the raw distance.
- It divides that distance by the volatility (ATR) to normalize the move.
- It multiplies the result by a user-defined factor to scale the movement into a visible "angle."
How to Interpret the Result
The output is displayed in a separate window as a line graph:
- Steeper Upward Slopes: Indicate a strong, aggressive bullish trend where the Moving Average is rising rapidly relative to market volatility.
- Steeper Downward Slopes: Indicate a powerful bearish trend where the Moving Average is dropping quickly.
- Flat Lines: Suggest that the market is moving sideways or "ranging," as there is little to no change in the Moving Average's position over time.
By using this logic, traders can visually distinguish between a slow, steady crawl and a high-momentum breakout by observing the intensity of the angle produced by the script.
//+------------------------------------------------------------------+
//| MA_Angle.mq4 |
//| Copyright 2009, KoliEr Li. |
//| http://kolier.li |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009, KoliEr Li."
#property link "http://kolier.li"
/*
* I here get paid to program for you. Just $15 for all scripts.
*
* I am a bachelor major in Financial-Mathematics.
* I am good at programming in MQL for Meta Trader 4 platform. The ability is between medium and top level.
* No matter what it is, create or modify any indicators, expert advisors and scripts.
* I will ask these jobs which are not too large for only $15, surely refundable if you are not appreciate mine.
* All products will deliver in 3 days.
* Also, I am providing EA, Indicator and Trade System Improvement Consultant services, contact me for the detail.
* If you need to have it done, don't hesitate to contact me at: kolier.li@gmail.com
*/
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 1
//+------------------------------------------------------------------+
//| User input variables |
//+------------------------------------------------------------------+
extern string IndicatorName = "MA_Angle"; // For Logging
extern int MAPeriod = 50; // MA Period
extern int ATRPeriod = 10; // 10% of MAPeriod
extern double ATRFactor = 50; // 500 = ATRPeriod * ATRFactor
extern int BarsToLoad = 1000; // Change to 0 to count all bars.
//+------------------------------------------------------------------+
//| Universal variables |
//+------------------------------------------------------------------+
double ma, ma_pre, atr;
double buffer_angle[];
double buffer_ma[], buffer_ma_pre[], buffer_atr[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName(IndicatorName);
IndicatorBuffers(4);
SetIndexBuffer(0, buffer_angle);
SetIndexStyle(0, DRAW_LINE);
SetIndexLabel(0, "MA Angle");
SetIndexBuffer(1, buffer_ma);
SetIndexStyle(1, DRAW_NONE);
SetIndexBuffer(2, buffer_ma_pre);
SetIndexStyle(2, DRAW_NONE);
SetIndexBuffer(3, buffer_atr);
SetIndexStyle(3, DRAW_NONE);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int bars_counted = IndicatorCounted();
if(bars_counted < 0)
{
return(1);
}
bars_counted--;
int limit = Bars - bars_counted;
if(limit>BarsToLoad && BarsToLoad>0)
{
limit = BarsToLoad;
}
for(int i=limit; i>=0; i--)
{
buffer_ma[i] = iMA(Symbol(), 0, MAPeriod, 0, MODE_SMA, PRICE_CLOSE, i);
buffer_ma_pre[i] = iMA(Symbol(), 0, MAPeriod, 0, MODE_SMA, PRICE_CLOSE, i+ATRPeriod);
buffer_atr[i] = iATR(Symbol(), 0, ATRPeriod, i);
}
for(int j=limit; j>=0; j--)
{
buffer_angle[j] = ATRFactor*(buffer_ma[j]-buffer_ma_pre[j])/buffer_atr[j];
}
return(0);
}
Comments