Download MetaTrader 5

The qusetion for OrderSend(),OnInit() and OnChartEvent()

To add comments, please log in or register
Articles have already helped many traders. Come and read them!
Hugh Ying
13
Hugh Ying 2012.02.07 13:04 

Here is the code I used and it's working in OnInit(),but not working in OnChartEvent()... return code is 10013...I get the 4756 error...

Why?

Please help.

            MqlTradeRequest request;
            request.action = TRADE_ACTION_DEAL;
            request.symbol = Symbol();
            request.volume = 0.01;
            request.type = ORDER_TYPE_BUY;
            request.type_filling = ORDER_FILLING_AON;  
            MqlTradeResult result;
            OrderSend(request,result);
            Print("Reply code=",result.retcode);  
Hugh Ying
13
Hugh Ying 2012.02.08 04:01  

Here is the code I added and it's working in OnChartEvent()


request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
JDeel
239
JDeel 2012.02.09 19:27  

Also don't forget to add ZeroMemory() function.... something like that... especially when you want to modify orders:

MqlTradeRequest request;
ZeroMemory(request);
...
...
...

MqlTradeResult result;
ZeroMemory(result);

 

Hugh Ying
13
Hugh Ying 2012.02.12 18:28  
JDeel:

Also don't forget to add ZeroMemory() function.... something like that... especially when you want to modify orders:

 

Thank you! I will always remember!

To add comments, please log in or register