NavelSMA
Download scriptThis custom indicator is designed to provide a smoothed visual representation of market trends by calculating a specific type of moving average. Unlike standard moving averages that often rely solely on the closing price, this script uses a unique pricing formula to determine the "heart" of each candle before averaging them over time.
Core Logic and Mechanism
1. Custom Price Calculation (The "Navel") The foundation of this indicator is a specialized price calculation. Instead of looking at just one data point (like the high, low, or close), the script combines four different price points from each candle:
- It takes the Closing Price and gives it the highest weight.
- It takes the Opening Price and gives it significant secondary weight.
- It incorporates the High and Low prices equally.
By blending these four elements into a single weighted value, the indicator attempts to capture a more nuanced "average" of what happened during that specific time period, rather than being skewed by extreme spikes or late-session movements.
2. Moving Average Smoothing Once the script has calculated this custom price for every individual candle, it applies a Simple Moving Average (SMA) logic. It looks back over a user-defined number of previous candles (the "Period") and calculates the average of those custom prices.
This results in a smooth line that follows the general direction of the market. Because it uses the weighted price calculation mentioned above, the resulting line is intended to be more representative of the actual price action than a standard moving average.
3. Visual Adjustments The script includes three primary settings for the user:
- MA Period: This determines how many candles are averaged together. A higher number will create a smoother, slower-moving line; a lower number will make the line more reactive to sudden price changes.
- MA Shift: This allows the user to move the entire line forward or backward on the chart without changing the underlying calculation.
- Visual Display: The indicator is rendered as a solid red line directly on the trading chart window, making it easy to overlay on top of existing price candles.
Summary for Traders
In simple terms, this tool acts as a "weighted trend filter." It identifies where the market is heading by calculating a balanced average of each candle's price action and then smoothing that data out over a set period. It is designed for traders who want to see a trend line that feels more balanced and less "noisy" than standard built-in indicators.
//+------------------------------------------------------------------+
//| NavelSMA.mq4 |
//+------------------------------------------------------------------+
//| Íà áàçå (êîä ïîñòàðàëñÿ ñîõðàíèòü, êàê â îðèãèíàëå):
//| Custom Moving Average.mq4
//| Copyright © 2004, MetaQuotes Software Corp.
//| http://www.metaquotes.net/
//| Âûçîâ:
//| Val=iCustom(symbol,
//| timeframe,
//| "NavelSMA",
//| MA_Period,
//| MA_Shift,
//| 0,
//| NumBar);
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Bookkeeper"
#property link "yuzefovich@gmail.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
extern int MA_Period=13;
extern int MA_Shift=0;
double ExtMapBuffer[];
int ExtCountedBars=0;
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,MA_Shift);
if(MA_Period<2) MA_Period=2;
SetIndexBuffer(0,ExtMapBuffer);
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(Bars<=MA_Period) return(0);
ExtCountedBars=IndicatorCounted();
if (ExtCountedBars<0) return(-1);
if (ExtCountedBars>0) ExtCountedBars--;
double sum=0;
int i,pos=Bars-ExtCountedBars-1;
if(pos<MA_Period) pos=MA_Period;
for(i=1;i<MA_Period;i++,pos--)
sum+=Navel(pos);
while(pos>=0)
{
sum+=Navel(pos);
ExtMapBuffer[pos]=sum/MA_Period;
sum-=Navel(pos+MA_Period-1);
pos--;
}
/*
double pr=2.0/(MA_Period+1);
int pos=Bars-2;
if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
while(pos>=0)
{
if(pos==Bars-2) ExtMapBuffer[pos+1]=Navel(pos+1);
ExtMapBuffer[pos]=Navel(pos)*pr+ExtMapBuffer[pos+1]*(1-pr);
pos--;
}
*/
return(0);
}
//+------------------------------------------------------------------+
double Navel(int bar)
{
double price=(Close[bar]*5+Open[bar]*2+High[bar]+Low[bar])/9;
return(price);
}
Comments