When a buysignal is triggered I do not get the sellsignal - EA
herbertioz:
Please see code above. When a buysignal is triggered I do not get the sellsignal. I have to restart EA to get the correct sellsignal. How can I fix this?
AlertedShort and AlertedLong is implemented for just getting 1 buysignal and 1 sellsignal and not multiples.
bool AlertedLong, AlertedShort = false; double bb, d; extern int bolingerPeriod=40; d=iStdDev(NULL,0,bolingerPeriod,MODE_SMA,0,PRICE_CLOSE,0); bb=((Close[0]+2*d - iMA(NULL,0,bolingerPeriod,0,MODE_EMA,PRICE_CLOSE,0)) / (4*d))*4-2; if (bb>0 && AlertedLong == false) { PlaySound("alert.wav"); SendMail("Buy "+Symbol(),""); AlertedLong = true; AlertedShort = false; } if (bb<0 && AlertedShort == false) { PlaySound("alert.wav"); SendMail("Sell "+Symbol(),""); AlertedShort = true; AlertedLong = false; }check if you still not get sell also value bb
- That may work is AlertedLong/Short is globably declared (common) not a local non-static variable
bb=((Close[0]+2*d - iMA(NULL,0,bolingerPeriod,0,MODE_EMA,PRICE_CLOSE,0)) / (4*d))*4-2;
You are trying (unnecessarily) to map price [2std above .. 2std below ima] to the range [+2 .. -2]. That can be simplified to:
double center = iMA(NULL,0,bolingerPeriod,0,MODE_EMA,PRICE_CLOSE,0); bb=(Close[0]- ima) / d;
- But your test is if(BB>0) which translates to if (Close[0] > center).
- If you wanted Buy when price is above the upper band, sell crosses lower band try the more readable:
bool isBuy = Close[0] > center + 2*d, isSell = Close[0] < center - 2*d;
deVries:
check if you still not get sell also value bb
check if you still not get sell also value bb
Thanks for help:) I do think that might work. I will try it when market opens again.
Please see code above. When a buysignal is triggered I do not get the sellsignal. I have to restart EA to get the correct sellsignal. How can I fix this?
AlertedShort and AlertedLong is implemented for just getting 1 buysignal and 1 sellsignal and not multiples.