Download MetaTrader 5

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

To add comments, please log in or register
Hugh Ying
13
Hugh Ying  

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  

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


request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
JDeel
238
JDeel  

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  
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