The code you provided has unbalanced brackets, a typo ? Your issue is unclear (at least to me), maybe you can show the mql4 code you want to convert ?
You can also print your variable's values to see why your condition isn't triggered.
here is the original MQL4 code
for (i=0;i<OrdersTotal();i++){ OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderComment()==Text && OrderMagicNumber()==MN){ if(OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) Bought++; if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELL) Sold++; } } if( Bought==0 && SMA10 > SMA40){ //no buy order Ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots, Kauf,3, SLLong, 0,Text,MN,TimeCurrent() + 24 * 60 *60 ,Blue); } if( Sold==0 && SMA10 < SMA40){ //no sell order Ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Verkauf, 3,SLShort, 0,Text,MN,TimeCurrent() + 24*60*60,Red); }
amando:
here is the original MQL4 code
Ok.
PositionSelect takes a string as parameter (symbol), and return a bool, you have to check this value to see if all is ok.
For pending orders, you have to use OrderXXXX functions.
// NOT TESTED, NOT COMPILED for(int i=0;i<PositionsTotal();i++) { string symbol=PositionGetSymbol(i); if(PositionSelect(symbol)) { if(PositionGetInteger(POSITION_MAGIC)==magic) { if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL ) Sold++; if( PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY ) Bought++; } } } for(int i=0;i<OrdersTotal();i++) { ulong ticket=OrderGetTicket(i); if(OrderSelect(ticket)) { if(OrderGetInteger(ORDER_MAGIC)) { if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP) Sold++; if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP) Bought++; } } } if(...)
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
- www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
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
Hello,
im translating my ea from mt4 to mt5 and i have some problems to set the orders.
as long the line with Bought == 00 i never get any sold order. i can try to delete the Bought line to get sold order.
the main idea behind is, look if there is some working orders ( in mt4 was working and pending) and if there is no one set some new one with the void function.
please be so kind, and do not refere to the help files. im not an english native and the german documentation is crap.