2017 May: Up & Down Detecting Swings by Domenico D'Errico

ICE Data Services -

2017 May: Up & Down Detecting Swings by Domenico D'Errico  

File Name: BollingerBands.efs, Pivot_HighLow.efs, RSI_Cross.efs, RSI_Cross_HLLH.efs

Description:
Up & Down Detecting Swings by Domenico D'Errico

Formula Parameters:
BollingerBands.efs

Period (W): 4
Length: 12
StdDev: 2

Pivot_HighLow.efs

Period: 4

RSI_Cross.efs

Period (W): 4
Length: 5
Overbought Level: 60
Oversold Level: 40

RSI_Cross_HLLH.efs

Period (W): 4
Length: 5
Overbought Level: 60
Oversold Level: 40

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

Download File:
BollingerBands.efs
Pivot_HighLow.efs
RSI_Cross.efs
RSI_Cross_HLLH.efs

BollingerBands.efs, Pivot_HighLow.efs, RSI_Cross.efs, RSI_Cross_HLLH.efs



EFS Code:

BollingerBands.efs



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

Provided By:  

eSignal (Copyright c eSignal), a division of Interactive Data 

Corporation. 2016. 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:        

    Up & Down Detecting Swings by Domenico D'Errico


Version:            1.00  03/14/2017


Formula Parameters:                     Default:

Period (W)                              4

Length                                  12

StdDev                                  2




Notes:

The related article is copyrighted material. If you are not a subscriber

of Stocks & Commodities, please visit www.traders.com.


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


var fpArray = new Array();


function preMain(){

    setPriceStudy(true);

    setStudyTitle("BollingerBands");

    setCursorLabelName("Upper", 0);

    setCursorLabelName("Lower",1);

    

    var x=0;

    fpArray[x] = new FunctionParameter("Period", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Period (W)");

        setDefault(4);

        setLowerLimit(1);

    }

    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Length");

        setDefault(12);

        setLowerLimit(1);

    }

    fpArray[x] = new FunctionParameter("StdDev", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("StdDev");

        setDefault(2);

        setLowerLimit(1);

    }

}


var bInit = false;

var bVersion = null;

var xHigh = null;

var xLow = null;

var xUpper = null;

var xLower = null;

var positionDate = null;

var rawDay = 86400;


