w35260_ws_MA_or_SDL
Download scriptThis tool is a technical analysis indicator designed for the MetaTrader 4 platform. Its primary purpose is to provide visual market direction signals by combining multiple data layers into a single, easy-to-read chart display.
Core Logic Overview
The script functions by analyzing historical price data and comparing current trends against previous ones. It essentially acts as a "trend filter" that determines whether the market momentum is moving upward or downward based on two distinct operational modes.
Key Components of the Logic
1. Data Integration (The Foundation) The indicator pulls information from other existing technical tools to create its foundation. Specifically, it looks at:
- Trend Strength: It retrieves specific values from a "Colored" trend indicator to understand the underlying market sentiment.
- Moving Averages or Slope Direction: Depending on your settings, the script chooses between calculating a standard Moving Average (a smoothed average of price) or a "Slope Direction Line" (which tracks the angle and direction of price movement).
2. Dual-Mode Operation The script offers two ways to interpret the market:
- Moving Average Mode: This focuses on the interaction between a weighted moving average and current trend strength. It is ideal for traders who prefer smoothed price action.
- Slope Direction Mode: This focuses on the momentum of the price path. It is designed to detect the "lean" of the market more aggressively.
3. Dynamic Adjustment (The Deviation Factor) The logic includes a sensitivity setting (the "deviation"). This allows the script to scale how much the underlying trend strength affects the final calculation. By adjusting this, users can decide if they want the indicator to react sharply to small price fluctuations or remain steady until a major trend shift occurs.
4. Visual Output and Filtering The final result is displayed on your chart as a dynamic line. The logic performs a "comparison check" at every new price candle:
- It compares the current calculated value against the previous one.
- If the trend is moving up, it highlights the upward momentum.
- If the trend is moving down, it highlights the downward momentum.
- By setting specific values to "Empty," the script ensures that only the active direction is clearly visible, reducing chart clutter and providing a cleaner visual signal for the trader.
Summary for the User
In simple terms, this script looks at the current price trend, blends it with a secondary "strength" indicator, and then draws a line on your chart that tells you which way the wind is blowing. It ignores the noise of minor fluctuations to show you whether the overall direction is currently climbing or falling.
//+------------------------------------------------------------------+
//| w35260_ws_MA_or_SDL.mq4 |
//| IgorS |
//| igor.senych@gmail.com |
//+------------------------------------------------------------------+
#property copyright "IgorS"
#property link "igor.senych@gmail.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- input parameters
extern int w_period1 = 89;
extern int w_price1 = 0;
extern int w_mode1 = 3;
extern int w_period2 = 144;
extern int w_price2 = 0;
extern int w_mode2 = 3;
extern bool MA = false;
extern int ma_period = 55;
extern int ma_price = 0;
extern int ma_mode = 3;
extern int sl_period = 144;
extern int sl_price = 0;
extern int sl_mode = 0;
extern int dev = 1;
double val1 = 0,
val2 = 0,
MA_prv = 0,
MA_cur = 0;
//---- buffers
double ExtMapBuffer0[];
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,EMPTY,2);
SetIndexBuffer(0,ExtMapBuffer0);
SetIndexStyle(1,DRAW_LINE,EMPTY,2);
SetIndexBuffer(1,ExtMapBuffer1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
val1 = iCustom(Symbol(),0,"w35260_Colored",w_period1,w_mode1,w_price1,w_period2,w_mode2,w_price2,2,0,i);
val2 = iCustom(Symbol(),0,"w35260_Colored",w_period1,w_mode1,w_price1,w_period2,w_mode2,w_price2,2,0,i+1);
if(MA == true)
{
MA_cur = iMA(NULL,0,ma_period,0,ma_mode,ma_price,i)*(1+val1/dev);
MA_prv = iMA(NULL,0,ma_period,0,ma_mode,ma_price,i+1)*(1+val2/dev);
}
else
{
MA_cur = iCustom(Symbol(),0,"Slope_Direction_Line",sl_period,sl_mode,sl_price,2,i)*(1+val1/dev);
MA_prv = iCustom(Symbol(),0,"Slope_Direction_Line",sl_period,sl_mode,sl_price,2,i+1)*(1+val2/dev);
}
ExtMapBuffer0[i]=MA_cur;
ExtMapBuffer1[i]=MA_cur;
if(MA_cur<MA_prv)
{
ExtMapBuffer0[i]=EMPTY_VALUE;
}
if(MA_cur>MA_prv)
{
ExtMapBuffer1[i]=EMPTY_VALUE;
}
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments