Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

mql4 - how can I get last trade result?

How can I get the last trade result in mql4 bot? I mean the part of code, mine does not work. This is code, how can I do it?

   int a = 0;
  
   while(a == 0){
       OrderSend(Symbol(),OP_BUY,0.01,price,5,0,(Ask+0.0002),0,0,0,Green);
       a = 1;
   }

   //if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS)==true){
   //    Print("Profit for the order 10 " + OrderProfit());
   //}
   //else{
   //    Print("OrderSelect returned the error of " + GetLastError());
   //}
   
   OrderSelect(OrderTicket(), SELECT_BY_POS);
   Print("Profit for the order 10 " + OrderProfit());
   OrderModify(OrderTicket(),OrderOpenPrice(),(Ask-0.0001),0,0,0);
   if(OrderProfit()<0){
       OrderSend(Symbol(),OP_SELL,0.01,price,5,0,0,0,0,0,Green);
   }
   else{
       OrderSend(Symbol(),OP_BUY,0.01,price,5,0,0,0,0,0,Red);
   }
question from:https://stackoverflow.com/questions/65936413/how-can-i-get-last-trade-result

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To select last open or pending order from trading pool:

OrderSelect(OrdersTotal()-1, SELECT_BY_POS);

If you want to select last closed or canceled order:

OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);

You can get more information in the docs OrderSelect()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...