YALEWANG: and made code below ,but it does not work ,may you point the erro out ?
- Your erro is not stating a problem. There are no mind readers here. "Does not work" tells us nothing.
- What does EMA( EMA(10,C), 10 ) - EMA( EMA(10,C), 15) mean.
iMA(NULL,5
You are getting iMA off the M5 chart but are using Bars which is only for the current chart. You are also getting M5 shift X and showing that in current chart shift X. All invalid unless your chart is M5.
thank you WHRoeder
1, the problem is no lines draw out on chart ;
2, EMA( EMA(10,C), 10 ) - EMA( EMA(10,C), 15) comes from the Imacd method MacdBuffer ;
3,macd function is calculate on close price ,my function is calculate on Ma5 price .
i add print function to check the value of three array , b1 and b3 has value ,b2 is 0
if (CBars >= Bars) CBars = Bars; for (int i1=0;i1<CBars;i1++) b1[i1]=iMA(NULL,5,10,0,MODE_EMA,PRICE_CLOSE,i1); Print("b1[10]=",b1[10]); for(int i2=0; i2<CBars; i2++) b2[i2]=iMAOnArray(b1,CBars,10,0,MODE_EMA,i2)-iMAOnArray(b1,CBars,15,0,MODE_EMA,i2); Print("b2[10]=",b2[10]); for(int i3=0; i3<CBars; i3++) b3[i3]=iMAOnArray(b2,CBars,10,0,MODE_SMA,i3); Print("b3[10]=",b3[10]); Print(GetLastError()); return(0);
YALEWANG:
2, EMA( EMA(10,C), 10 ) - EMA( EMA(10,C), 15) comes from the Imacd method MacdBuffer ;
3,macd function is calculate on close price ,my function is calculate on Ma5 price .
- From the standard macd.mql4
for(int i=0; i<limit; i++) MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i) -iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i); //---- signal line counted in the 2-nd buffer for(i=0; i<limit; i++) SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
Do you see any EMA(EMA)? - Why aren't you just using a MTF MACD indicator from the codebase?
i find why ?
it is array size make it .
int start() { if (CBars >= Bars) CBars = Bars; for (int i1=0;i1<CBars;i1++) b1[i1]=iMA(NULL,5,10,0,MODE_EMA,PRICE_CLOSE,i1); for(int i2=0; i2<CBars; i2++) b2[i2]=iMAOnArray(b1,Bars,10,0,MODE_EMA,i2)-iMAOnArray(b1,Bars,15,0,MODE_EMA,i2); for(int i3=0; i3<CBars; i3++) b3[i3]=iMAOnArray(b2,Bars,10,0,MODE_SMA,i3); Print(GetLastError()); return(0); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
i want to use macd method on MA5 lines and made code below ,but it does not work ,may you point the erro out ?
thanks
#property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_width1 1 #property indicator_color2 Blue #property indicator_width2 1 int CBars = 5000; double b1[]; double b2[]; double b3[]; int init() { IndicatorBuffers(3); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,b3); SetIndexBuffer(1,b2); SetIndexBuffer(2,b1); SetIndexLabel(0,"imacd"); //ArraySetAsSeries(b1,true);ArraySetAsSeries(b2,true); return(0); } int start() { if (CBars >= Bars) CBars = Bars; for (int i1=0;i1<CBars;i1++) b1[i1]=iMA(NULL,5,10,0,MODE_EMA,PRICE_CLOSE,i1); for(int i2=0; i2<CBars; i2++) b2[i2]=iMAOnArray(b1,CBars,10,0,MODE_EMA,i2)-iMAOnArray(b1,CBars,15,0,MODE_EMA,i2); for(int i3=0; i3<CBars; i3++) b3[i3]=iMAOnArray(b2,CBars,10,0,MODE_SMA,i3); Print(GetLastError()); return(0); }