I'm confused
- MACD indicator
- Need Help w/Expert Advisor
- how do i get macd signals for my ea
is this close to right?
Is This close to right? for (int x=0; x<=7;x++) { RSI[x]=iRSI(NULL,0,8,PRICE_CLOSE,x); EMA=iMAOnArray(RSI,0,8,0,MODE_EMA,0); } for (x=1; x<=8;x++) { RSI1[x]=iRSI(NULL,0,8,PRICE_CLOSE,x); EMA1=iMAOnArray(RSI1,0,8,0,MODE_EMA,1); } if (EMA<iRSI(NULL,0,8,PRICE_CLOSE,0) && EMA1>iRSI(NULL,0,8,PRICE_CLOSE,0)) EnterLong=true; if (EMA>iRSI(NULL,0,8,PRICE_CLOSE,0) && EMA1<iRSI(NULL,0,8,PRICE_CLOSE,0)) EnterShort=true;
double RSI[8]; // 6 ArraySetAsSeries(RSI, true); // 1 for (int x=0; x<=7;x++) { RSI[x]=iRSI(NULL,0,8,PRICE_CLOSE,x); } EMA=iMAOnArray(RSI,0,8,0,MODE_EMA,0); // 2 for (x=1; x<=8;x++) { RSI1[x]=iRSI(NULL,0,8,PRICE_CLOSE,x); } EMA1=iMAOnArray(RSI1,0,8,0,MODE_EMA,1); // 2 if (EMA<iRSI[0] && EMA1>iRSI[0]) // 3,4 { EnterLong=true; EnterShort = false; // 5 } else if (EMA>iRSI[0] && EMA1<iRSI[0] // 3,4 { EnterShort=true; EnterLong = false; //5 } else { EnterShort = False; // 5 EnterLong = false; }
It's close.
1 ArraySetAsSeries should be set.
2 Take the EMA out of the loops.
3 You will have false signals for the cross, since Price (and therefore RSI and
EMA) is still moving on bar 0. You will detect a cross, then
it will be gone, come back, gone again.
4 You already calculated RSI for bar 0 in the loops, so you can use that array value in the EMA test instead of calculating again.
5 You might be specific on setting the booleans so you don't have old signals laying around
6 Always declare the size of an array, it is memory allocation ( not requred for arrays used as indicator buffers)