PlaySound not working on open order script

 
Hey there. I have some scripts I use to use hotkeys to place orders in mt4 using my stream deck while scalping. I didn't originally code it, but I did make some minor alterations to better suit my needs. I miss hearing the confirmation sound "ok" that one click trading makes when an order goes through.

I've been trying to get the script to play the sound but I've been unable to get it to work. I have little to no coding experience besides modifying scripts and indicators in mql4. I have watched a couple hours of basic mql4 coding instructionals trying to figure this out. Here is a copy of what appears to be my closest attempt based on it having the fewest amount of errors. I know this must be something so basic I'm missing. I've tried a variety of different things based on various threads and videos I've seen using PlaySound. Different bracket orientations and arrangements, using "ok" vs "ok.wav", etc., adding bool before playsound, a few other things. 

Like I said, this current config returns the fewest errors. The only error I'm getting is:  '{' - function definition unexpected          on the respective bracket closest above the PlaySound line at the bottom.


I wanted to figure this out on my own but at this point the time investment is getting high on it and is taking away from a lot of other things for what is probably very simple. 

The section in question is at the very bottom of this code.


Thank you anyone and everyone for your time and any assistance


enum Operation{
   buy=OP_BUY,    //BUY
   sell=OP_SELL,   //SELL
};

extern double Lots=0.01;                  //Specify position size, this is ignored if you use the Risk %
extern bool UseRiskPercentage=false;    //True if you want to use the risk % to calculate the size
extern double RiskPercentage=2;        //% of available balance to risk
input Operation Command=buy;           //Order type
extern int TakeProfit=0;              //Take Profit in pips
extern int StopLoss=0;                //Stop Loss in pips
extern int Slippage=2;                 //Slippage in pips
extern int MagicNumber=0;              //Magic number if you want to specify one
extern string Cmt="";                  //Comment for the order if you want one

//Function to normalize the digits
double CalculateNormalizedDigits()
{
   if(Digits<=3){
      return(0.01);
   }
   else if(Digits>=4){
      return(0.0001);
   }
   else return(0);
}

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()

  {
//---
   
   //If Stop Loss is not set and risk % is in use stop the program, the stop loss is required
   if(StopLoss==0 && UseRiskPercentage){
      Print("A stop loss is required if you are using a risk percentage");
      return;
   }
   
   int Cmd=Command;
   
   //Normalize the digits and calculate the position size
   double nTickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
   double nDigits=CalculateNormalizedDigits();
   if(Digits==3 || Digits==5){
      Slippage=Slippage*10;
      nTickValue=nTickValue*10;
   }
   if(UseRiskPercentage){
      Lots=(AccountBalance()*RiskPercentage/100)/(StopLoss*nTickValue);
      Lots=MathRound(Lots/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP);
   }
   
   //Set the open, stop loss and take profit prices
   double OpenPrice=0;
   double TakeProfitPrice=0;
   double StopLossPrice=0;
   if(Cmd==OP_BUY){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice+TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice-StopLoss*nDigits,Digits);
   } 
   if(Cmd==OP_SELL){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice-TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice+StopLoss*nDigits,Digits);
   } 
   
   //Print on screen the informations to see what we are submitting
   Print("Opening an Order ",Command," size ",Lots, " open price ",OpenPrice," slippage ",Slippage," SL ",StopLossPrice," TP ",TakeProfitPrice," comment ",Cmt," magic ",MagicNumber);
   
   //Submit the order, check the it has been accepted
   int OrderNumber;
   OrderNumber=OrderSend(Symbol(),Cmd,Lots,OpenPrice,Slippage,StopLossPrice,TakeProfitPrice,Cmt,MagicNumber);
   if(OrderNumber>0){
      Print("Order ",OrderNumber," open");
   }
   else{
      Print("Order failed with error - ",GetLastError());
   }
   
  }
{ 
  //---
       PlaySound("ok");
       }
  

//+------------------------------------------------------------------+

 

Hello . You were right on the command , the placement was the issue .

It won't work now as its the weekend 

#property strict
enum Operation{
   buy=OP_BUY,    //BUY
   sell=OP_SELL,   //SELL
};

extern double Lots=0.01;                  //Specify position size, this is ignored if you use the Risk %
extern bool UseRiskPercentage=false;    //True if you want to use the risk % to calculate the size
extern double RiskPercentage=2;        //% of available balance to risk
input Operation Command=buy;           //Order type
extern int TakeProfit=0;              //Take Profit in pips
extern int StopLoss=0;                //Stop Loss in pips
extern int Slippage=2;                 //Slippage in pips
extern int MagicNumber=0;              //Magic number if you want to specify one
extern string Cmt="";                  //Comment for the order if you want one
input string sound="ok";//the sound to play
//Function to normalize the digits
double CalculateNormalizedDigits()
{
   if(Digits<=3){
      return(0.01);
   }
   else if(Digits>=4){
      return(0.0001);
   }
   else return(0);
}

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()

  {
//---
  
   //If Stop Loss is not set and risk % is in use stop the program, the stop loss is required
   if(StopLoss==0 && UseRiskPercentage){
      Print("A stop loss is required if you are using a risk percentage");
      return;
   }
   
   int Cmd=Command;
   
   //Normalize the digits and calculate the position size
   double nTickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
   double nDigits=CalculateNormalizedDigits();
   if(Digits==3 || Digits==5){
      Slippage=Slippage*10;
      nTickValue=nTickValue*10;
   }
   if(UseRiskPercentage){
      Lots=(AccountBalance()*RiskPercentage/100)/(StopLoss*nTickValue);
      Lots=MathRound(Lots/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP);
   }
   
   //Set the open, stop loss and take profit prices
   double OpenPrice=0;
   double TakeProfitPrice=0;
   double StopLossPrice=0;
   if(Cmd==OP_BUY){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice+TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice-StopLoss*nDigits,Digits);
   } 
   if(Cmd==OP_SELL){
      OpenPrice=NormalizeDouble(MarketInfo(Symbol(),MODE_BID),Digits);
      if(TakeProfit!=0) TakeProfitPrice=NormalizeDouble(OpenPrice-TakeProfit*nDigits,Digits);
      if(StopLoss!=0) StopLossPrice=NormalizeDouble(OpenPrice+StopLoss*nDigits,Digits);
   } 
   
   //Print on screen the informations to see what we are submitting
   Print("Opening an Order ",Command," size ",Lots, " open price ",OpenPrice," slippage ",Slippage," SL ",StopLossPrice," TP ",TakeProfitPrice," comment ",Cmt," magic ",MagicNumber);
   
   //Submit the order, check the it has been accepted
   int OrderNumber;
   OrderNumber=OrderSend(Symbol(),Cmd,Lots,OpenPrice,Slippage,StopLossPrice,TakeProfitPrice,Cmt,MagicNumber);
   if(OrderNumber>0){
      Print("Order ",OrderNumber," open");
      PlaySound(sound);
   }
   else{
      Print("Order failed with error - ",GetLastError());
   }
  }
 
Lorentzos Roussos #:

Hello . You were right on the command , the placement was the issue .

It won't work now as its the weekend 

thank you very much my friend. You have been a big help. God bless