MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Check MetaTrader Market in order to find your Expert Advisor

ea not closing open trades at specific time

Back to topics list To post a new topic, please log in or register
avatar
5
igorko 2011.11.07 10:47
 

Hello!

I've made an EA (with debugging help from RaptorUK, thanx for that :) ) that should open and close trades at specific time. Opening works properly, and everything else, but close_all doesn't work at all...

Here is the piece of the code I found online and inserted:

void closeall() {
  double pBid, pAsk;

if (TimeHour(TimeCurrent())==CloseHour && TimeMinute(TimeCurrent())>=CloseMinute) { 
    for (int i=OrdersTotal()-1; i>=0; i--) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
        if (!UseCurrSymbol || OrderSymbol()==Symbol()) {
          if (OrderType()==OP_BUY) {
            pBid=MarketInfo(OrderSymbol(), MODE_BID);
            OrderClose(OrderTicket(), OrderLots(), pBid, Slippage, clCloseBuy);
          }
          if (OrderType()==OP_SELL) {
            pAsk=MarketInfo(OrderSymbol(), MODE_ASK);
            OrderClose(OrderTicket(), OrderLots(), pAsk, Slippage, clCloseSell);
          }
        }
      }
    }
  }
}

In my EA, it doesn't work... I attached the EA so you can have a look on whole code.

Help please...

 
What Is a Martingale?

What Is a Martingale?

A short description of various illusions that come up when people trade using martingale betting strategies or misuse spiking and the like approaches.

avatar
14053
RaptorUK 2011.11.07 10:56 #
 
You need to test the return code from the OrderClose just like you did with the OrderSend . . . add in some Print statements to see which parts of the code are being executed and which aren't . .
 
avatar
5
igorko 2011.11.08 09:47 #
 

solved :) this part of code that needed to be activated at certain hour to close all orders needed to be called on every tick, and in my code was a continuation of part of the code called when pending orders are opened once in the morning....

print statements didn't show anything, but the lack of them, where they should be, gave me the idea what the problem is ;)

tnx again RaptorUK

 
Back to topics list  

To add comments, please log in or register