Problem in setting conditions for entry and exit on indicator

 

i attached the indicator, photo of indicator and code snippet of ea. 

I have tried to set an entry and exit for this indicator but i haven't got the exact or perfect entry. It's misbehaving, my settings are terrible.

I would like to get best settings for this indicator.

I have given the indicator high period to filter the noise (159). But anyone  can set lower than this minimum 10, both in indicator and ea. 

Entry condition: Buy when color gets lime. Exit open position when trend change color to red

                       sell when color change to red. Exit position when color change to lime.

i tried to use alternating periods for indicator as in this ea. 

This are my settings. 

 //buy enter

      if(ind>=0.01 && ind<=0.15 &&indback>=0.2000) 

       //sell this if ok

      if(ind<=-0.01 && ind>=-0.25 && indback<=-0.200)

 

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
extern int period=159; //modify this periods 

extern int StopLoss=80;
extern int TakeProfit=80;
extern double Lots=0.05;
extern int Slippage=3;

extern bool UseTrail=true;

int MagicNo=12345;
int Ticket;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

//call this indicator
   double ind=iCustom(NULL,0,"Mimi",period,Black,Red,Lime,0,0);

//shift bacck
   double indshift1=iCustom(NULL,0,"Mimi",period,Black,Red,Lime,0,1);//previous 1
   double indshift2=iCustom(NULL,0,"Mimi",period,Black,Red,Lime,0,2);//previos 
       // trying different periods
   double indd=iCustom(NULL,0,"Mimi",10,Black,Red,Lime,0,0);// period 10 here 

  
    //Entry conditions
   int Total=OrdersTotal();
   if(Total<=1)
     {
      //buy enter
      if(ind>=0.01 && ind<=0.15 && indd>=0.2000)
        {
         Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,NULL,MagicNo,0,clrNONE);
        }
      //sell this if ok
      if(ind<=-0.01 && ind>=-0.25 && indd<=-0.200)
        {
         Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,NULL,MagicNo,0,clrNONE);
        }
     }

  
  
  //closing orders
   for(int b=OrdersTotal()-1; b>=0; b--)
     {
     //closing buy....
      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==MagicNo)
            if(OrderSymbol()==Symbol())
               if(OrderType()==OP_BUY)
                  if(ind<=-0.01 && ind>=-0.15 && indd<=-0.100)
                     bool buy=OrderClose(OrderTicket(),Lots,Bid,Slippage);

     }

   for(int s=OrdersTotal()-1; s>=0; s--)
     {
     //closing sell
      if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==MagicNo)
            if(OrderSymbol()==Symbol())
               if(OrderType()==OP_SELL)
                  if(fish>=0.01 && fish<=0.15 && fishd>=0.1000)
                     bool sel=OrderClose(OrderTicket(),Lots,Ask,Slippage,Blue);

     }
  }
//+------------------------------------------------------------------+
Files:
photo.PNG  15 kb
Mimi.mq4  3 kb