create your own

Price Forecast Oscillator - Custom MT4 Indicator

76
rate or flag this page

By ForexCashBack



Description

The Forecast Oscillator is an extension of the linear regression based indicators made popular by Tushar Chande. The Forecast Oscillator plots the percentage difference between the forecast price (generated by an x-period linear regression line) and the actual price. The oscillator is above zero when the forecast price is greater than the actual price. Conversely, it's less than zero if its below. In the rare case when the forecast price and the actual price are the same, the oscillator would plot zero.

Interpretation

Actual prices that are persistently below the forecast price suggest lower prices ahead. Likewise, actual prices that are persistently above the forecast price suggest higher prices ahead. Short-term traders should use shorter time periods and perhaps more relaxed standards for the required length of time above or below the forecast price. Long-term traders should use longer time periods and perhaps stricter standards for the required length of time above or below the forecast price.

Chande also suggests plotting a three-day moving average trigger line of the Forecast Oscillator to generate early warnings of changes in trend. When the oscillator crosses below the trigger line, lower prices are suggested. When the oscillator crosses above the trigger line, higher prices are suggested. It has the suggested three day moving average incorporated into it, so no worries about needing to add one!

I recommended the following strategy for best results:
Time Frame: M30-D1

Short position when the regress line has crossed the t3 line.
How will you know? A pink square box will result above the trigger line

Long Position when the regress line has crossed the t3 line.
How will you know? A blue square box will result below the trigger line.

If you want to get in the market sooner (more risk and false signals) you can place a long position when the regress line cross above the trigger line and vice a versa for a short position. And use the square boxes as an exit point signal.


To incorporate this indicator into your trading, I have provided the code below.
For those that need instructions:
1.Open up MetaEditor through the MT4 terminal
2.Click on "File" ---> New
3.Choose Customer Indicator
4. Click "Next"
5. Put in desired indicator name
6. Click "Next"
7. Check box that says "Indicator in Seperate Window"
8. Click "Finish"
9. Delete the generic code
10.Copy the code below
11. Paste the code
12. Compile it to make sure it has not errors/warning
13. Should be zero errors/warning
14. Save
15. Restart MT4 terminal ---> You should now have your new indicator under the custom indicator heading and able to attach it to any chart.


Explanation of Input Values: (experiment with these to determine the best setting/results)
Regress = Price Forecast Line
t3 = Moving Average Line
b = Shift

Trigger Line = Value of Zero - shown on indicator graph.

Code:

//+------------------------------------------------------------------+
//| forecast osc.mq4 |
//| Copyright © 2009
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_level1 0
#property indicator_color1 SteelBlue
#property indicator_color2 HotPink
#property indicator_color3 Magenta
#property indicator_color4 Aqua

//---- 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);
}
//+---------------------------------------------



To learn about candle stick patterns as a trading strategy, click here. -  Midasfx has written a very detailed hub about them.


Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working