RD-ForecastOsc_v3
Download scriptThis script is designed as a technical analysis tool for the MetaTrader trading platform. Its primary purpose is to generate a "Forecast Oscillator," which helps traders visualize price trends and potential momentum shifts by calculating mathematical projections based on historical data.
Core Logic and Methodology
The tool operates by processing historical price information through several layers of mathematical analysis:
1. Weighted Data Collection Instead of looking at every price point equally, the script uses a "Regression" window (defined by the user). It analyzes a specific set of past closing prices to establish a baseline. It applies a weighted calculation where it identifies the relationship between the chronological order of the prices and their actual values. This helps the tool understand the current "path" the market is taking.
2. Forecast Calculation Once the historical path is established, the script calculates a "Forecast Oscillator." This is essentially a percentage-based representation of how the current price deviates from the weighted average trend it just calculated. It converts complex movement into a readable value that shows the strength or weakness of the price momentum.
3. Smoothing and Signal Projection (T3 Filtering) Raw market data is often "noisy," meaning it can have jagged, unpredictable movements that make it hard to see the true trend. To solve this, the script applies a specific type of smoothing filter known as a T3 moving average logic.
- This filter takes the raw forecast data and processes it multiple times.
- By layering these calculations on top of each other, it reduces market noise.
- The result is a smoother, more refined line that highlights the underlying trend without the distracting fluctuations of minute-to-minute price changes.
Visual Output
On your trading chart, this logic produces two distinct lines in a separate window:
- The Primary Forecast: This shows the immediate oscillator value derived from the weighted regression.
- The Smoothed Signal: This represents the refined trend, allowing traders to see the broader direction of the price momentum more clearly.
Summary for Traders
In simple terms, this script looks at a specific chunk of past price history, determines the "weight" of that history to find a trend line, calculates how far the current price is moving away from that trend, and then smooths out all the "jitter" so you can see the underlying momentum more clearly.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| forecast osc.mq4 |
//| Copyright © 2005, Nick Bilak, beluck[AT]gmail.com |
//| http://metatrader.50webs.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak"
#property link "http://metatrader.50webs.com/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_level1 0
#property indicator_color1 SteelBlue
#property indicator_color2 Red
//---- input parameters
extern int Regress= 15;
extern int T3= 3;
extern double B= 0.7;
//---- buffers
double Osc[];
double Osct3[];
double HiSig[];
double LoSig[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Osc);
SetIndexEmptyValue(0,0);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Osct3);
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars= IndicatorCounted(),
limit;
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit= Bars - counted_bars;
ForecastOsc(0, limit, Osc, Osct3, Regress, T3, B);
return (0);
}
//+------------------------------------------------------------------+
//| Calc forecast buffers from lastbar down to offset |
//+------------------------------------------------------------------+
void ForecastOsc(int offset, int lastbar, double &osc[], double &osct3[], int regress, int t3, double b)
{
int shift, length, warmup= 30;
double b2=b*b,
b3=b2*b,
c1=-b3,
c2=(3*(b2+b3)),
c3=-3*(2*b2+b+b3),
c4=(1+3*b+b3+3*b2),
n = 1 + 0.5*(t3-1),
w1 = 2 / (n + 1),
w2 = 1 - w1,
wt,forecastosc,t3_fosc,sum,
e1,e2,e3,e4,e5,e6,tmp,tmp2;
lastbar= MathMin(Bars-warmup-regress, lastbar);
for (shift= lastbar+warmup; shift>=offset; shift--) {
length= regress;
sum = 0;
for (int i = length; i>0; i--) {
tmp = length+1;
tmp = tmp/3;
tmp2 = i;
tmp = tmp2 - tmp;
sum = sum + tmp*Close[shift+length-i];
}
tmp = length;
wt = sum*6/(tmp*(tmp+1));
forecastosc= (Close[shift]-wt)/wt*100;
e1 = w1*forecastosc + w2*e1;
e2 = w1*e1 + w2*e2;
e3 = w1*e2 + w2*e3;
e4 = w1*e3 + w2*e4;
e5 = w1*e4 + w2*e5;
e6 = w1*e5 + w2*e6;
t3_fosc = c1*e6 + c2*e5 + c3*e4 + c4*e3;
if (shift<=lastbar) { // don't put swing in cycle into the signal buffers
osc[shift] = forecastosc;
osct3[shift] = t3_fosc;
}
}
return(0);
}
Comments