//+------------------------------------------------------------------+
//|                                                   TrendTrade.mq4 |
//|                                        jesing.sumesara@gmail.com |
//+------------------------------------------------------------------+

#property copyright " Jesing Sumesara | jesing.sumesara@gmail.com | +91 93270 93276 | Trend Trade"
#property link      "  jesing.sumesara@gmail.com | +91 93270 93276"
#property version   "1.00"
//#property strict   


input int      MagicNumber=121212; // Magic Number 
input double   LotSize=1.00; // Lot Size
input double   CandleHight = 0.00025; // Candle Hight
input double   ProfitCloser = 1000; // Profit Target % Close All 

int BarsCount;
int ceqt=(AccountEquity()+ProfitCloser);

int deinit()
  {
   return(0);
  }


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int closeal()
{
  int total = OrdersTotal();
  for(int ji=total-1;ji>=0;ji--)
  {
    if(!OrderSelect(ji, SELECT_BY_POS)) continue;
    int type   = OrderType();

    bool result = false;
    
    switch(type)
    {
      //Close opened long positions
      case OP_BUY       : result = OrderMagicNumber()==MagicNumber && OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                          break;
      
      //Close opened short positions
      case OP_SELL      : result = OrderMagicNumber()==MagicNumber && OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Green );
                          
    }
    
  }
  
  return(0);
}




int start()
{


     
    if (Bars > BarsCount)
    {

      double CHight=DoubleToStr(Close[1]-Open[1]);
     
      
      //if (CHight>CandleHight) Alert("Stong Move High...Order Buy "+(Close[1]-Open[1]));
      //if(CHight<-CandleHight) Alert("Stong Move Low....Order Sell"+(Close[1]-Open[1]));

      if (CHight>CandleHight) int ticketB=OrderSend(Symbol(),OP_BUY,LotSize,Ask,0,Ask-25*Point,0,NULL,MagicNumber,0,Blue);
      if (CHight<-CandleHight) int ticketS=OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,Bid+25*Point,0,NULL,MagicNumber,0,Red);

      Comment(DoubleToStr(CHight));
      
      BarsCount = Bars;
      
    }   
    
    {
    if (AccountEquity()>ceqt) closeal();
    }

    {
    if (AccountEquity()>ceqt) ceqt=(AccountEquity()+ProfitCloser);
    }

 
   return(0);
   
//-------------------------------------
   

}




//-------------------------------------

//void Breakeven1()
//{  int total = OrdersTotal()-1;
//      if (total >= 0)
//      {
//         for(int cnt=0;cnt<total;cnt++)
//         {
//             if(OrderSelect(cnt,SELECT_BY_POS))
//            {
//               if (OrderType() == OP_BUY)
//                 {
//                 if (Bid > (OrderOpenPrice()+0.00100))
//                 {
//                    int ib=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);
//                  }
//               }
//               if (OrderType() == OP_SELL)
//               {
//                  if (Ask < (OrderOpenPrice()-0.00100))
//                  {
//                   int is=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);   
//                  }
//                }
//            }
//         }
//      } 
//}
//



