Announcement

Collapse
No announcement yet.

2008 Aug: Premier Stochastic Oscillator, by Lee Leibfarth

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

  • 2008 Aug: Premier Stochastic Oscillator, by Lee Leibfarth

    File Name: PremiereStochastic.efs

    Description:
    The following studies are based on the August 2008 article, Premier Stochastic Oscillator, by Lee Leibfarth.

    Formula Parameters:
    PremiereStochastic.efs
    Stoch Length: 8
    Period: 25
    Line1: .9
    Line2: .2

    PSO_Strategy.efs
    Stoch Length: 8
    Period: 25
    Line1: .9
    Line2: .2
    Profit Target %: 3
    Stop Loss %: 1.5


    Notes:
    The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.



    Download File:
    PremiereStochastic.efs
    PSO_Strategy.efs






    EFS Code:
    PremierStochastic.efs
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright © eSignal), a division of Interactive Data 
        Corporation. 2008. 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:        Premier Stochastic Oscillator
                        by Lee Leibfarth

    Version:            1.0  6/11/2008

    Notes:
    * August  2008 Issue of Stocks and Commodities Magazine
    * Study requires version 10.1 or later.

    **********************************/


    function preMain(){
        
    setStudyTitle("Premiere Stochastic Oscillator");
        
    setCursorLabelName("PSO",0);
        
    setShowCursorLabel(false,1);
        
    setShowTitleParameters(false);
        
    setPlotType(PLOTTYPE_LINE,0);
        
    setPlotType(PLOTTYPE_HISTOGRAM,1);
        
    setDefaultBarFgColor(Color.black,0);
        
    setDefaultBarFgColor(Color.blue,1);
        
    setStudyMax(1.1);
        
    setStudyMin(-1.1);
        
        var 
    fp1 = new FunctionParameter("StochLength"FunctionParameter.NUMBER);
            
    fp1.setName("Stoch Length");
            
    fp1.setLowerLimit(1);        
            
    fp1.setDefault(8);
        var 
    fp2 = new FunctionParameter("Period"FunctionParameter.NUMBER);
            
    fp2.setName("Period");
            
    fp2.setLowerLimit(1);        
            
    fp2.setDefault(25); 
        var 
    fp3 = new FunctionParameter("Line1"FunctionParameter.NUMBER);
            
    fp3.setName("Line1");
            
    fp3.setLowerLimit(0);        
            
    fp3.setDefault(.9); 
        var 
    fp4 = new FunctionParameter("Line2"FunctionParameter.NUMBER);
            
    fp4.setName("Line2");
            
    fp4.setLowerLimit(0);        
            
    fp4.setDefault(.2); 
    }

    var 
    bVersion    null;
    var 
    bInit false;
    var 
    xPremiere null;

    function 
    main(StochLength,Period,Line1,Line2){
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    
        if(
    bInit == false){
            
    xPremiere efsInternal("calcPremiere",StochLength,Period);
            
    addBand(Line1,PS_SOLID,1,Color.blue,"Line1");
            
    addBand(Line2,PS_SOLID,1,Color.blue,"Line2");
            
    addBand(Line1*(-1),PS_SOLID,1,Color.red,"Line3");
            
    addBand(Line2*(-1),PS_SOLID,1,Color.red,"Line4");
            
    addBand(0PS_SOLID1Color.black"0");
            
    bInit true;
        }
        var 
    nPremiere xPremiere.getValue(0);
        if(
    nPremiere==null) return;
        if(
    nPremiere>=0setBarFgColor(Color.blue,1);
        else 
    setBarFgColor(Color.red,1);
        return new Array (
    nPremiere,nPremiere);
    }

    var 
    xSmoothStoch null;

    function 
    calcPremiere(_stochlength,_period){
        if(
    _period<0)
            var 
    Length 1;
        else
            var 
    Length Math.sqrt(_period);
        if(
    xSmoothStoch==nullxSmoothStoch ema(Length,ema(Length,efsInternal("normStoch",_stochlength)));
        var 
    nSmoothStoch xSmoothStoch.getValue(0);
        if(
    nSmoothStoch==null) return;
        return (
    Math.exp(1*nSmoothStoch)-1)/(Math.exp(1*nSmoothStoch)+1);
    }

    var 
    xStochK null;

    function 
    normStoch(_stochlength){
        if(
    xStochK==nullxStochK stochK(_stochlength,1,1)
        var 
    nStochK xStochK.getValue(0);
        if(
    nStochK==null) return;
        return (
    .1*(nStochK-50));
    }

    function 
    verify() {
        var 
    false;
        if (
    getBuildNumber() < 999) {
            
    drawTextAbsolute(535"This study requires version 10.1 or later."
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"error");
            
    drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"upgrade");
            return 
    b;
        } else {
            
    true;
        }
        return 
    b;


    PSO_Strategy.efs
    PHP Code:
    /*********************************
    Provided By:  
        eSignal (Copyright © eSignal), a division of Interactive Data 
        Corporation. 2008. 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:        Premier Stochastic Oscillator
                        by Lee Leibfarth

    Version:            1.0  6/11/2008

    Notes:
    * August  2008 Issue of Stocks and Commodities Magazine
    * Study requires version 10.1 or later.
    * Study is back testing compatible.

    **********************************/


    function preMain(){
        
    setStudyTitle("PSO Strategy");
        
    setCursorLabelName("PSO"0);
        
    setShowTitleParameters(false);
        
    setDefaultFont("Ariel"11);
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.lightgrey);
        
    setStudyMax(1.1);
        
    setStudyMin(-1.1);
        
        var 
    fp1 = new FunctionParameter("StochLength"FunctionParameter.NUMBER);
            
    fp1.setName("Stoch Length");
            
    fp1.setLowerLimit(1);        
            
    fp1.setDefault(8);
        var 
    fp2 = new FunctionParameter("Period"FunctionParameter.NUMBER);
            
    fp2.setName("Period");
            
    fp2.setLowerLimit(1);        
            
    fp2.setDefault(25); 
        var 
    fp3 = new FunctionParameter("Line1"FunctionParameter.NUMBER);
            
    fp3.setName("Line1");
            
    fp3.setLowerLimit(0);        
            
    fp3.setDefault(.9); 
        var 
    fp4 = new FunctionParameter("Line2"FunctionParameter.NUMBER);
            
    fp4.setName("Line2");
            
    fp4.setLowerLimit(0);        
            
    fp4.setDefault(.2); 
        var 
    fp5 = new FunctionParameter("Profit"FunctionParameter.NUMBER);
            
    fp5.setName("Profit Target %");
            
    fp5.setLowerLimit(0);        
            
    fp5.setDefault(3); 
        var 
    fp6 = new FunctionParameter("Stop"FunctionParameter.NUMBER);
            
    fp6.setName("Stop Loss %");
            
    fp6.setLowerLimit(0);        
            
    fp6.setDefault(1.5); 
    }

    var 
    bVersion    null;
    var 
    bInit false;
    var 
    bBT true;
    var 
    xPremiere null;
    var 
    TargetPrice 0;
    var 
    StopPrice 0;
    var 
    vPosition 0;  // 1=long, 0=flat, -1=short

    function main(StochLength,Period,Line1,Line2,Profit,Stop){
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    
        if (
    bInit == false) {
            
    xPremiere efsInternal("calcPremiere",StochLength,Period);
            
    addBand(Line1,PS_SOLID,1,Color.blue,"Line1");
            
    addBand(Line2,PS_SOLID,1,Color.blue,"Line2");
            
    addBand(Line1*(-1),PS_SOLID,1,Color.red,"Line3");
            
    addBand(Line2*(-1),PS_SOLID,1,Color.red,"Line4");
            
    addBand(0PS_SOLID1Color.black"0");
            
    bInit true;
        }
        
        var 
    nPremiere_0 xPremiere.getValue(0);
        var 
    nPremiere_1 xPremiere.getValue(-1);
        var 
    nPremiere_2 xPremiere.getValue(-2);
        if(
    nPremiere_2==null) return;
        
        if (
    getCurrentBarIndex() >= -1bBT false;
        
        if(
    vPosition == ) { // Long Exit
            
    if(high(0)>=TargetPrice) {
                if (
    bBTStrategy.doSell("Long 

    Target"
    ,Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,Math.max(open(0),TargetPrice));
                
    drawShape(Shape.DOWNARROW,TopRow2,Color.green,"LongTarget"+rawtime(0));
                
    drawText("LT",TopRow1,Color.green,Text.CENTER,"LT"+rawtime(0));
                
    vPosition 0;
            }
            if(
    low(0)<=StopPrice) {
                if (
    bBTStrategy.doSell("Long 

    Stop"
    ,Strategy.STOP,Strategy.THISBAR,Strategy.ALL,Math.min(open(0),StopPrice));
                
    drawShape(Shape.DOWNARROW,TopRow2,Color.red,"LongStop"+rawtime(0));
                
    drawText("LS",TopRow1,Color.red,Text.CENTER,"LS"+rawtime(0));
                
    vPosition 0;
            }
        }
        if(
    vPosition == -1) { // Short Exit
            
    if(low(0)<=TargetPrice){
                if (
    bBTStrategy.doCover("Short 

    Target"
    ,Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,Math.min(open(0),TargetPrice));
                
    drawShape(Shape.UPARROW,BottomRow2,Color.green,"ShortTarget"+rawtime(0));
                
    drawText("ST",BottomRow1,Color.green,Text.CENTER,"ST"+rawtime(0));
                
    vPosition 0;
            }
            if(
    high(0)>=StopPrice) {
                if (
    bBTStrategy.doCover("Short 

    Stop"
    ,Strategy.STOP,Strategy.THISBAR,Strategy.ALL,Math.max(open(0),StopPrice));
                
    drawShape(Shape.UPARROW,BottomRow2,Color.red,"ShortStop"+rawtime(0));
                
    drawText("SS",BottomRow1,Color.red,Text.CENTER,"SS"+rawtime(0));
                
    vPosition 0;
            }
        }
        if(
    getBarState()==BARSTATE_NEWBAR) {
            
    // Long Entry
            
    if(vPosition != && nPremiere_2>Line1&&nPremiere_1<Line1||nPremiere_2>Line2&&nPremiere_1<Line2) {
                if (
    bBTStrategy.doLong("Long Entry",Strategy.MARKET,Strategy.THISBAR,Strategy.DEFAULT);
                
    drawShape(Shape.UPARROW,BottomRow2,Color.blue,"LongEntry"+rawtime(0));
                
    drawText("LE",BottomRow1,Color.blue,Text.CENTER,"LE"+rawtime(0));
                
    TargetPrice open(0)*(1+(Profit/100));
                
    StopPrice   open(0)*(1-(Stop/100));
                
    vPosition 1;
            } 
            
    // Short Entry
            
    if(vPosition != -&& 

    nPremiere_2<Line1*(-1)&&nPremiere_1>Line1*(-1)||nPremiere_2<Line2*(-1)&&nPremiere_1>Line2*(-1)) {
                if (
    bBTStrategy.doShort("Short Entry",Strategy.MARKET,Strategy.THISBAR,Strategy.DEFAULT);
                
    drawShape(Shape.DOWNARROW,TopRow2,Color.magenta,"ShortEntry"+rawtime(0));
                
    drawText("SE",TopRow1,Color.magenta,Text.CENTER,"SE"+rawtime(0));
                
    TargetPrice open(0)*(1-(Profit/100));
                
    StopPrice   open(0)*(1+(Stop/100));
                
    vPosition = -1;
            }
        }
        
        if (
    nPremiere_0 >= 0setBarFgColor(Color.blue);
        else 
    setBarFgColor(Color.red);
        
        if (
    vPosition == 1setDefaultPriceBarColor(Color.blue);
        else if (
    vPosition == -1setDefaultPriceBarColor(Color.red);
        else 
    setDefaultPriceBarColor(Color.lightgrey);
        
        return 
    nPremiere_0;
    }

    var 
    xSmoothStoch null;

    function 
    calcPremiere(_stochlength,_period) {
        if(
    _period<0)
            var 
    Length 1;
        else
            var 
    Length Math.sqrt(_period);
        if(
    xSmoothStoch==nullxSmoothStoch ema(Length,ema(Length,efsInternal("normStoch",_stochlength)));
        var 
    nSmoothStoch xSmoothStoch.getValue(0);
        if(
    nSmoothStoch==null) return;
        return (
    Math.exp(1*nSmoothStoch)-1)/(Math.exp(1*nSmoothStoch)+1);
    }

    var 
    xStochK null;

    function 
    normStoch(_stochlength) {
        if(
    xStochK==nullxStochK stochK(_stochlength,1,1)
        var 
    nStochK xStochK.getValue(0);
        if(
    nStochK==null) return;
        return (
    .1*(nStochK-50));
    }

    function 
    verify() {
        var 
    false;
        if (
    getBuildNumber() < 999) {
            
    drawTextAbsolute(535"This study requires version 10.1 or later."
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"error");
            
    drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                
    null13"upgrade");
            return 
    b;
        } else {
            
    true;
        }
        return 
    b;

    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
Working...
X