MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Buy Latest Technical Indicators in MetaTrader Market

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...

 
Scandals and investigations: BNP senior officials examined in the trading probe
Paris prosecutors have started examining several senior BNP Paribas SA officials with a preliminary insider-trading probe related to the lender’s record settlement in the U.S. The prosecutors are trying to determine how much senior BNP Paribas directors and top executives knew about the bank’s exposure to litigation risks in the U.
avatar
14177
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