//+------------------------------------------------------------------+
//|                                                    Sound_Bar.mq4 |
//|                                       Copyright © 2009, NsTrader |
//|                                           NsTrader.Mql@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, NsTrader"
#property link      "NsTrader.Mql@gmail.com"

#property indicator_chart_window

extern bool Sound = true;

extern int Corner = 2;//1,2,3,4

string stad;
int Sell = 0;
int Buy = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("On");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
  
   
   if(Sound)
   {
      stad = "On";
      if(Open[0]-Close[0] > 0 && Sell == 0)
      {
         PlaySound("Ok.wav");
         Sell = 1;
         Buy = 0;
      }
   
      if(Open[0]-Close[0] < 0 && Buy == 0)
      {
         PlaySound("alert.wav");
         Sell = 0;
         Buy = 1;
      }
   }
   else 
   {
      stad = "Off";
   }
   OBJ_LABEL_("On",StringConcatenate("Sound: ",stad),20, 20,Yellow,15);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

void OBJ_LABEL_(string str="",string TEXT="",int X=0, int Y=0,color COLOR=Blue,int FONT_SIZE=10)
{
   if(ObjectFind(str) == -1)
   {
      ObjectCreate(str,OBJ_LABEL,0,0,0);
   }
   ObjectSetText(str,TEXT,FONT_SIZE,"",COLOR);
   ObjectSet(str,OBJPROP_CORNER, Corner);  
   ObjectSet(str,OBJPROP_XDISTANCE,X);
   ObjectSet(str,OBJPROP_YDISTANCE,Y);
}