EA Bollingerband & CCI Alarm Help

 

Hi there. I've some problem that I know some one on this forum can help me with.

 I have a idé and some code to set an alarm.

 Primery trigger:

If cangle < iBands go to next trigger

 

 

secondary trigger: If the CCI is between -170 & -120 Trigger alarm (Buy)

 

 

First of all i dont know how to make the secondary trigger trigger after the first one if that one is true.

I to get them all to work but only if all of them are on the same candle. 

And also my alarm is not trigged once but when everything is TRUE it keeps trigger the alrm until its FALSE. 

but first problem first:

//+------------------------------------------------------------------+
//|                                   Bollinger Band & CCI Alarm.mq4 |
//|                                   Copyright 2013, Mathias Halén. |
//|                                       http://www.mathiashalen.se |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Mathias Halén."
#property link      "http://www.mathiashalen.se"

//--- input parameters
extern double     CCIPeriod;
extern double     BBPeriod;
double            CCI;
double            CCIDelay;
double            BBHigh;
double            BBLow;
double            candle;
extern bool       buyFilter1=true;
extern double     buyFilter1.upperLimit=-170;
extern double     buyFilter1.lowerLimit=-120;
extern bool       sellFilter1=true;
extern double     sellFilter1.upperLimit=170;
extern double     sellFilter1.lowerLimit=120;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int start(){

//----------------indicators

   CCI               =iCCI(Symbol(),0,14,0,0);
   CCIDelay          =iCCI(Symbol(),0,14,0,2);
   BBHigh            =iBands(Symbol(),0,20,2,0,0,1,0);
   BBLow             =iBands(Symbol(),0,20,2,0,0,2,0);
   candle            =iClose(Symbol(),0,0);


//----------------CCI BUY CODE
   if (
      candle<BBLow
      &&
      CCI<buyFilter1.lowerLimit && CCI>buyFilter1.upperLimit
      &&
      CCIDelay<CCI
       ){
      Alert("BUY");
     
         } //CCI>OLD

//----------------CCI SELL CODE
   if (
      candle>BBHigh
      &&
      CCI>sellFilter1.lowerLimit && CCI<sellFilter1.upperLimit
      &&
      CCIDelay>CCI
       ){
      Alert("SELL");
         } //CCI<OLD
   return(0);
}
//----
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

 

 I do get the candle to trigger everything right but the CCIDelay i don't get to be trigged on the sekendary trigger.

 

 -------------------------------------------------------------------------------------------------------

 

Update:

i change the code to this and the only thing know is to have the alarm only playing once. how do i do that?

   if (candle<BBLow){            //primery
         if(                     //sekendary
            CCI<buyFilter1.lowerLimit && CCI>buyFilter1.upperLimit
            &&
            CCIDelay<CCI
            )
       {
            Alert("BUY");
            }                    //END sekendary
       }                         //END primery

//----------------CCI SELL CODE
   if (candle>BBHigh){           //primery
         if (                    //sekendary
            CCI>sellFilter1.lowerLimit && CCI<sellFilter1.upperLimit
            &&
            CCIDelay>CCI
            )
       {
            Alert("SELL");
            }                    //END sekendary
       }                         //END primery
   return(0);
}
 

mattehalen:

Primery trigger: If cangle < iBands go to next trigger

secondary trigger: If the CCI is between -170 & -120 Trigger alarm (Buy)

#define OP_NONE 0
static int primary = OP_NONE;
if   (candle < ibandLower) primary = OP_BUY;   // Remember
else (candle > ibandUpper) primary = OP_SELL;
if(primary == OP_Buy && -170 < CCI && CCI < -120){
   primary = OP_NONE; DoBuy();
}
 
WHRoeder:


Thank you for the code.

I did get that part to work.

if (candle<BBLow){            //primery
         if(                     //sekendary
            CCI<buyFilter1.lowerLimit && CCI>buyFilter1.upperLimit
            &&
            CCIDelay<CCI
            )
       {
               ObjectCreate("line"+objcount,OBJ_VLINE,0,Time[0],0,0,0);
               ObjectSet("line"+objcount,OBJPROP_COLOR,Green);
               Alert("BUY");
            return;
               
            }                    //END sekendary
       }                         //END primery

 

 

But i still dont get the alarm to play only once.

 
if (candle<BBLow){            //primery
         if(                     //sekendary
            CCI<buyFilter1.lowerLimit && CCI>buyFilter1.upperLimit
That code means they must BOTH be true at the same time (in the SAME candle) That's not what you asked for and not what I give you.
Reason: