This script functions as a specialized technical analysis tool designed to smooth out price fluctuations and identify underlying trends in financial markets. Instead of reacting instantly to every minor price tick, it processes a specific window of historical data to provide a clearer picture of market movement.
How the Logic Works
1. Weighted Data Processing The core logic relies on a "weighted calculation." Rather than treating all past prices equally, the script assigns a specific mathematical weight to each of the last 66 price points (the "Close" and "Open" prices).
- Prices closer to the present are given higher importance.
- As the data moves further into the past, its influence on the current calculation gradually decreases.
- The formula includes both positive and negative weights; this allows the script to subtract certain historical influences from others, effectively "filtering" out market noise or temporary anomalies that might mislead a trader.
2. Dual-Stream Analysis The script simultaneously calculates two distinct lines on your chart:
- Closing Price Filter: This tracks the weighted average of the closing prices of each candle. It represents the primary trend of where the market is "settling."
- Opening Price Filter: This tracks the weighted average of the opening prices. By comparing this against the closing price filter, traders can better observe the momentum and volatility occurring within individual time periods.
3. Precision Smoothing To ensure the final result is clean and readable, the script includes a normalization step. This rounds the complex mathematical results to a specific number of decimal places (defined by the user). This prevents the visual lines from becoming cluttered with unnecessary digits, keeping the chart professional and easy to interpret at a glance.
Summary for the User
In simple terms, this tool acts like a high-quality filter for your price charts. It looks back at the last 66 candles, performs a sophisticated "weighted average" to see which way the market is truly leaning, and draws two smooth lines on your screen. By ignoring the "jitter" of minor price changes, it helps you focus on the more significant trends in the data.
//+------------------------------------------------------------------+
//| dspFilter.mq4
//|
//+------------------------------------------------------------------+
#property copyright "Copyright 2002, Finware.ru Ltd."
#property link "http://www.finware.ru/"
//#property indicator_separate_window
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2
extern int CountBars=1000;
extern int nd=4;
//---- buffers
double Buffer1[];
double Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE,DRAW_LINE,2);
SetIndexBuffer(0,Buffer1);
SetIndexDrawBegin(0,CountBars);
SetIndexStyle(1,DRAW_LINE,DRAW_LINE,2);
SetIndexBuffer(1,Buffer2);
SetIndexDrawBegin(1,CountBars);
//----
return(0);
}
//+------------------------------------------------------------------+
//
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i,AccountedBars,shift;
AccountedBars = Bars-CountBars;
for(i=AccountedBars;i<=Bars-1;i++)
{
shift = Bars - 1 - i;
Buffer1[shift]=
0.11859648*Close[shift+0]
+0.11781324*Close[shift+1]
+0.11548308*Close[shift+2]
+0.11166411*Close[shift+3]
+0.10645106*Close[shift+4]
+0.09997253*Close[shift+5]
+0.09238688*Close[shift+6]
+0.08387751*Close[shift+7]
+0.07464713*Close[shift+8]
+0.06491178*Close[shift+9]
+0.05489443*Close[shift+10]
+0.04481833*Close[shift+11]
+0.03490071*Close[shift+12]
+0.02534672*Close[shift+13]
+0.01634375*Close[shift+14]
+0.00805678*Close[shift+15]
+0.00062421*Close[shift+16]
-0.00584512*Close[shift+17]
-0.01127391*Close[shift+18]
-0.01561738*Close[shift+19]
-0.01886307*Close[shift+20]
-0.02102974*Close[shift+21]
-0.02216516*Close[shift+22]
-0.02234315*Close[shift+23]
-0.02165992*Close[shift+24]
-0.02022973*Close[shift+25]
-0.01818026*Close[shift+26]
-0.01564777*Close[shift+27]
-0.01277219*Close[shift+28]
-0.00969230*Close[shift+29]
-0.00654127*Close[shift+30]
-0.00344276*Close[shift+31]
-0.00050728*Close[shift+32]
+0.00217042*Close[shift+33]
+0.00451354*Close[shift+34]
+0.00646441*Close[shift+35]
+0.00798513*Close[shift+36]
+0.00905725*Close[shift+37]
+0.00968091*Close[shift+38]
+0.00987326*Close[shift+39]
+0.00966639*Close[shift+40]
+0.00910488*Close[shift+41]
+0.00824306*Close[shift+42]
+0.00714199*Close[shift+43]
+0.00586655*Close[shift+44]
+0.00448255*Close[shift+45]
+0.00305396*Close[shift+46]
+0.00164061*Close[shift+47]
+0.00029596*Close[shift+48]
-0.00093445*Close[shift+49]
-0.00201426*Close[shift+50]
-0.00291701*Close[shift+51]
-0.00362661*Close[shift+52]
-0.00413703*Close[shift+53]
-0.00445206*Close[shift+54]
-0.00458437*Close[shift+55]
-0.00455457*Close[shift+56]
-0.00439006*Close[shift+57]
-0.00412379*Close[shift+58]
-0.00379323*Close[shift+59]
-0.00343966*Close[shift+60]
-0.00310850*Close[shift+61]
-0.00285188*Close[shift+62]
-0.00273508*Close[shift+63]
-0.00274361*Close[shift+64]
+0.01018757*Close[shift+65];
Buffer2[shift]=
0.11859648*Open[shift+0]
+0.11781324*Open[shift+1]
+0.11548308*Open[shift+2]
+0.11166411*Open[shift+3]
+0.10645106*Open[shift+4]
+0.09997253*Open[shift+5]
+0.09238688*Open[shift+6]
+0.08387751*Open[shift+7]
+0.07464713*Open[shift+8]
+0.06491178*Open[shift+9]
+0.05489443*Open[shift+10]
+0.04481833*Open[shift+11]
+0.03490071*Open[shift+12]
+0.02534672*Open[shift+13]
+0.01634375*Open[shift+14]
+0.00805678*Open[shift+15]
+0.00062421*Open[shift+16]
-0.00584512*Open[shift+17]
-0.01127391*Open[shift+18]
-0.01561738*Open[shift+19]
-0.01886307*Open[shift+20]
-0.02102974*Open[shift+21]
-0.02216516*Open[shift+22]
-0.02234315*Open[shift+23]
-0.02165992*Open[shift+24]
-0.02022973*Open[shift+25]
-0.01818026*Open[shift+26]
-0.01564777*Open[shift+27]
-0.01277219*Open[shift+28]
-0.00969230*Open[shift+29]
-0.00654127*Open[shift+30]
-0.00344276*Open[shift+31]
-0.00050728*Open[shift+32]
+0.00217042*Open[shift+33]
+0.00451354*Open[shift+34]
+0.00646441*Open[shift+35]
+0.00798513*Open[shift+36]
+0.00905725*Open[shift+37]
+0.00968091*Open[shift+38]
+0.00987326*Open[shift+39]
+0.00966639*Open[shift+40]
+0.00910488*Open[shift+41]
+0.00824306*Open[shift+42]
+0.00714199*Open[shift+43]
+0.00586655*Open[shift+44]
+0.00448255*Open[shift+45]
+0.00305396*Open[shift+46]
+0.00164061*Open[shift+47]
+0.00029596*Open[shift+48]
-0.00093445*Open[shift+49]
-0.00201426*Open[shift+50]
-0.00291701*Open[shift+51]
-0.00362661*Open[shift+52]
-0.00413703*Open[shift+53]
-0.00445206*Open[shift+54]
-0.00458437*Open[shift+55]
-0.00455457*Open[shift+56]
-0.00439006*Open[shift+57]
-0.00412379*Open[shift+58]
-0.00379323*Open[shift+59]
-0.00343966*Open[shift+60]
-0.00310850*Open[shift+61]
-0.00285188*Open[shift+62]
-0.00273508*Open[shift+63]
-0.00274361*Open[shift+64]
+0.01018757*Open[shift+65];
Buffer1[shift]= NormalizeDouble(Buffer1[shift],nd);
Buffer2[shift]= NormalizeDouble(Buffer2[shift],nd);
}
return(0);
}
//+------------------------------------------------------------------+
Comments