Results 1 to 3 of 3
 0 Attachment(s)    

Thread: How to code ea to backtest 2 or more TF at same time?

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    2

    Default How to code ea to backtest 2 or more TF at same time?

    I try to make an ea and encounter such problem, let's say entry is back on 15m chart but exit will be based on 1hr chart. I know it is easy to do it on foreward test, but how could I code it to do backtest?

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

    Default

    Quote Originally Posted by jialinc View Post
    I try to make an ea and encounter such problem, let's say entry is back on 15m chart but exit will be based on 1hr chart. I know it is easy to do it on foreward test, but how could I code it to do backtest?
    Hi jialinc,

    You need to modify the timeframe parameter of the wanted indicators used for the exit.

    For exampe with Parabolic SAR :

    Code:
    iSAR(NULL,0,0.02,0.2,i);
    becomes :

    Code:
    iSAR(NULL,PERIOD_H1,0.02,0.2,i);
    More informations : Timeframe enumeration

  3. #3
    Junior Member
    Join Date
    Dec 2008
    Posts
    14

    Default Access to multi TF in EA

    Quote Originally Posted by jialinc View Post
    I try to make an ea and encounter such problem, let's say entry is back on 15m chart but exit will be based on 1hr chart. I know it is easy to do it on foreward test, but how could I code it to do backtest?
    Hi,
    and thx funyoo for your reply,
    these are the codes that I use them for Access to multi TF in EA.

    1. definitions in the top of EA

    #define TF1m 1
    #define TF5m 2
    #define TF15m 3
    #define TF30m 4
    #define TF1H 5
    #define TF4H 6
    #define TF1D 7
    #define TF1W 8
    #define TF1MON 9

    2. TF variables :

    extern int TRADE_TF1 = TF15m ;
    extern int TRADE_TF2 = TF4H ;

    3. TF extract function:


    int TF_EXTRACT ( int tf_sel )
    {

    switch ( tf_sel )
    {

    case TF1m:
    return ( PERIOD_M1);
    break;

    case TF5m:
    return ( PERIOD_M5);
    break;

    case TF15m:
    return ( PERIOD_M15);
    break;

    case TF30m:
    return ( PERIOD_M30);
    break;

    case TF1H:
    return ( PERIOD_H1);
    break;

    case TF4H:
    return ( PERIOD_H4);
    break;

    case TF1D:
    return ( PERIOD_D1);
    break;

    case TF1W:
    return ( PERIOD_W1);
    break;

    case TF1MON:
    return ( PERIOD_MN1);
    break;

    }
    return ( PERIOD_M15);
    }

    ////////////////////////////////////////////////////////

    4. using in main code example:

    int my_TF1 = TF_EXTRACT ( TRADE_TF1 ) ;
    int my_TF2 = TF_EXTRACT ( TRADE_TF2 ) ;

    BUY_ma1_now = iMA( NULL, my_TF1, BUY_TREND_PER , 0 , BUY_MODE_MA1 , BUY_PRICE_X1 , BUY_SIG_BAR ) ;

    BUY_ma1_prev = iMA( NULL, my_TF, BUY_TREND_PER , 0 , BUY_MODE_MA1 , BUY_PRICE_X1 , BUY_CHK_BAR ) ;


    or use my_TFx in any indicator for timeframe selection,

    and use 1 2 3 4 5 6 7 for range of Optimiztion for TRADE_TFx


    OTR

Similar Threads

  1. Are you a Part-time trader or Full-time trader?
    By shereali in forum Trading discussion
    Replies: 3
    Last Post: 09-22-2014, 12:22
  2. Time filter code
    By himnoor in forum MQL programming
    Replies: 0
    Last Post: 12-21-2010, 02:55
  3. Add time to rest for EA (allow sever time )
    By 671988 in forum MQL programming
    Replies: 1
    Last Post: 10-24-2010, 03:28
  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. Code to Backtest Quicker
    By keymaker in forum MQL programming
    Replies: 4
    Last Post: 06-08-2009, 19:12

Tags for this Thread

backtest, how to, indicator, indicators, main, mql, parabolic sar, test, time, trend

Posting Permissions

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