forecast_osc-30M
Download scriptThis tool is designed as a visual indicator for trading platforms, specifically built to help traders identify potential trends and market momentum. It functions by analyzing historical price data to generate two primary lines on your chart and provides specific visual signals (arrows) to highlight potential entry or exit points.
Core Logic Overview
The script operates through a multi-step mathematical process to move beyond simple price tracking, aiming instead to "forecast" the movement of an asset:
1. Data Weighting and Smoothing The tool starts by looking at a specific window of historical prices (determined by the "regress" setting). Rather than treating every past price with equal importance, it applies a weighting system. This helps smooth out "noise"—the random, small price fluctuations that can often lead to false signals—allowing the underlying trend to become more visible.
2. Forecast Calculation The primary logic calculates a "Forecast Oscillator." It measures the difference between the current market price and a weighted average of recent prices. By converting this difference into a percentage, the tool creates an oscillator that shows how far the current price has deviated from its expected path.
3. Trend Projection (Triple Smoothing) To make the data even more reliable, the script takes the Forecast Oscillator and passes it through a series of three consecutive smoothing filters. This is similar to looking at a reflection in three different mirrors: each layer removes more of the "jitter" from the data, resulting in a final line that represents the most refined, long-term direction of the momentum.
Visual Outputs and Signals
The tool translates these complex calculations into three visual elements on your screen:
- Primary Lines: These show the standard oscillator and the triple-smoothed version. By watching how these two lines interact with each other and the zero level, you can get a sense of whether the market is gaining strength or losing steam.
- Buy/Sell Signals: The script automatically monitors the relationship between these lines. When specific conditions are met—essentially when the oscillator shows a significant shift in direction relative to its smoothed average—the tool places an arrow on the chart.
- A High Signal appears when the momentum suggests a potential upward move.
- A Low Signal appears when the momentum suggests a potential downward move.
Summary for the Trader
In plain terms, this script acts as a sophisticated "momentum filter." It takes raw price data, cleans it of market noise, projects where the trend is heading based on past behavior, and then alerts you with visual icons when the current price movement shows a significant departure from that trend.
//+------------------------------------------------------------------+
//| 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 4
#property indicator_level1 0
#property indicator_color1 SteelBlue
#property indicator_color2 Red
#property indicator_color3 White
#property indicator_color4 White
//---- input parameters
extern int regress=15;
extern int t3=3;
extern double b=0.7;
//---- buffers
double osc[];
double osct3[];
double hiSig[];
double loSig[];
//----
int shift,limit,length;
double b2,b3,c1,c2,c3,c4,w1,w2,n,WT,forecastosc,t3_fosc,sum,e1,e2,e3,e4,e5,e6,tmp,tmp2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//---- SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,osc);
SetIndexEmptyValue(0,0);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,osct3);
SetIndexStyle(2,DRAW_ARROW);
SetIndexBuffer(2,hiSig);
SetIndexEmptyValue(2,EMPTY_VALUE);
SetIndexArrow(2,159);
SetIndexStyle(3,DRAW_ARROW);
SetIndexBuffer(3,loSig);
SetIndexEmptyValue(3,EMPTY_VALUE);
SetIndexArrow(3,159);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-31;
if(counted_bars>=31) limit=Bars-counted_bars+2;
for(shift=limit+30;shift>=0;shift--)
{
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=t3;
//----
if (n<1) n=1;
n=1 + 0.5*(n-1);
w1=2/(n + 1);
w2=1 - w1;
//----
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;
osc[shift]=forecastosc;
osct3[shift]=t3_fosc;
//----
if (osc[shift+1] > osct3[shift+2] && osc[shift+2]<=osct3[shift+3] && osct3[shift+1]<0) loSig[shift+1]=t3_fosc-0.05;
if (osc[shift+1] < osct3[shift+2] && osc[shift+2]>=osct3[shift+3] && osct3[shift+1]>0) hiSig[shift+1]=t3_fosc+0.05;
}
return(0);
}
//+------------------------------------------------------------------+
Comments