When needed, the sound don't play (why?)

 
Greetings,

I wrote an EA that supposed to help 'dismember' losing trades that got 'too fat' ,bearing heavy loss.

I do that by comparing to another 'profitable' trade, and when I gain enough with the 'profitable' trade,
I releases 1 part of the losing trade against the money in the  'profitable' tradem. So the loss is covered with 'no damage' to the balance.

The routine works fine, except that I can't figure out why when the 'profitable' trade get closed, the 'cat_cry' sound doesn't play.

Any Ideas?

James

 

/*------------------+
 | Extern Variables |
 +------------------*/
extern double cover_money =  1;      // the amount to gain over the loss
extern int losing         =  99999;  // the losing trade to cover
extern int profiting      =  99999;  // the covering trade to use

/*------------------+
 | Globel Variables |
 +------------------*/
int    OCO=0;
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int losing_lot_parts;
  bool exist=false;
  double profiting_profit, profiting_lots;
//----

   if (OrderSelect(profiting, SELECT_BY_TICKET, MODE_TRADES)==true) // profiting trade's values
      {
       profiting_profit=OrderProfit();
       profiting_lots=OrderLots();

       if (OrderSelect(losing, SELECT_BY_TICKET, MODE_TRADES)==true)  // losing trade's values
          {
           losing_lot_parts=OrderLots()/0.01;
           if (profiting_profit>=MathAbs(OrderProfit()/losing_lot_parts)+cover_money)
              {
               OrderClose(losing,0.01,0,0,Blue);
               OrderClose(profiting,profiting_lots,0,0,Blue);
               PlaySound("coin-drop-2[3].wav");
               Print("losing_hedge_solver() closed one part of losing #",losing);
              }
           else
              {
               ObjectCreate("comment_label",OBJ_LABEL,0,0,0);
               ObjectSet("comment_label",OBJPROP_XDISTANCE,10);
               ObjectSet("comment_label",OBJPROP_YDISTANCE,20);
               ObjectSetText("comment_label",StringConcatenate(" $",MathAbs(profiting_profit+(OrderProfit()/losing_lot_parts)-cover_money)," until #",profiting,
                       " will cover #",losing," partial loss"),14,"Arial",White);
               WindowRedraw();
//          StringConcatenate("\n\r\n\rWell, there is still $",-OrderProfit()/losing_lot_parts+cover_money," until the close");
//          Comment("\n\r\n\rWell, there is still $",-OrderProfit()/losing_lot_parts+cover_money," until the close");
              }
          }
       else 
          {
           Sleep (30000);
           Alert ("losing_hedge_solver: No valid losing trade");
           PlaySound ("cat_cry[3].wav");
          }
      }
   else 
      {
       Sleep (30000);
       Alert ("losing_hedge_solver: No valid profiting trade");
       PlaySound ("cat_cry[3].wav");
      }

//----
   return(0);
  }
//+------------------------------------------------------------------+

 

 
JJF:
Greetings,

I wrote an EA that supposed to help 'dismember' losing trades that got 'too fat' ,bearing heavy loss.

I do that by comparing to another 'profitable' trade, and when I gain enough with the 'profitable' trade , I releases 1 part of the losing trade against the money in the  'profitable' tradem. So the loss is covered and 'no damage' to the balance.

The routine works fine, except that I can't figure out why when the 'profitable' trade get closed, the 'cat_cry' sound doesn't play.

Any Ideas?

Yes.  Your  elses  apply to your . . . 

if (OrderSelect(

  . . .   so if your OrderSelect() fails you will get your Cat Cry

 
RaptorUK:

Yes.  Your  elses  apply to your . . . 

  . . .   so if your OrderSelect() fails you will get your Cat Cry


Yes, you are absolutely right.

If you look closely, there are two 'if (OrderSelect(..' each with its own 'Cat Cry' sound maker. The idea is to notify the user that either one of the trades, is no longer exist (active trade). Due to stoploss or the routine was successful: the profitable trade closed and the losing one changed it's ticket number (happens on partial close event)

The problem is that when such event happens, the sound and alert part of the EA doesn't activated.

I looked for a reason but couldn't find any.

Can you explain that?


Thanks,

James

 
JJF:

Yes, you are absolutely right.

If you look closely, there are two 'if (OrderSelect(..' each with its own 'Cat Cry' sound maker. The idea is to notify the user that either one of the trades, is no longer exist (active trade). Due to stoploss or the routine was successful and the profitable closed and the losing one changed it's ticket number (happens on partial close event)

Select by ticket selects from either pool,  you can't just specify MODE_TRADES,  it's not valid,  read the documentation.

"pool -  Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:"

 

You should check the OrderCloseTime() ,  if it's not zero then it's closed,  "Open and pending orders close time is equal to 0."

 
Thanks for the solution.

There is a say: Every day that you learn something new, is a good day.

Thank you for making my day  'a good day'


James
 
JJF:
Thanks for the solution.

There is a say: Every day that you learn something new, is a good day.

Thank you for making my day  'a good day'
You are most welcome :-)
Reason: