MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Read Financial Magazines in MetaTrader 4 and MetaTrader 5!

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

 
Mechanical Trading System "Chuvashov's Triangle"

Mechanical Trading System "Chuvashov's Triangle"

Let me offer you an overview and the program code of the mechanical trading system based on ideas of Stanislav Chuvashov. Triangle's construction is based on the intersection of two trend lines built by the upper and lower fractals.

avatar
14034
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