Download MetaTrader 5

expert advisor - miscellaneous questions

To add comments, please log in or register
Max Enrik
862
Max Enrik  

Hi, 

I try to use 'else {}' code when market closed just it could play.

But two sounds mixed, where is a problem, please?

// SELL
if( sparam == "SELL GROUP" )
{
    ObjectSetInteger ( 0, "SELL GROUP", OBJPROP_STATE, false );
    _ticket = Order  (    "SELL GROUP"                       );

    PlaySound ( "ok.wav" );
}
else
{
    PlaySound( "timeout.wav" );
}

Best.

(English is not my native language) 

Marco vd Heijden
Moderator
4753
Marco vd Heijden  
timeout.wav will sound for any/every sparam other then "SELL GROUP".
Max Enrik
862
Max Enrik  

Thanks for the comment.

I tried like below, now market is closed 'timeout.wav' playing. But I am not sure 'ok.wav' will play for new order or not?

Can you let me know, please?

int _ticket = 0;
if ( expression )
{
...  
}   //---if Close

if ( _ticket > 0 )
{
    PlaySound( "ok" );
}   //---if Close
//---
if ( _ticket < 0 )
{
    PlaySound( "timeout.wav" );
}   //---if Close

Thanks. 

Marco vd Heijden
Moderator
4753
Marco vd Heijden  

Replace with print function and run it in the tester.

From what i can see it is correct.

You could use -1 in stead of <0 but the result would be similar.

Max Enrik
862
Max Enrik  

OK! Thanks. I will try it on Monday.

//--- second time edited

Works good.

Max Enrik
862
Max Enrik  
Actually I want to add 'OrderLots' function to my main TradePanel EA's but before I need to test it.
So I try to when I click '-' button then lot will decrease, but it does not work for me.

You can see my 'test' EA's codes. I need a help, please.

int             i                                                ,
                int_example         = 1                          ;
double          _lotStep            = 0.01                       ,
                _lot                = 0.09                       ;
string          _prefix             = "| TP -"                   ,
                _edtLot             = _prefix + " Lot"           ,
                _btnLotMinus        = _prefix + " Button Minus"  ;

//---init
_PanelDraw();

//---OnChartEvent
if ( sparam == _btnLotMinus )
{
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_STATE, false );
    _lot = _lot - _lotStep;
    if ( _lot <= 0 )
         _lot = _lotStep;

    Print( "| Just You Clicked Button Lot Minues" );
    return;
}   //---if Close

//---
void _PanelDraw()
{
//---Button
    ObjectCreate    ( 0, _btnLotMinus, OBJ_BUTTON         , 0, 0, 0   );
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_XDISTANCE  , 16        );
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_YDISTANCE  , 16        );
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_XSIZE      , 80        );
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_YSIZE      , 32        );
    ObjectSetString ( 0, _btnLotMinus, OBJPROP_TEXT       , "-"       );
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_FONTSIZE   , 20        );
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_STATE      , false     );
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_SELECTABLE , false     );
    Print( "I am Minus" );

//---Lot
    ObjectCreate    ( 0, _edtLot,      OBJ_EDIT           , 0, 0, 0   );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_COLOR      , Red       );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_XDISTANCE  , 16        );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_YDISTANCE  , 56        );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_XSIZE      , 80        );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_YSIZE      , 32        );
    ObjectSetString ( 0, _edtLot,      OBJPROP_TEXT       , "Lot: " + DoubleToStr( _lot, 2 ) );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_FONTSIZE   , 12        );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_STATE      , true      );
    ObjectSetInteger( 0, _edtLot,      OBJPROP_READONLY   , true      );
    Print( "I am Minus" );
    //---
    return;
}

Thanks! 

Keith Watford
Moderator
9641
Keith Watford  

//---OnChartEvent
if ( sparam == _btnLotMinus )
{
    ObjectSetInteger( 0, _btnLotMinus, OBJPROP_STATE, false );
    _lot = _lot - _lotStep;
    if ( _lot <= 0 )
         _lot = _lotStep;

    Print( "| Just You Clicked Button Lot Minues" );
    return;
}   //---if Close

This is not the OnChartEvent function

This is

void OnChartEvent(const int id,         // Event ID
                  const long& lparam,   // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam  // Parameter of type string events
  );

   if(id==CHARTEVENT_OBJECT_CLICK)

     {

     //

     }


Max Enrik
862
Max Enrik  

Keith Watford:

This is not the OnChartEvent function

This is

I still need help about #5

--- 

But why I did not wrote it? Because it takes more spaces...

Anyway thanks.

Marco vd Heijden
Moderator
4753
Marco vd Heijden  

it seems to be ok but make sure lotstep itself does not go below 0.01

Max Enrik
862
Max Enrik  
But lot doesn't decrease I did not see it.
Keith Watford
Moderator
9641
Keith Watford  
Max Enrik:
But lot doesn't decrease I did not see it.

Where do you expect to see it?

Print( "| Just You Clicked Button Lot Minues" );
Does this print?
12345678...39
To add comments, please log in or register