Announcement

Collapse
No announcement yet.

unable to backtest built-in macd study

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • unable to backtest built-in macd study

    Hi hope someone can figure this out.

    this strategy was built using the formula wizard by selecting the built-in macd study and conditions for buy and sell signals for backtesting purposes. however when backtesting no backtesting results are produced.

    i have been sucessfully backtesting other strategies containing built-in and custom studies so i have some experience with backtesting.

    apologies if the code post is difficult to read i couldnt get that top line of html or whatever it is to wrap into a better width.

    PHP Code:

    [CODE]//{{EFSWizard_Description
    //
    //    This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vMACD12_24 = new MACDStudy(12249"Close"false);
    var 
    vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
       
    /**
        *  This function is called only once, before any of the bars are loaded.
        *  Place any study or EFS configuration commands here.
        */
    //{{EFSWizard_PreMain
        
    setPriceStudy(true);
        
    setStudyTitle("CL_MYMACD_");
    //}}EFSWizard_PreMain

    }

    function 
    main() {
       
    /**
        *  The main() function is called once per bar on all previous bars, once per
        *  each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
        *  in your preMain(), it is also called on every tick.
        */

    //{{EFSWizard_Expressions
        //{{EFSWizard_Expression_1
            
    if (
                
    Strategy.isShort(-1) == false &&
                
    vMACD12_24.getValue(MACDStudy.MACD, -1) == vMACD12_24.getValue(MACDStudy.SIGNAL) &&
                
    vMACD12_24.getValue(MACDStudy.MACD, -2) > vMACD12_24.getValue(MACDStudy.SIGNAL)
            ) 
    onAction1()
        
    //}}EFSWizard_Expression_1
        
        //{{EFSWizard_Expression_2
            
    else if (
                
    Strategy.isLong(-1) == false &&
                
    vMACD12_24.getValue(MACDStudy.MACD, -1) == vMACD12_24.getValue(MACDStudy.SIGNAL) &&
                
    vMACD12_24.getValue(MACDStudy.MACD, -2) < vMACD12_24.getValue(MACDStudy.SIGNAL)
            ) 
    onAction2();
        
    //}}EFSWizard_Expression_2
        
    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
        
    return null;
    //}}EFSWizard_Return

    }

    function 
    postMain() {
       
    /**
        *  The postMain() function is called only once, when the EFS is no longer used for
        *  the current symbol (ie, symbol change, chart closing, or application shutdown).
        */
    }

    //{{EFSWizard_Actions
        //{{EFSWizard_Action_1
        
    function onAction1() {
            if (
    vLastAlert != 1Strategy.doShort("SS1"Strategy.MARKETStrategy.NEXTBARStrategy.DEFAULT, 0);
            
    vLastAlert 1;
        }
        
    //}}EFSWizard_Action_1
        
        //{{EFSWizard_Action_2
        
    function onAction2() {
            if (
    vLastAlert != 2Strategy.doLong("L1"Strategy.MARKETStrategy.NEXTBARStrategy.DEFAULT, 0);
            
    vLastAlert 2;
        }
        
    //}}EFSWizard_Action_2
        
    //}}EFSWizard_Actions
    [/CODE

  • #2
    One thing you may want to change is the "-1" in the Strategy.isShort(-1) and Strategy.isLong(-1).

    It stillmay not be triggering trades but that syntax is a problem.

    You need to check that your conditions are all true to trigger a trade.

    Glen
    Glen Demarco
    [email protected]

    Comment

    Working...
    X