BollingerBands extreme values arrow signal

 

Hi there,

I'm stuck with this thing. The idea is to generate an arrow object at current candle OpenPrice, when previous candle Open & Close is completely outside the range of 2stdv.

The code works once, but wont work "every Tick".


Thank you!

   extern int BBPeriod = 20;
   extern double BBDeviation = 2;

void OnTick()
{
   //BollingerBands 
   double MiddleBB = iBands(NULL,0,BBPeriod,BBDeviation,0,0,MODE_MAIN,0);
   double LowerBB = iBands(NULL,0,BBPeriod,BBDeviation,0,0,MODE_LOWER,0);
   double UpperBB = iBands(NULL,0,BBPeriod,BBDeviation,0,0,MODE_UPPER,0);
   
  
   //BUY SIGNAL
   if (Open[1] && Close[1]  <  LowerBB)
   ObjectCreate(NULL,"Buy",OBJ_ARROW_BUY,0,TimeCurrent(),Open[0]);
  
   //SELL SIGNAL
   if ( Open[1] && Close[1]  >  UpperBB)
   ObjectCreate(NULL,"Sell",OBJ_ARROW_SELL,0,TimeCurrent(),Open[0]);
   
 
 }
 
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
 
if (Open[1] && Close[1]  <  LowerBB)

This is wrong, you can use

if (Open[1]  <  LowerBB && Close[1]  <  LowerBB)

or

if (MathMax(Open[1] , Close[1])  <  LowerBB)
 
ObjectCreate(NULL,"Buy",OBJ_ARROW_BUY,0,TimeCurrent(),Open[0]);

You can only create an object once, so if you want more arrows, they will all have to have different names.

Either that or you can use buffers.