Results 1 to 6 of 6
 0 Attachment(s)    

Thread: Close at specyfic time

  1. #1

    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,003

    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

    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 20:24.

  4. #4

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

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

    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

    Default

    Quote Originally Posted by funyoo View Post
    Hi jezzer1961,

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

Similar Threads

  1. Close all buy and close all sell orders
    By q8m2002 in forum Scripts and other tools
    Replies: 11
    Last Post: 12-01-2012, 04:38
  2. Time Confirmation for Close Trades
    By FX-BoT-FX in forum MQL programming
    Replies: 0
    Last Post: 03-08-2012, 20:18
  3. Replies: 2
    Last Post: 04-15-2010, 16:44
  4. How is the code to close at same time with sl-tp
    By gaspar in forum MQL programming
    Replies: 0
    Last Post: 10-18-2009, 13:32
  5. Close trades after X amount of time?
    By lforet3252 in forum MQL programming
    Replies: 1
    Last Post: 09-28-2009, 01:26

Tags for this Thread

magic, magic number, metatrader, time

Posting Permissions

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