//+------------------------------------------------------------------+
//|    Binary Options                                                |
//+------------------------------------------------------------------+
#property copyright ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_width1 1
#property indicator_color2 Red
#property indicator_width2 1


double dUpCCIBuffer[];
double dDownCCIBuffer[];


int RowNum     = 0;
int LastTrend  = -1;
int UP_IND     = 1;
int DOWN_IND   = 0;
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping  
    SetIndexBuffer(0,dUpCCIBuffer);
    SetIndexBuffer(1,dDownCCIBuffer);  
 
//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,233); //241 option for different arrow head
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,234); //242 option for different arrow head

    
//----
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);

//---- name for DataWindow
    SetIndexLabel(0,"Buy");
    SetIndexLabel(1,"Sell");

//----


   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int nBars,nCountedBars;

    nCountedBars=IndicatorCounted(); //ncountedbars 655
//---- check for possible errors
    if(nCountedBars<0) return(-1);
//---- last counted bar will be recounted    
    if(nCountedBars<=3)
       nBars=Bars-nCountedBars-4;
    
    if(nCountedBars>2)
      {
       nCountedBars--;
       nBars=Bars-nCountedBars-1; //number of bars in current chart-655-1
      }

int lastCloseLong=0;
int lastCloseShort=0;

 for (int ii=Bars; ii>0; ii--){
   
	dUpCCIBuffer[ii]=0;
	dDownCCIBuffer[ii]=0;

	double myCCInow  = iCCI(NULL,0,10,PRICE_OPEN,ii);           //CCI now  
	double myCCI2    = iCCI(NULL,0,10,PRICE_OPEN,ii+1);         //CCI one bar ago
	double myCCI3    = iCCI(NULL,0,10,PRICE_OPEN,ii+2);         //CCI two bars ago
   double RSInow    =iRSI(NULL,0,10,PRICE_OPEN,ii);                    //RSI now
   double RSI2      =iRSI(NULL,0,10,PRICE_OPEN,ii+1);                  //RSI one bar ago
   double TDI4now      =iCustom(NULL,0,"TDI",13,0,34,2,0,7,0,4,ii);    //green line now
   double TDI5now      =iCustom(NULL,0,"TDI",13,0,34,2,0,7,0,5,ii);    //red line now
   double TDI4_2      =iCustom(NULL,0,"TDI",13,0,34,2,0,7,0,4,ii+1);   //green line one bar ago
   double TDI5_2      =iCustom(NULL,0,"TDI",13,0,34,2,0,7,0,5,ii+1);   //red line one bar ago
   double STOCHmn     = iStochastic(NULL,0,8,3,3,0,0,MODE_MAIN,ii);
	double STOCHsg     = iStochastic(NULL,0,8,3,3,0,0,MODE_SIGNAL,ii);
   
//-------------------LONG TRADES---------------------------------------------------- 
 
	if((myCCInow > 105 && myCCI2 < 90.5000) && (myCCI3 < 100 && myCCInow > myCCI2+25.0000) 
	&& (RSInow > RSI2+3.0000) && (RSInow < 70) && (TDI4now > TDI5now) && (STOCHmn > STOCHsg)) {    
	{     
	dUpCCIBuffer[ii] = Low[ii] - 40 * MarketInfo(Symbol(),MODE_POINT);
  } 
 }
   if((myCCInow < 0 && myCCI2 < 0 && myCCInow < myCCI2+25.0000) && (RSInow < RSI2+3.0000)
   && (RSInow > 30) && (TDI4now < TDI5now) && (STOCHmn < STOCHsg)) {
   {
   dUpCCIBuffer[ii] = Low[ii] - 40 * MarketInfo(Symbol(),MODE_POINT);
   }
   } 
   if((myCCInow > -105 && myCCI2 < -90.5000 && myCCInow > myCCI2+25.0000) 
   && (RSInow > RSI2+3.0000)&& (RSInow < 70) && (TDI4now > TDI5now) && (STOCHmn > STOCHsg)) {
   {
   dUpCCIBuffer[ii] = Low[ii] - 40 * MarketInfo(Symbol(),MODE_POINT);
   }
   }
   if((myCCInow > 105 && myCCI2 > 100) && (myCCInow > myCCI2+25.0000) 
   && (RSInow > RSI2+3.0000)&& (RSInow < 70) && (TDI4now > TDI5now) && (STOCHmn > STOCHsg)) {
   {
   dUpCCIBuffer[ii] = Low[ii] - 40 * MarketInfo(Symbol(),MODE_POINT);
   }
   }
   if((TDI4now > TDI5now && TDI4_2 < TDI5_2) && (STOCHmn > STOCHsg)) {
   {
   dUpCCIBuffer[ii] = Low[ii] - 40 * MarketInfo(Symbol(),MODE_POINT);
   }
   } 

//------------------SHORT TRADES----------------------------------------------------

 
	if((myCCInow < 90.5000 && myCCI2 > 105) && (myCCInow < myCCI2-25.0000) 
	&& (RSInow < RSI2-3.0000) && (RSInow > 30) && (TDI4now < TDI5now) && (STOCHmn < STOCHsg && STOCHmn < 80)) {
   {     
	dDownCCIBuffer[ii] = High[ii] + 40 * MarketInfo(Symbol(),MODE_POINT);
    }
   }	

   if((myCCInow < -100 && myCCI2 > -90.5000) && (myCCI3 > -100 && myCCInow < myCCI2-25.0000) 
   && (RSInow < RSI2-3.0000)&& (RSInow > 30) && (TDI4now < TDI5now) && (STOCHmn < STOCHsg)) {
   {
   dDownCCIBuffer[ii] = High[ii] + 40 * MarketInfo(Symbol(),MODE_POINT);
   }
   }
   if((myCCInow < -105 && myCCI2 < -100) && (myCCInow < myCCI2+25.0000) 
   && (RSInow < RSI2+3.0000) && (RSInow > 30) && (TDI4now < TDI5now) && (STOCHmn < STOCHsg)) {
   {
   dDownCCIBuffer[ii] = High[ii] + 40 * MarketInfo(Symbol(),MODE_POINT);
   }
   }
   if((TDI4now < TDI5now && TDI4_2 > TDI5_2) && (STOCHmn < STOCHsg && STOCHmn > 20)) {
   {
   dDownCCIBuffer[ii] = High[ii] + 40 * MarketInfo(Symbol(),MODE_POINT);
   }
   }   

 
  } 
 }


