int OrderClose() { int all_trade = OrdersTotal(); ////////////////////////////////////////What is this variable for? - It is not used. int total_orders = 0; for(int order = 0; order < OrdersTotal(); order++) { if(OrderSelect(order,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol) { total_orders++; } } return(total_orders); /////////////////////////////////////////////////You return here so following code will not be executed. if(OrderType() == OP_BUY) { if( iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,1)>40 && iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,0) <= 40) { bool OrderCloseBuy=OrderClose(OrderTicket(),OrderLots(),Bid, 3, Green); } } if( OrderType() == OP_SELL) { if( iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,1)>40 && iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,0) <= 40) { bool OrderCloseSell=OrderClose(OrderTicket(),OrderLots(),Ask, 3, Green); } } }
Try something like this (not tested)
void CheckToClose() { bool closeBuys=false,closeSells=false; if( iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,1)>40 && iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,0) <= 40) { closeBuys=true; } if( iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,1)>40 && iADX(_Symbol,PERIOD_CURRENT,14,PRICE_CLOSE,MODE_MAIN,0) <= 40) { closeSells=true; } if(closeBuys || closeSells) for(int order = OrdersTotal()-1; order >=0 ; order--) { if(OrderSelect(order,SELECT_BY_POS,MODE_TRADES)==true) if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol) if((OrderType()==OP_BUY && closeBuys) || (OrderType()==OP_SELL && closeSells)) { if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(), 3, Green)) Print ("ERROR closing ticket #",OrderTicket()," code ",GetLastError()); } } }
Try something like this (not tested)
Thanks for your help Keith,
I will post in the right section next time.
Concerning to your code, I have tried it but unfortunately, nothing happened. I don't see any errors here as well, I think that there might be something wrong with the ADX's conditions to close orders
Thanks for your help Keith,
I will post in the right section next time.
Concerning to your code, I have tried it but unfortunately, nothing happened. I don't see any errors here as well, I think that there might be something wrong with the ADX's conditions to close orders
I just copied the adx check code.
Looking at it I see now that the same adx condition closes both buys and sells.
It should still work though
Do not double post!
I have deleted your other post.
You have had replies here already so no need to post in another topic.
You should follow through your code and see what it is doing.
You should get the value of the adx in CheckToClose.
This is a problem with using global-scope variables unnecessarily.
You should follow through your code and see what it is doing.
You should get the value of the adx in CheckToClose.
This is a problem with using global-scope variables unnecessarily.
Do you have any suggestions?
I have tried many ways but the result was still the same
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
Currently I'm developing an EA to close trades when the ADX Main line cross down 40. But the EA didn't close the trades.
Can you guys give me a hand. Thanks.