Miscellaneous
0
Views
0
Downloads
0
Favorites
All ForecastOscillator-Problem
//+------------------------------------------------------------------+
//| Forecast Oscillator.mq4 |
//| Copyright © 2005, Nick Bilak, beluck[AT]gmail.com |
//| http://forexsystems.ru/phpBB/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak, beluck[AT]gmail.com"
#property link "http://forexsystems.ru/phpBB/index.php"
//
//
//
//
//
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_level1 0
#property indicator_color1 DarkTurquoise
#property indicator_color2 LawnGreen
#property indicator_color3 Magenta
#property indicator_color4 Aqua
//---- input parameters
extern int regress=15;
extern int t3=10;
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;
//---- input parameters
//
//
//
//
//
extern string _ = "Parameters";
extern int PriceField = 0;
extern string __ = "Chose timeframes (as in periodicity bar)";
extern string timeFrames = "M1;M5;M15;M30;H1;H4;D1;W1;MN";
extern int barsPerTimeFrame = 35;
extern bool shiftRight = False;
extern bool currentFirst = False;
extern color txtColor = Silver;
extern color separatorColor = DimGray;
//---- buffers
//
//
//
//
//
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//
//
//
//
//
string shortName;
string labels[];
int periods[];
int Shift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
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);
//----
if (shiftRight) Shift = 1;
else Shift = 0;
barsPerTimeFrame = MathMax(barsPerTimeFrame,15);
shortName = indicatorName+" ("+regress+","+t3+","+b+")";
IndicatorShortName(shortName);
//
//
//
//
//
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexShift(0,Shift*(barsPerTimeFrame+1));
SetIndexShift(1,Shift*(barsPerTimeFrame+1));
SetIndexLabel(0,"Oscillator");
SetIndexLabel(1,"Signal");
//
//
//
//
//
timeFrames = StringUpperCase(StringTrimLeft(StringTrimRight(timeFrames)));
if (StringSubstr(timeFrames,StringLen(timeFrames),1) != ";")
timeFrames = StringConcatenate(timeFrames,";");
//
//
//
//
//
int s = 0;
int i = StringFind(timeFrames,";",s);
int time;
string current;
while (i > 0)
{
current = StringSubstr(timeFrames,s,i-s);
time = stringToTimeFrame(current);
if (time > 0) {
ArrayResize(labels ,ArraySize(labels)+1);
ArrayResize(periods,ArraySize(periods)+1);
labels[ArraySize(labels)-1] = current;
periods[ArraySize(periods)-1] = time; }
s = i + 1;
i = StringFind(timeFrames,";",s);
}
//
//
//
//
//
if(currentFirst)
for (i=1;i<ArraySize(periods);i++)
if (Period()==periods[i])
{
string tmpLbl = labels[i];
int tmpPer = periods[i];
//
//
//
//
//
for (int k=i ;k>0; k--) {
labels[k] = labels[k-1];
periods[k] = periods[k-1];
}
labels[0] = tmpLbl;
periods[0] = tmpPer;
}
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
for(int l=0;l<ArraySize(periods);l++) {
ObjectDelete(indicatorName+l);
ObjectDelete(indicatorName+l+"label");
}
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 ib = length; ib>0; ib--) {//ubah i ke ii
tmp = length+1;
tmp = tmp/3;
tmp2 = ib;//ubah i ke ii
tmp = tmp2 - tmp;
sum = sum + tmp*Close[shift+length-ib]; //ubah i ke ii
}
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;
{//tambahan utk balance parenteses
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;
}
Comment("WT=",WT);
}
return(0);
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
string separator;
int window=WindowFind(shortName);
int k=0;
//
//
//
//
for(int p=0; p<ArraySize(periods);p++)
{
for(int i=0; i<barsPerTimeFrame;i++,k++)//adjust ii
{
ExtMapBuffer1[k] = iCustom(NULL,periods[p],regress,t3,b,PriceField,0,i);//buang iOscillator
ExtMapBuffer2[k] = iCustom(NULL,periods[p],regress,t3,b,PriceField,1,i);//buang iOscillator
ExtMapBuffer3[k] = iCustom(NULL,periods[p],regress,t3,b,PriceField,2,i);//buang iOscillator
ExtMapBuffer4[k] = iCustom(NULL,periods[p],regress,t3,b,PriceField,3,i);//buang iOscillator
}
ExtMapBuffer1[k] =EMPTY_VALUE;
ExtMapBuffer2[k] =EMPTY_VALUE;
ExtMapBuffer3[k] =EMPTY_VALUE;
ExtMapBuffer4[k] =EMPTY_VALUE;
k += 1;
//
//
//
//
//
separator = indicatorName+p;
if(ObjectFind(separator)==-1)
ObjectCreate(separator,OBJ_TREND,window,0,0);
ObjectSet(separator,OBJPROP_TIME1,barTime(k-Shift*(barsPerTimeFrame+1)-1));
ObjectSet(separator,OBJPROP_TIME2,barTime(k-Shift*(barsPerTimeFrame+1)-1));
ObjectSet(separator,OBJPROP_PRICE1, 0);
ObjectSet(separator,OBJPROP_PRICE2,100);
ObjectSet(separator,OBJPROP_COLOR ,separatorColor);
ObjectSet(separator,OBJPROP_WIDTH ,2);
separator = indicatorName+p+"label";
if(ObjectFind(separator)==-1)
ObjectCreate(separator,OBJ_TEXT,window,0,0);
ObjectSet(separator,OBJPROP_TIME1,barTime(k-Shift*(barsPerTimeFrame+1)-5));
ObjectSet(separator,OBJPROP_PRICE1,100);
ObjectSetText(separator,labels[p],9,"Arial",txtColor);
}
//
//
//
//
//
SetIndexDrawBegin(0,Bars-k);
SetIndexDrawBegin(1,Bars-k);
return(0);
}
//+------------------------------------------------------------------+
//+ Custom functions and procedures +
//+------------------------------------------------------------------+
int barTime(int a)
{
if(a<0)
return(Time[0]+Period()*60*MathAbs(a));
else return(Time[a]);
}
//+------------------------------------------------------------------+
//+ +
//+------------------------------------------------------------------+
//
//
//
//
//
int stringToTimeFrame(string TimeFrame)
{
int TimeFrameInt=0;
if (TimeFrame=="M1") TimeFrameInt=PERIOD_M1;
if (TimeFrame=="M5") TimeFrameInt=PERIOD_M5;
if (TimeFrame=="M15") TimeFrameInt=PERIOD_M15;
if (TimeFrame=="M30") TimeFrameInt=PERIOD_M30;
if (TimeFrame=="H1") TimeFrameInt=PERIOD_H1;
if (TimeFrame=="H4") TimeFrameInt=PERIOD_H4;
if (TimeFrame=="D1") TimeFrameInt=PERIOD_D1;
if (TimeFrame=="W1") TimeFrameInt=PERIOD_W1;
if (TimeFrame=="MN") TimeFrameInt=PERIOD_MN1;
return(TimeFrameInt);
}
//
//
//
//
//
string StringUpperCase(string str)
{
string s = str;
int lenght = StringLen(str) - 1;
int char;
while(lenght >= 0)
{
char = StringGetChar(s, lenght);
//
//
//
//
//
if((char > 96 && char < 123) || (char > 223 && char < 256))
s = StringSetChar(s, lenght, char - 32);
else
if(char > -33 && char < 0)
s = StringSetChar(s, lenght, char + 224);
//
//
//
//
//
lenght--;
}
//
//
//
//
//
return(s);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---