function main(Period, Length, StdDev){

    if (bVersion == null) bVersion = verify();

    if (bVersion == false) return;

    

    if (getCurrentBarCount() <= Length) return;

    

    if (getBarState() == BARSTATE_ALLBARS){

        bInit = false;

    }


    if (!bInit){

        xHigh = high();

        xLow = low();

        xUpper = upperBB(Length, StdDev);

        xLower = lowerBB(Length, StdDev);

        positionDate = null;

        bInit = true;

    }


    if (Strategy.isInTrade()){

        if (rawtime(0) >= (positionDate + rawDay * (Period * 7))){

            if (Strategy.isLong()){

                Strategy.doSell("BB CROSS OVER Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

            else if (Strategy.isShort()){

                Strategy.doCover("BB CROSS UNDER Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

        }

    }


    if (getCurrentBarIndex() != 0){

        if (!Strategy.isInTrade()){

            if (xLow.getValue(-1) < xLower.getValue(-1) && xLow.getValue(0) > xLower.getValue(0)){

                Strategy.doLong("BB CROSS OVER", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(0,BelowBar2, "\u00E9", Color.green, null, Text.PRESET|Text.CENTER, "Wingdings", 10, positionDate);

            }

            else if (xHigh.getValue(-1) > xUpper.getValue(-1) && xHigh.getValue(0) < xUpper.getValue(0)){

                Strategy.doShort("BB CROSS UNDER", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(0, AboveBar2, "\u00EA", Color.red, null, Text.PRESET|Text.CENTER, "Wingdings", 10, positionDate);

            }

        }

    }

    return [xUpper.getValue(0), xLower.getValue(0)];

}


function verify(){

    var b = false;

    if (getBuildNumber() < 3742){

        drawTextAbsolute(5, 35, "This study requires version 12.1 or later.", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "error");

        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "upgrade");

        return b;

    } 

    else

        b = true;

    

    return b;

}


Pivot_HighLow.efs


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

Provided By:  

eSignal (Copyright c eSignal), a division of Interactive Data 

Corporation. 2016. 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:        

    Up & Down Detecting Swings by Domenico D'Errico


Version:            1.00  03/14/2017


Formula Parameters:                     Default:

Period                                  4




Notes:

The related article is copyrighted material. If you are not a subscriber

of Stocks & Commodities, please visit www.traders.com.


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


var fpArray = new Array();


function preMain(){

    setPriceStudy(true);

    setStudyTitle("Pivot H/L");

    

    var x=0;

    fpArray[x] = new FunctionParameter("Period", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Period");

        setDefault(4);

        setLowerLimit(1);

    }

}


var bInit = false;

var bVersion = null;

var xHigh = null;

var xLow = null;

var positionDate = null;

var rawDay = 86400;


function main(Period){

    if (bVersion == null) bVersion = verify();

    if (bVersion == false) return;

    

    if (getBarState() == BARSTATE_ALLBARS){

        bInit = false;

    }


    if (!bInit){

        xHigh = high();

        xLow = low();

        positionDate = null;

        bInit = true;

    }


    if (Strategy.isInTrade()){

        if (rawtime(0) >= (positionDate + (rawDay * Period * 7))){

            if (Strategy.isLong()){

                Strategy.doSell("PIVOT LOW Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

            else if (Strategy.isShort()){

                Strategy.doCover("PIVOT HIGH Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

        }

    }


    if (getCurrentBarIndex() != 0){

        if (!Strategy.isInTrade()){

            if (IsPivotLow(xLow)){

                Strategy.doLong("PIVOT LOW", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(-1,BelowBar1, "\u009F", Color.green, null, Text.PRESET|Text.CENTER, "Wingdings", 11, positionDate);

            }

            else if (IsPivotHigh(xHigh)){

                Strategy.doShort("PIVOT HIGH", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(-1, AboveBar1, "\u009F", Color.red, null, Text.PRESET|Text.CENTER, "Wingdings", 11, positionDate);

            }

        }

    }

    return;

}


function IsPivotLow(xLow){

    var res = false;

    if (xLow != null){

        if (xLow.getValue(-1) < xLow.getValue(0) &&

            xLow.getValue(-1) < xLow.getValue(-2))

            res = true;

    }

    return res;

}


function IsPivotHigh(xHigh){

    var res = false;

    if (xHigh != null){

        if (xHigh.getValue(-1) > xHigh.getValue(0) &&

            xHigh.getValue(-1) > xHigh.getValue(-2))

            res = true;

    }

    return res;

}


function verify(){

    var b = false;

    if (getBuildNumber() < 3742){

        drawTextAbsolute(5, 35, "This study requires version 12.1 or later.", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "error");

        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "upgrade");

        return b;

    } 

    else

        b = true;

    

    return b;

}


RSI_Cross.efs


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

Provided By:  

eSignal (Copyright c eSignal), a division of Interactive Data 

Corporation. 2016. 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:        

    Up & Down Detecting Swings by Domenico D'Errico


Version:            1.00  03/14/2017


Formula Parameters:                     Default:

Period (W)                              4

Length                                  5

Overbought Level                        60

Oversold Level                          40




Notes:

The related article is copyrighted material. If you are not a subscriber

of Stocks & Commodities, please visit www.traders.com.


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


var fpArray = new Array();


function preMain(){

    setPriceStudy(false);

    setStudyTitle("RSI Cross");

    setDefaultBarFgColor(Color.grey);

    setCursorLabelName("RSI");

    

    var x=0;

    fpArray[x] = new FunctionParameter("Period", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Period (W)");

        setDefault(4);

        setLowerLimit(1);

    }

    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Length");

        setDefault(5);

        setLowerLimit(1);

    }

    fpArray[x] = new FunctionParameter("UpLevel", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Overbought level");

        setDefault(60);

    }

    fpArray[x] = new FunctionParameter("LwLevel", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Oversold Level");

        setDefault(40);

    }

}


var bInit = false;

var bVersion = null;

var xRSI = null;

var positionDate = null;

var rawDay = 86400;


function main(Period, Length, UpLevel, LwLevel){

    if (bVersion == null) bVersion = verify();

    if (bVersion == false) return;

    

    if (getCurrentBarCount() <= Length) return;

    

    if (getBarState() == BARSTATE_ALLBARS){

        bInit = false;

    }


    if (!bInit){

        xRSI = rsi(Length);

        addBand(UpLevel, PS_DASH, 1, Color.grey, "Overbought");

        addBand(LwLevel, PS_DASH, 1, Color.grey, "Oversold");

        positionDate = null;

        bInit = true;

    }


    if (Strategy.isInTrade()){

        if (rawtime(0) >= (positionDate + rawDay * (Period * 7))){

            if (Strategy.isLong()){

                Strategy.doSell("RSI CROSS OVER Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

            else if (Strategy.isShort()){

                Strategy.doCover("RSI CROSS UNDER Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

        }

    }


    if (getCurrentBarIndex() != 0){

        if (!Strategy.isInTrade()){

            if (xRSI.getValue(-1) < LwLevel && xRSI.getValue(0) > LwLevel){

                Strategy.doLong("RSI CROSS OVER", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(0, BottomRow1, "\u00E9", Color.green, null, Text.PRESET|Text.CENTER, "Wingdings", 10, positionDate);

            }

            else if (xRSI.getValue(-1) > UpLevel && xRSI.getValue(0) < UpLevel){

                Strategy.doShort("RSI CROSS UNDER", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(0, TopRow1, "\u00EA", Color.red, null, Text.PRESET|Text.CENTER, "Wingdings", 10, positionDate);

            }

        }

    }


    if (xRSI.getValue(0) > UpLevel) setBarFgColor(Color.red);

    else if (xRSI.getValue(0) < LwLevel) setBarFgColor(Color.green);


    return xRSI.getValue(0);

}


function verify(){

    var b = false;

    if (getBuildNumber() < 3742){

        drawTextAbsolute(5, 35, "This study requires version 12.1 or later.", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "error");

        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "upgrade");

        return b;

    } 

    else

        b = true;

    

    return b;

}


RSI_Cross_HLLH


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

Provided By:  

eSignal (Copyright c eSignal), a division of Interactive Data 

Corporation. 2016. 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:        

    Up & Down Detecting Swings by Domenico D'Errico


Version:            1.00  03/14/2017


Formula Parameters:                     Default:

Period (W)                              4

Length                                  5

Overbought Level                        60

Oversold Level                          40




Notes:

The related article is copyrighted material. If you are not a subscriber

of Stocks & Commodities, please visit www.traders.com.


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


var fpArray = new Array();


function preMain(){

    setPriceStudy(false);

    setStudyTitle("RSI Cross HLLH");

    setDefaultBarFgColor(Color.grey);

    setCursorLabelName("RSI");

    

    var x=0;

    fpArray[x] = new FunctionParameter("Period", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Period (W)");

        setDefault(4);

        setLowerLimit(1);

    }

    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Length");

        setDefault(5);

        setLowerLimit(1);

    }

    fpArray[x] = new FunctionParameter("UpLevel", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Overbought level");

        setDefault(60);

    }

    fpArray[x] = new FunctionParameter("LwLevel", FunctionParameter.NUMBER);

      with(fpArray[x++]){

        setName("Oversold Level");

        setDefault(40);

    }

}


var bInit = false;

var bVersion = null;

var xRSI = null;

var xHigh = null;

var xLow = null;

var positionDate = null;

var rawDay = 86400;


function main(Period, Length, UpLevel, LwLevel){

    if (bVersion == null) bVersion = verify();

    if (bVersion == false) return;

    

    if (getCurrentBarCount() <= Length) return;

    

    if (getBarState() == BARSTATE_ALLBARS){

        bInit = false;

    }


    if (!bInit){

        xRSI = rsi(Length);

        xHigh = high();

        xLow = low();

        addBand(UpLevel, PS_DASH, 1, Color.grey, "Overbought");

        addBand(LwLevel, PS_DASH, 1, Color.grey, "Oversold");

        positionDate = null;

        bInit = true;

    }


    if (Strategy.isInTrade()){

        if (rawtime(0) >= (positionDate + rawDay * (Period * 7))){

            if (Strategy.isLong()){

                Strategy.doSell("RSI CROSS OVER Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

            else if (Strategy.isShort()){

                Strategy.doCover("RSI CROSS UNDER Exit", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

            }

        }

    }


    if (getCurrentBarIndex() != 0){

        if (!Strategy.isInTrade()){

            if (xRSI.getValue(0) < LwLevel && xLow.getValue(0) > xLow.getValue(-1)){

                Strategy.doLong("RSI CROSS OVER", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(0, BottomRow1, "\u00E9", Color.green, null, Text.PRESET|Text.CENTER, "Wingdings", 10, positionDate);

            }

            else if (xRSI.getValue(0) > UpLevel && xHigh.getValue(0) < xHigh.getValue(-1)){

                Strategy.doShort("RSI CROSS UNDER", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);

                positionDate = rawtime(0);

                drawTextRelative(0, TopRow1, "\u00EA", Color.red, null, Text.PRESET|Text.CENTER, "Wingdings", 10, positionDate);

            }

        }

    }


    if (xRSI.getValue(0) > UpLevel) setBarFgColor(Color.red);

    else if (xRSI.getValue(0) < LwLevel) setBarFgColor(Color.green);


    return xRSI.getValue(0);

}


function verify(){

    var b = false;

    if (getBuildNumber() < 3742){

        drawTextAbsolute(5, 35, "This study requires version 12.1 or later.", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "error");

        drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", 

            Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,

            null, 13, "upgrade");

        return b;

    } 

    else

        b = true;

    

    return b;

}