Announcement

Collapse
No announcement yet.

Backtesting using a study that's not "built in"

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

  • Backtesting using a study that's not "built in"

    Just a quick question about something. Can I create, using the formula wizard, a backtesting strategy using a study that is not built in (take for example the DiNapoli Stoch).

    There is a backtesting example using a stochastic oscillator in eSignal which looks like this:

    PHP Code:
    var study = new StochStudy(14,1,3);


    function 
    preMain() {
        
    setPriceStudy(false);
    }

    function 
    main() {
        var 
    vFast study.getValue(StochStudy.FAST0, -2);

        if(
    vFast == null)
            return;

        if(
    vFast[0] > 20 && vFast[1] <= 20) {
            if(!
    Strategy.isLong()) {
                
    Strategy.doLong("Over Sold"Strategy.CLOSEStrategy.THISBAR);
            }

        } else if(
    vFast[0] < 80 && vFast[1] >= 80) {
            if(!
    Strategy.isShort()) {
                
    Strategy.doShort("Over Bought"Strategy.CLOSEStrategy.THISBAR);
            }
        }

        if(
    Strategy.isLong()) {
            
    setBarBgColor(Color.green);
        } else if(
    Strategy.isShort()) {
            
    setBarBgColor(Color.red);
        }


        return 
    vFast[0];

    The stochastic study I'd like to use (Dinapoli) looks like this:

    PHP Code:

    function preMain()
    {
        
    setStudyTitle("Preferred Stochastic");
        
    setCursorLabelName("percentK"0);
        
    setCursorLabelName("percentD"1);
        
    setDefaultBarFgColor(Color.lime0);
        
    setDefaultBarFgColor(Color.red1);

    }

    var 
    MAVt null;
    var 
    MAVt1 null;
    var 
    MAVt_1 0;
    var 
    MAVt1_1 0;

    function 
    main(nLengthnSmoothingnSmoothings) {
        if(
    nLength == null)
            
    nLength 8;
        if(
    nSmoothing == null)
            
    nSmoothing 3;
        if(
    nSmoothings == null)
            
    nSmoothings 3;

        var 
    percentK;
        var 
    ll 0hh 0;
        var 
    sum 0;
        var 
    vHigh getValue("High"0, -nLength);
        var 
    vLow getValue("Low"0, -nLength);
        var 
    temp 0;
        
        if(
    vHigh == null || vLow == null)
            return;


        for(
    0nLengthj++) {
            if(
    == 0) {
                
    ll vLow[j];    
                
    hh vHigh[j];
            } else {
                
    hh Math.max(hhvHigh[j]);
                
    ll Math.min(llvLow[j]);
            }
        }
        
    percentK = ((close() - ll) / (hh ll)) * 100;
        if (
    isNaN(percentK) == falseMAVt MAVt_1 + (percentK MAVt_1) / nSmoothing;
        if (
    getBarState() == BARSTATE_NEWBARMAVt_1 MAVt;
        if (
    isNaN(percentK) == falseMAVt1 MAVt1_1 + (MAVt MAVt1_1) / nSmoothings;
        if (
    getBarState() == BARSTATE_NEWBARMAVt1_1 MAVt1;
        
        return new Array(
    MAVt,MAVt1);

    I'm thinking that it's not possible through the formula wizard, and if it is correct me, but if not... what's a relativley painless way to get that stoch into that backtesting study?

    Thanks for all of the suggestions. I'll be working on it, but if I haven't posted again in this thread, you can reasonably assume I haven't figured it out.

    Happy Thanksgiving!!!

  • #2
    Hello techinvest,

    Currently, the Formula Wizard does not have the ability to use a non-builtin study for back testing. This requires custom coding. The easiest way to bring in the external study into a custom back testing study is through the efsExternal() function.

    You could create the basic structure of the back test with the Formula Wizard and then modify the EFS through the EFS Editor and replace the builtin Stochastic study with the series created by the efsExternal() call. Give this a try and if you need help, post your code here and we'll provide further guidance.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment

    Working...
    X