#property indicator_chart_window

#property indicator_buffers 7
#property indicator_color1 Red           // Stop Loss
#property indicator_color2 Lime          // Take Profit
#property indicator_color3 SkyBlue       // Entry
#property indicator_color4 SkyBlue          // Buy
#property indicator_color5 SkyBlue           // Sell 
#property indicator_width1 1     // 4k screen
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 1

double StopLoss[],TakeProfit[],Entry[],Buy[],Sell[];

int OnInit()
{
   SetIndexStyle(0,DRAW_ARROW); SetIndexBuffer(0,StopLoss); SetIndexLabel(0,"StopLoss"); SetIndexArrow(0,159);
   SetIndexStyle(1,DRAW_ARROW); SetIndexBuffer(1,TakeProfit); SetIndexLabel(1,"TakeProfit"); SetIndexArrow(1,159);
   SetIndexStyle(2,DRAW_ARROW); SetIndexBuffer(2,Entry); SetIndexLabel(2,"Entry"); SetIndexArrow(2,159);
   SetIndexStyle(3,DRAW_ARROW); SetIndexBuffer(3,Buy); SetIndexLabel(3,"Buy"); SetIndexArrow(3,233);
   SetIndexStyle(4,DRAW_ARROW); SetIndexBuffer(4,Sell); SetIndexLabel(4,"Sell"); SetIndexArrow(4,234);    
   
   return(INIT_SUCCEEDED);
}


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
// T Wave 

   for(int bar=1;bar<rates_total-prev_calculated-1;bar++)
   {
      // buying 
      
      if(iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,bar)>iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,bar)) // 8 above 20 buy only
      {
         if(Low[bar]<iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,bar))      // low touching 8ema or below   
         if(Open[bar]>(High[bar]-((High[bar]-Low[bar])*0.5)))       // open in top half
         if(Close[bar]>(High[bar]-((High[bar]-Low[bar])*0.5)))      // close in top half  
         if(bar==1 || (High[bar-1]>High[bar]))                      // check it entered if > bar==1
         {
            Entry[bar-1]=High[bar];
            StopLoss[bar-1]=Low[bar];
            TakeProfit[bar-1]=High[bar]+(High[bar]-Low[bar]);
            Buy[bar-1]=Low[bar-1]-(iATR(NULL,0,10,bar)/3.0);
         }
      }     
      
      // selling
      
      if(iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,bar)<iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,bar)) // 8 below 20 sell only
      {
         if(High[bar]>iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,bar))       // high touching 8 ema or above
         if(Open[bar]<(Low[bar]+((High[bar]-Low[bar])*0.5)))         // open in bottom half
         if(Close[bar]<(Low[bar]+((High[bar]-Low[bar])*0.5)))        // close in bottom half     
         if(bar==1 || (Low[bar-1]<Low[bar]))                         // check entered 
         {
            Entry[bar-1]=Low[bar];
            StopLoss[bar-1]=High[bar];
            TakeProfit[bar-1]=Low[bar]-(High[bar]-Low[bar]);
            Sell[bar-1]=High[bar-1]+(iATR(NULL,0,10,bar)/3.0);
         }
      }
   }    
  
   return(rates_total);
  }
