Announcement

Collapse
No announcement yet.

Help with Formula please

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

  • Help with Formula please

    Hope someone can help me here.

    I've got a formula that prints the day's high/low after the first 30mins.

    However, it also prints the highs or lows leading up to this point. See attached chart.
    Is there a way to stop this please.

    Here's the formula:

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("First X mins HL ");
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.blue, 1);
    setDefaultBarThickness(1, 0);
    setDefaultBarThickness(1, 1);
    setPlotType(PLOTTYPE_FLATLINES, 0);
    setPlotType(PLOTTYPE_FLATLINES, 1);
    setShowCursorLabel(false);


    var fp1 = new FunctionParameter("nMin", FunctionParameter.NUMBER);
    fp1.setName("Number of Minutes");
    fp1.setLowerLimit(1);
    fp1.setDefault(35);

    var fp2 = new FunctionParameter("nThickness", FunctionParameter.NUMBER);
    fp2.setName("Line Thickness");
    fp2.setLowerLimit(1);
    fp2.setDefault(1);

    var fp3 = new FunctionParameter("cColor", FunctionParameter.COLOR);
    fp3.setName("Line Color");
    fp3.setDefault(Color.blue);
    }

    var bEdit = true;
    var bActive = true;
    var nDayCntr = 0;

    var vStartTime = null;
    var vHigh = null;
    var vLow = null;
    var FirstBar = null;

    function main(nMin, nThickness, cColor) {
    if (nMin == null) nMin = 35;
    if (bEdit == true) {
    nMin = Math.round(nMin);
    setCursorLabelName(nMin + "min H", 0);
    setCursorLabelName(nMin + "min L", 1);
    setDefaultBarThickness(nThickness, 0);
    setDefaultBarThickness(nThickness, 0);
    setDefaultBarFgColor(cColor, 0);
    setDefaultBarFgColor(cColor, 1);
    bEdit = false;
    }

    if (getDay() != getDay(-1) || vHigh == null || vLow == null) {
    bActive = true;
    nDayCntr += 1;
    vStartTime = getValue("Time");
    vHigh = high();
    vLow = low();
    }
    FirstBar = getFirstBarIndexOfDay(vStartTime);
    var vTime = getValue("Time");

    // 3,600,000 milliseconds = 1 hour
    // 60,000 milliseconds = 1 minute
    if ((vTime - vStartTime)/60000 < nMin) {
    vHigh = Math.max(high(), vHigh);
    vLow = Math.min(low(), vLow);
    } else {
    bActive = false;
    }

    if (FirstBar != null) {
    drawLineRelative( FirstBar, vHigh, 0, vHigh, PS_SOLID, nThickness,
    cColor, "Hline");

    drawLineRelative( FirstBar, vLow, 0, vLow, PS_SOLID, nThickness,
    cColor, "Lline")

    }



    return new Array(vHigh, vLow);


    return null;
    }
    Attached Files

  • #2
    I think...

    You just need to remove the following line in your code..

    return new Array(vHigh, vLow);

    This line returns the vHigh and vLow values (as they are created) - thus creating the lines that you don't like.

    I believe by removing this statement you will get the desired results.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment

    Working...
    X