Announcement

Collapse
No announcement yet.

how to create a 2 % system

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

  • how to create a 2 % system

    i am trying to create a efs which will draw a line 2% above the current swing low and 2% below the current swing high. the 2% would be of the current share price ,
    so if the share price was 400 the line would be drawn 8 above the current swing low,
    is this possible any help will be much appreciated

    thanks.

  • #2
    See if this is what you want.

    You can change the percentage and turn the lines on and off.



    function preMain() {
    setStudyTitle("% Pivot");
    setDefaultBarFgColor(Color.green, 0);
    setDefaultBarFgColor(Color.red, 1)
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    setCursorLabelName("High Pivot", 0);
    setCursorLabelName("Low Pivot", 1);
    setPriceStudy(true);

    var fp1 = new FunctionParameter("vPercent", FunctionParameter.NUMBER);
    fp1.setName("% of Pivot");
    fp1.setDefault(2);
    fp1.setLowerLimit(0);

    var fp2 = new FunctionParameter("vDrawPivot", FunctionParameter.STRING);
    fp2.setName("Draw Lines");
    fp2.addOption( "Yes" );
    fp2.addOption( "No" );
    fp2.setDefault("No");
    }

    var vHighLine = null, vLowLine = null;

    function main(vPercent, vDrawPivot) {


    if (getBarState() == BARSTATE_ALLBARS) {
    }

    if ( vDrawPivot == "Yes"){

    vPercent = vPercent/100;

    if ( high(-2) < high(-1) && high(-1) > high(0)){
    vHighLine = high(-1)*(1-vPercent);
    drawLineAbsolute(-2, vHighLine, 2, vHighLine, PS_SOLID, 3, Color.green, "nHL");
    }

    if ( low(-2) > low(-1) && low(-1) < low(0)){
    vLowLine = low(-1)*(1+vPercent);
    drawLineAbsolute(-2, vLowLine, 2, vLowLine, PS_SOLID, 3, Color.red, "nLL");
    }
    return;
    }
    return;
    }
    Attached Files

    Comment


    • #3
      whatever thanks this will be a big help, its not exactly what i am after but it gives me some building blocks to start with as i did not have a clue where to start, alexis put me onto a efs by jason on zig zags which might be able to pinpoint the swing lows/highs,

      are there supposed to be 2 " returns; " at the bottom of the script or is one a printing error.

      Comment

      Working...
      X