You haven't selected any order
GumRai:
You haven't selected any order
You haven't selected any order
Hi..
I have change my code like this.... is it ok ?
if (OrdersTotal() > 0) { TicketNo4 = OrderTicket(); if (OrderSelect(TicketNo4, SELECT_BY_TICKET) == true) { if (OrderType() == OP_BUY) { Print ("[TRACE-4] Close buy and open sell for " + TicketNo4 + ", current post:" + OrderType() + ", No:" + OrdersTotal() + ", op_buy:" + OP_BUY + ", op_sell" + OP_SELL); //CloseBuy(TicketNo4); //TicketNo4 = OpenSell(); } }
bh_hensem:
Hi..
I have change my code like this.... is it ok ?
You can't be sure selecting this way if the selected trade is from your EA / strategy
bh_hensem:
I want to do like this :-
IF current order is BUY then do something
IF current order is SELL then do something
All you need to do is to correctly select the order and once selected, do whatever you want with it.
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==false) // select order using OrderSelect function Print("Failed to select order, error : "+ErrorDescription(GetLastError())); // if function fails, print error to let me know what's wrong if(OrderSymbol() != Symbol() || OrderMagicNumber() !=MagicNumber)continue; // if the order is of different symbol or magic number, skip over to the next order if(OrderType()==OP_BUY) { // your code here } if(OrderType()==OP_SELL) { // your code here }
Hope it helps.
thrdel,
there is a problem with your code
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==false) // select order using OrderSelect function Print("Failed to select order, error : "+ErrorDescription(GetLastError())); // if function fails, print error to let me know what's wrong //------------If OrderSelect fails, you continue as if it had been successful if(OrderSymbol() != Symbol() || OrderMagicNumber() !=MagicNumber)continue; // if the order is of different symbol or magic number, skip over to the next order if(OrderType()==OP_BUY) { // your code here } if(OrderType()==OP_SELL) { // your code here }
GumRai:
thrdel,
there is a problem with your code
Well, I guess we can throw a continue in there at no extra cost if you insist but as far as warning messages, even without it, you still not going to get any.
Thanks for pointing that out.
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==false) // select order using OrderSelect function { Print("Failed to select order, error : "+ErrorDescription(GetLastError())); // if function fails, print error to let me know what's wrong continue; } if(OrderSymbol() != Symbol() || OrderMagicNumber() !=MagicNumber)continue; // if the order is of different symbol or magic number, skip over to the next order if(OrderType()==OP_BUY) { // your code here } if(OrderType()==OP_SELL) { // your code here }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi...
How could i check the current order is BUY or SELL ?.
I want to do like this :-
Refer to the terminal, I have one post on SELL order. But once I test my expert advisor, the program return the OrderType value as OP_BUY ?. Why ? It shoud be return the current order is SELL right ?...
This is the trace message:
This is my code that the program refer to:-