龙听期货论坛's Archiver

龙听 发表于 2018-11-27 16:49

StiffnessIndicator指标[eSIGNAL]

For this month’s Traders’ Tip, we’ve provided the StiffnessIndicator.efs study based on the article by Markos Katsanos in this issue, “The Stiffness Indicator.” This study attempts to determine if markets are in a strong price trend.

The study contains formula parameters that may be configured through the edit chart window (right-click on the chart and select “edit chart”). A sample chart is shown in Figure 2.

[attach]5571[/attach]

龙听 发表于 2018-11-27 16:50

[code]
/*********************************
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:        
    The Stiffness Indicator by Markos Katsanos
   

Version:            1.00  9/14/2018

Formula Parameters:                     Default:
Period                                  60
MA DAYS                                 100
STIFFNESS CRITICAl                      90

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("Stiffness Indicator");
    setCursorLabelName("STIFFNESS");
    setPlotType(PLOTTYPE_HISTOGRAM);
   
    var x = 0;
    fpArray[x] = new FunctionParameter("Period", FunctionParameter.NUMBER);
        with(fpArray[x++]){
        setName("STIFFNESS PERIOD");
        setLowerLimit(1);
        setDefault(60);
        
    }

    fpArray[x] = new FunctionParameter("MAB", FunctionParameter.NUMBER);
        with(fpArray[x++]){
        setName("MA DAYS");
        setLowerLimit(1);
        setDefault(100);
      
    }
    fpArray[x] = new FunctionParameter("STIFFCRIT", FunctionParameter.NUMBER);
        with(fpArray[x++]){
        setName("STIFFNESS CRITICAl");
        setLowerLimit(1);
        setDefault(90);
        
    }
}

var bInit = false;
var bVersion = null;
var xClose = null;
var xMA2 = null;
var nEntryPrice = null;
var xLow = null;
var xHigh = null;
var vStopPrice = null;
var bIsLong = null;
var xCloseSPY = null;
var xEMA = null;
var xStiffness = null;
var bWasLong = false;


function main(Period, MAB, STIFFCRIT){
    if (bVersion == null) bVersion = verify();
    if (bVersion == false) return;
        
    if (getBarState() == BARSTATE_ALLBARS){
        bInit = false;
        bIsLong = false;
    }

    if (getCurrentBarCount() < Period) return;
   
    if (!bInit){
        
        xCloseSPY = close("SPY");
        xClose = close();
        xHigh = high();
        xLow = low();
        bIsLong = false;
        bWasLong = false;
            
        xMA2 = efsInternal("Calc_MA2", xClose, MAB);
        xEMA = efsInternal("Calc_Ema", xCloseSPY, MAB);
        xStiffness = efsInternal("Calc_Stif", xClose, Period, xMA2);
        
        addBand(STIFFCRIT, PS_DASH, 1, Color.grey, 2);
        
        bInit = true;
    }

   
    if (getBarState() == BARSTATE_NEWBAR && xStiffness.getValue(-1) != null)  {   
         if ((xStiffness.getValue(0)<= STIFFCRIT) && bIsLong){      
            
            if (xStiffness.getValue(-1) > STIFFCRIT){
                drawTextRelative(0, TopRow1, "\u00EA", Color.red, null, Text.PRESET|Text.CENTER, "Wingdings", 10, "Exit"+rawtime(0));
                bIsLong = false;                    
            }
            else {
                removeText("Long"+rawtime(0));
                removeText("Text"+rawtime(0));
            }
            bIsLong = false;
        }
   
        if (xEMA.getValue(0) >= xEMA.getValue(-2) && !bIsLong && (xStiffness.getValue(-1) < STIFFCRIT)){                  
            
            if ((xStiffness.getValue(1) > STIFFCRIT)){
                 
                drawTextRelative(0, TopRow1, "\u00E9", Color.green, null, Text.PRESET|Text.CENTER, "Wingdings", 10, "Long"+rawtime(0));
                bIsLong = true;
                bWasLong = true;
            }      
            else {
                removeText("Exit"+rawtime(0));
                removeText("TextExit"+rawtime(0));
                if (bWasLong)
                    bIsLong = true;
                    
            }
        }
    }
    return (xStiffness.getValue(0))
}

var P = null;

function Calc_Stif (xClose, Period, xMA2){
    if (xClose.getValue(-Period) == null || xMA2.getValue(-Period) == null) return;
   
    P = 0;
    for (var i = 0; i < Period; i++) {
        
        if (xClose.getValue(-i) > xMA2.getValue(-i)) P++;
    }
    return (P * 100 / Period);
}

function Calc_MA2(xClose, MAB){   
    if (xClose.getValue(-MAB) == null) return;
    return (sma(MAB) - 0.2 * stdDev(MAB));
}

function Calc_Ema(xCloseSPY, MAB){
    if (xCloseSPY.getValue(-MAB) == null) return;
    return ema(MAB, sym("SPY," + getInterval()));
}

function verify(){
    var b = false;
    if (getBuildNumber() < 3756){
        
        drawTextAbsolute(5, 35, "This study requires version 10.6 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;
}

[/code]
[attach]5571[/attach]

页: [1]