+ Reply to Thread
Results 1 to 6 of 6
 0 Attachment(s)    

Thread: Close at specyfic time

  1. #1
    Member
    Join Date
    Nov 2008
    Posts
    257

    Default Close at specyfic time

    hy
    could you help?
    how close open order after x minuts independent of it's loss or win?
    is a function of history where we can find and remember time's open order?

  2. #2
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,455

    Default

    Quote Originally Posted by przem81621 View Post
    hy
    could you help?
    how close open order after x minuts independent of it's loss or win?
    is a function of history where we can find and remember time's open order?
    Hi przem81621,

    In the extern parameters, add :

    Code:
    extern bool UseTimeOut=false;
    extern double TimeOut=60; //in minutes
    After the extern parameters, add :

    Code:
    datetime expiration;
    int ticket;
    Before the OrderSend function, add :

    Code:
    ticket=
    Just after the OrderSend function add :

    Code:
    if(ticket>0)expiration=CurTime()+TimeOut*60*60;
    At the beginning of the Start function, add :

    Code:
    if (UseTimeOut)
    {
          if(CurTime()>=expiration)
          {
               Close();
               Print("Order closed due to TimeOut");
          }
    }
    Replace Close() by your close function.

  3. #3
    Member
    Join Date
    Jan 2009
    Posts
    151

    Default

    There are two ways of doing this. With both methods you need firstly to process the trades pool and select your order by symbol and magic number and open buy/sell.

    The first way uses some code similar to this:

    Code:
    if(TimeCurrent()-OrderOpenTime()>=Close_after_minutes*60) {ClosePosition();}
    The problem with this approach is that if your position was taken on a Friday evening shortly before the market closed, you may find yourself unable to close the position.

    Instead you could use this second approach:

    Code:
    int OpenBar = iBarShift(NULL,0,OrderOpenTime());
    if(OpenBar*Period()>=Close_after_minutes) {ClosePosition();}
    Obviously you would need to tidy this logic up a little bit and insert it at the correct places.
    Last edited by jezzer1961; 05-21-2009 at 19:24.
    PipRider.com - The home of the PipRider EA. From $100 to over $1m in 10 year backtest, and it works LIVE too!!

  4. #4
    Member
    Join Date
    Jan 2009
    Posts
    151

    Default

    Ooops, looks like Funyoo posted while I was typing.

    Funyoo,

    I think you might find that CurTime() is an obsolete MetaTrader function now. I'm pretty sure it's been replaced by TimeCurrent().
    PipRider.com - The home of the PipRider EA. From $100 to over $1m in 10 year backtest, and it works LIVE too!!

  5. #5
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,455

    Default

    Quote Originally Posted by jezzer1961 View Post
    Ooops, looks like Funyoo posted while I was typing.

    Funyoo,

    I think you might find that CurTime() is an obsolete MetaTrader function now. I'm pretty sure it's been replaced by TimeCurrent().
    Hi jezzer1961,

    Indeed you are right!

  6. #6
    Member
    Join Date
    Nov 2008
    Posts
    257

    Default

    Quote Originally Posted by funyoo View Post
    Hi jezzer1961,

    Indeed you are right!
    thanks to you both F & J

+ Reply to Thread

Similar Threads

  1. Close all buy and close all sell orders
    By q8m2002 in forum Scripts and other tools
    Replies: 8
    Last Post: 12-17-2010, 05:33
  2. Brokers Time Conversion
    By Passion Trader in forum Metatrader brokers
    Replies: 10
    Last Post: 07-21-2009, 21:57
  3. Add a time filter
    By funyoo in forum MQL programming
    Replies: 12
    Last Post: 05-28-2009, 21:26
  4. Mesir Time EA
    By ahlan042000 in forum Expert advisors backtesting
    Replies: 14
    Last Post: 03-13-2009, 13:18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts