errors - miscellaneous questions - page 2

 

First parameter in  OrderClose() is an order ticket. Instead of "i" you should use OrderTicket().



void closebuy()
{
    Updates();

    for ( i = OrdersTotal() - 1; i >= 0; i-- )
    {
        if  ( ! OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) continue;
        if  ( OrderSymbol() != Symbol() ) continue;
        if  ( OrderType() != OP_BUY ) continue;

        res = OrderClose( OrderTicket(), lots, OrderClosePrice(), 3, clrRed );
        if  ( ! res ) Print( " | Order Close Error #", GetLastError() );
        else          Print( " | Order Modified Successfully." );
    }
    //---
    return;
}
 
Drazen Penic:

First parameter in  OrderClose() is an order ticket. Instead of "i" you should use OrderTicket().

What a simple, what a big mistake?

Thanks a lot.

#4051 - Closed
 

#4109 - Open

ERR_TRADE_NOT_ALLOWED
I already know #4109 error comes from Disabled " Enable Automated Trading ". So I get error code #4109 that is true but I need to get error code description, now I get description " no error " while I get error #4109

I try to use below part code of error for gets error number and description. So get right Error number but not error description.

Q:  What could do for ErrorDescription, please?

( I am hard working on it right now )

Thanks in advance.

Print( "error #", GetLastError(), " ", ErrorDescription( error_code ) );
 

ErrorDescription(): it is function on libraries stdlib.mq4

you need import it to your EA or copy code to your EA.

#import "stdlib.ex4"
string ErrorDescription(int error_code);
#import
 
Nguyen Nga:

ErrorDescription(): it is function on libraries stdlib.mq4
you need import it to your EA or copy code to your EA.

Thanks for your comment.
I try like below code, so am I doing wrong, please?

Thanks in advance.

// error description
#property strict
#import "stdlib.ex4"
string ErrorDescription(int error_code);
#import

int error_code = GetLastError();
//-----------------
int OnInit()
{
    ObjectCreate( 0,"sell button", OBJ_BUTTON, 0, 0, 0 );
    ObjectSetInteger(0,"sell button",OBJPROP_XDISTANCE,20);
    ObjectSetInteger(0,"sell button",OBJPROP_YDISTANCE,20);
    ObjectSetInteger(0,"sell button",OBJPROP_BGCOLOR,Red);
    ObjectSetInteger(0,"sell button",OBJPROP_COLOR,White);
    //---
    return(0);
}

//-----------------
void OnTick()
{

    //---
    return;
}

//-----------------
void OnChartEvent(const int id, const long & lparam, const double & dparam, const string & sparam )
{
    if( id == CHARTEVENT_OBJECT_CLICK && sparam == "sell button" )
    {
        int ticket = OrderSend( _Symbol, OP_SELL, 0.01, Ask, 3, 0, 0, "sell", 0123, 0, Red );
        if  ( ticket<0 )
        {
            Print( "error #", GetLastError(), " ", ErrorDescription(error_code) );
        }
    }
    ObjectSetInteger ( 0, sparam, OBJPROP_STATE, false );
    //---
    return;
}
//-----------------
void OnDeinit(const int reason)
{
    //---
    return;
}
 

you must get error.

error_code = GetLastError();
Print( "error #", error_code, " ", ErrorDescription(error_code) );
 
Nguyen Nga:

you must get error.

Perfect! Thanks a lot.

#4109 - Closed
 

#Time To Integer - Open

error: possible loss of data due to type conversion

I few times faced above error and I was fixed it with removing "#property strict" then I was not seen that error after it.
But know I need to fix it without remove "#property strict".

So, I need to convert Time to Integer, how can I do it right, please?

Thanks in advance.

int IntGetValue = TimeOne / TimeTwo; // equal = 3


 
Try long instead of int.
 

Which integer do you need ?

https://docs.mql4.com/dateandtime

Hour - Date and Time - MQL4 Reference
Hour - Date and Time - MQL4 Reference
  • docs.mql4.com
Hour - Date and Time - MQL4 Reference
Reason: