MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Have Something to Say to Traders? Welcome to Blogs!

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

 
Show Must Go On, or Once Again about ZigZag
About an obvious but still substandard method of ZigZag composition, and what it results in: the Multiframe Fractal ZigZag indicator that represents ZigZags built on three larger ons, on a single working timeframe (TF). In their turn, those larger TFs may be non-standard, too, and range from M5 to MN1.
avatar
14179
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