How to set two trade time in one day?

Discussion in 'Automated Trading' started by ww11, Jul 21, 2015.

  1. ww11

    ww11

    Assume that I want to buy at 091500 to 114500(morning) and 130000 to 160000(afternoon) and sell before 115500(morning) and 161000(afternoon) respectively.

    How can write it in formula correctly? I could only partly write the following language. When I try to add the morning period, the system only trade in either morning or afternoon. I tried many ways but they didn't work. Could anyone help? Thank you!


    Buy=(Strategy) AND TimeNum()<=160000;
    Sell=(Strategy) OR TimeNum()>=161000;
     
  2. aqtrader

    aqtrader

    Use Epoch time https://en.wikipedia.org/wiki/Unix_time, like many such as google's intraday data time series. Then you can simply compare time by comparing simple integers. It is easy to translate back and forth between standard time and epoch time. Such as by the date command in a Unix/Linux machine by, for example,
    $ TZ='America/New_York' date --date="20150721 12:01:16" +%s
    You get
    1437494476
    This is, the epoch time, that is, the number of seconds since Jan 1, 1970.
     
  3. ww11

    ww11

    Thank you for answering my question! Yet it is not the answer I need. Maybe my question is not clear. I want to trade in two different time sections within the same day for auto trade(Amibroker). I have no idea how to write it correctly.
     
  4. wrbtrader

    wrbtrader

    There are several Amibroker forums and support groups...a few are very active...did you join them and ask the same question ?
     
  5. M.ST.

    M.ST.

    Code:
    // http://www.amibroker.com/kb/2014/11/28/how-to-restrict-trading-to-certain-hours-of-the-day/
    // http://www.elitetrader.com/et/index.php?threads/how-to-set-two-trade-time-in-one-day.293049/#post-4154197
    
    tn = TimeNum();
    
    startTime1 = 091500; // start in HHMMSS format
    endTime1 = 114500;  // end in HHMMSS format
    time1OK = tn >= startTime1 AND tn <= endTime1;
    
    startTime2 = 130000; // start in HHMMSS format
    endTime2 = 160000;  // end in HHMMSS format
    time2OK = tn >= startTime2 AND tn <= endTime2;
    
    strategy = true; // or instead insert some rule like Cross( MACD(), Signal() ); or C > MA(C, 20 ); etc.
    
    BuyA = strategy AND time1OK;
    SellA = Cross( tn, 115500 ); 
    
    BuyB = strategy AND time2OK;
    SellB = Cross( tn, 161000 ); 
    
    Buy = BuyA OR BuyB;
    Sell = SellA OR SellB;
    
    Buy = ExRem( Buy, Sell );
    Sell = ExRem( Sell, Buy );
     
    Last edited: Jul 23, 2015
  6. M.ST.

    M.ST.

    Or like this one

    Code:
    // http://www.amibroker.com/kb/2014/11/28/how-to-restrict-trading-to-certain-hours-of-the-day/ 
    // http://www.elitetrader.com/et/index.php?threads/how-to-set-two-trade-time-in-one-day.293049/#post-4154197
    
    tn = TimeNum();
    
    startTime1 = 091500; // start in HHMMSS format
    endTime1 = 114500;  // end in HHMMSS format
    time1OK = tn >= startTime1 AND tn <= endTime1;
    
    startTime2 = 130000; // start in HHMMSS format
    endTime2 = 160000;  // end in HHMMSS format
    time2OK = tn >= startTime2 AND tn <= endTime2;
    
    Buystrategy = C > MA(C, 20);
    Sellstrategy = MA(C, 20) > C;
    
    BuyA = Buystrategy AND time1OK;
    SellA = (Sellstrategy AND time1OK) OR Cross( tn, 115500 ); 
    
    BuyB = Buystrategy AND time2OK;
    SellB = (Sellstrategy AND time2OK) OR Cross( tn, 161000 ); 
    
    Buy = BuyA OR BuyB;
    Sell = SellA OR SellB;
    
    Buy = ExRem( Buy, Sell ); 
    Sell = ExRem( Sell, Buy );
    or whatever
     
  7. ww11

    ww11


    Very Appreciated!! That's exactly what I want. Thank you for your reply with useful examples.