Download MetaTrader 5

When a buysignal is triggered I do not get the sellsignal - EA

To add comments, please log in or register
Herbertioz
28
Herbertioz  
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;
 }
 if (bb<0 && AlertedShort == false) {
PlaySound("alert.wav");
SendMail("Sell "+Symbol(),"");
AlertedShort = true;
 }

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.

Tjipke de Vries
6384
Tjipke de Vries  
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
whroeder1
15934
whroeder1  
  1. That may work is AlertedLong/Short is globably declared (common) not a local non-static variable
  2. 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;
    
  3. But your test is if(BB>0) which translates to if (Close[0] > center).
  4. 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;
Herbertioz
28
Herbertioz  
deVries:

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.
To add comments, please log in or register