Announcement

Collapse
No announcement yet.

Stochastic Crossover

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stochastic Crossover

    File Name: strStochCrsvr.efs

    Description:
    Stochastic Crossover

    Formula Parameters:
    nLength : 7
    nSmoothing : 1
    nDLength : 3
    Overbought : 80
    Oversold : 20


    Notes:
    This back testing strategy generates a long trade at the Open of the following
    bar when the %K line crosses below the %D line and both are above the Overbought level.
    It generates a short trade at the Open of the following bar when the %K line
    crosses above the %D line and both values are below the Oversold level.


    Download File:
    strStochCrsvr.efs



    EFS Code:
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright c eSignal), a division of Interactive Data 
        Corporation. 2009. All rights reserved. This sample eSignal 
        Formula Script (EFS) is for educational purposes only and may be 
        modified and saved under a new file name.  eSignal is not responsible
        for the functionality once modified.  eSignal reserves the right 
        to modify and overwrite this EFS file with each new release.

    Description:        
        Stochastic Crossover
        
    Version:            1.0  05/12/2009
        
    Formula Parameters:                     Default:
        nLength                             7
        nSmoothing                          1
        nDLength                            3
        Overbought                          80
        Oversold                            20

    Notes:
        This back testing strategy generates a long trade at the Open of the following 
        bar when the %K line crosses below the %D line and both are above the Overbought level.
        It generates a short trade at the Open of the following bar when the %K line 
        crosses above the %D line and both values are below the Oversold level.

    **********************************/
    var fpArray = new Array();
    var 
    bInit false;

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setColorPriceBars(true);
        
    setStudyTitle("Stochastic Crossover");
        
    setDefaultPriceBarColor(Color.black);
        var 
    0;
        
    fpArray[x] = new FunctionParameter("nLength"FunctionParameter.NUMBER);
        
    with(fpArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(7);
        }    
        
    fpArray[x] = new FunctionParameter("nSmoothing"FunctionParameter.NUMBER);
        
    with(fpArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(1);
        }    
        
    fpArray[x] = new FunctionParameter("nDLength"FunctionParameter.NUMBER);
        
    with(fpArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(3);
        }    
        
    fpArray[x] = new FunctionParameter("Oversold"FunctionParameter.NUMBER);
        
    with(fpArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(20);
        }    
        
    fpArray[x] = new FunctionParameter("Overbought"FunctionParameter.NUMBER);
        
    with(fpArray[x++]) {
            
    setLowerLimit(1);
            
    setDefault(80);
        }        
    }

    var 
    xStochK null;
    var 
    xStochD null;

    function 
    main(nLengthnSmoothingnDLengthOversold,  Overbought) {
    var 
    nBarState getBarState();
        if (
    nBarState == BARSTATE_ALLBARS) {
            if (
    nLength == nullnLength 7;
            if (
    nSmoothing == nullnSmoothing 1;
            if (
    nDLength == nullnDLength 3;
            if (
    Overbought == nullOverbought 80;
            if (
    Oversold == nullOversold 20;
        }
        if (
    bInit == false) {
            
    xStochK stochK(nLengthnSmoothingnDLength);
            
    xStochD stochD(nLengthnSmoothingnDLength);        
            
    bInit true;
        }
        if(
    getCurrentBarIndex() == 0) return;
        var 
    vFast xStochK.getValue(0);
        var 
    vSlow xStochD.getValue(0);
        if(
    vFast == null || vSlow == null)    return;
        if(
    vFast vSlow && vFast Overbought && vSlow Overbought && !Strategy.isLong()) 
            
    Strategy.doLong("Long"Strategy.MARKETStrategy.NEXTBAR);
        if(
    vFast >= vSlow && vFast Oversold && vSlow Oversold && !Strategy.isShort()) 
            
    Strategy.doShort("Short"Strategy.MARKETStrategy.NEXTBAR);
        if(
    Strategy.isLong())
            
    setPriceBarColor(Color.lime);
        else if(
    Strategy.isShort())
            
    setPriceBarColor(Color.red);
        return;

Working...
X