//+------------------------------------------------------------------+
//|                                            Jason Cross beta1.mq4 |
//|                                                  COPYRIGHT robert|
//|                                                  COPYRIGHT robert|
//+------------------------------------------------------------------+
#property copyright "COPYRIGHT robert"
#property link      "COPYRIGHT robert"

#property indicator_chart_window

extern   int      StopLoss=40;
extern   string   SoundFileName="Alert.wav";


static   bool FT=true,PS, ExitBuyTrade,ExitSellTrade, BuyTrade,SellTrade;


int init()
{

   return(0);
}

int deinit()
{
   Comment("");
   return(0);
}

int start()
{


   Comment("The indicator is working properly.");
   
   if(PS)
   {
      PlaySound(SoundFileName);
      PS=false;
   }

   string   cmt;

   double   EMA5=iMA(Symbol(),0,5,0,MODE_EMA,PRICE_CLOSE,0);
   double   EMA12=iMA(Symbol(),0,12,0,MODE_EMA,PRICE_CLOSE,0);
   double   RSI=iRSI(Symbol(),0,21,PRICE_CLOSE,0);
   
   if(FT)
   {
      FT=false;
      if(EMA5>EMA12 && RSI>50)
         BuyTrade=true;
         
      if(EMA5<EMA12 && RSI<50)
         SellTrade=true;

   }
      
   

   if(EMA5>EMA12 && RSI>50 && !BuyTrade)
   {// buy
      BuyTrade=true;
      SellTrade=false;

      cmt= "We have a buy signal.";
      Alert(cmt);

      cmt=DoubleToStr(TimeCurrent(),0);
      ObjectCreate(cmt,OBJ_ARROW,0,Time[0],Bid);
      ObjectSet(cmt,OBJPROP_ARROWCODE,241);
      ObjectSet(cmt,OBJPROP_COLOR,Orange);
      ObjectSet(cmt,OBJPROP_WIDTH,5);
      
      cmt="Place stop loss at "+ DoubleToStr(Bid-StopLoss*Point,Digits);
      Alert(cmt);
      
      PS=true;
      
      ExitBuyTrade=true;
   }
   
   if(ExitBuyTrade)
   {
      if((EMA5<EMA12) || RSI<47)
      {
         ExitBuyTrade=false;
         cmt= "Exit our long trade now.";
         Alert(cmt);
         PS=true;
      }
   }



   if(EMA5<EMA12 && RSI<50 && !SellTrade)
   {// sell
      BuyTrade=false;
      SellTrade=true;

      cmt= "We have a sell signal.";
      Alert(cmt);

      cmt=DoubleToStr(TimeCurrent(),0);
      ObjectCreate(cmt,OBJ_ARROW,0,Time[0],Bid);
      ObjectSet(cmt,OBJPROP_ARROWCODE,242);
      ObjectSet(cmt,OBJPROP_COLOR,Yellow);
      ObjectSet(cmt,OBJPROP_WIDTH,5);
      
      cmt="Place stop loss at "+ DoubleToStr(Bid+StopLoss*Point,Digits);
      Alert(cmt);
      
      PS=true;
      
      ExitSellTrade=true;
   }
   
   if(ExitSellTrade)
   {
      if(EMA5>EMA12 || RSI>53)
      {
         ExitSellTrade=false;
         cmt= "Exit our short trade now.";
         Alert(cmt);
         PS=true;
      }
   }






   return(0);
}













