Announcement

Collapse
No announcement yet.

Slope Trend Indicator

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

  • Slope Trend Indicator

    I am not a pro, so I don't know if it already exists and its real name !!!
    I thought about a surrogate for Linear Regression, easy to calculate, that I called "Trend Slope Indicator" for obvious reasons .
    Although this indicator is extremely trivial, I find it useful as a filter within trading systems to prevent trades during non-trendy market, for example by avoiding operations where its value is less than 0.5.
    When it has high values​​, for example greater than 2, it indicates that we are in a trendy market and it is better to approach the trailing stop because there could be a reversal.
    So it's a simple indicator of trend. Remember to set the tick properly.
    Passing correctly the parameters can be used as a efsExternal.
    Let me Know if you find other interesting ways to use it.
    Regards
    Massimo

    /************************************************** ********************
    SLOPE TREND INDICATOR by Massimo Rizzi ([email protected]) May 2011
    I used as a sample an EFS 2 Custom provided by ESignal !
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** *********************/

    var fpArray = new Array();

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("SlopeTrendIndicator");
    setCursorLabelName("STI",0);
    setDefaultBarFgColor(Color.blue,0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(10);
    }
    fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
    with(fpArray[x++]){
    addOption("open()");
    addOption("high()");
    addOption("low()");
    addOption("close()");
    addOption("hl2()");
    addOption("hlc3()");
    addOption("ohlc4()");
    setDefault("close()");
    }
    fpArray[x] = new FunctionParameter("Tick", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault(0.001);
    }
    fpArray[x] = new FunctionParameter("Offset", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault(0);
    }
    }

    var bInit = false;
    var vSource = null, vLength = null, vTick = null, vOffset=null;
    var xA = null, xB = null, xSTI = null;

    function main(Length,Source,Tick,Offset) {
    if (bInit == false) {
    vLength = Length;
    vSource = Source;
    vTick = Tick;
    vOffset = Offset;
    bInit = true;
    }

    xA = hhv(vLength, eval(vSource)).getValue(vOffset);
    xB = llv(vLength, eval(vSource)).getValue(vOffset);
    xSTI = ((xA-xB)/vLength)/vTick;
    return xSTI;
    }
Working...
X