Announcement

Collapse
No announcement yet.

Daily Pivots

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

  • Daily Pivots

    Until one of esignal's updates the following code used to give me the daily pivots from historical data. But now it only works in real time, so I can no longer see the previous days pivots defore 9:30 AM EDT. Why? and How do I make it work on historical data?

    var pp = null;
    var r1 = null;
    var r2 = null;
    var r3 = null;
    var s1 = null;
    var s2 = null;
    var s3 = null;
    var DayClose = null;
    var DayHigh = null;
    var DayLow = null;
    var dr = null;
    var vArray = null;
    var mr23 = null;
    var mr12 = null;
    var mr01 = null;
    var ms01 = null;
    var ms12 = null;
    var ms23 = null;

    function round(n,precision) { // to nearest 1/precision
    if (n==null) return 0;
    else return Math.round(n*precision)/precision;
    }

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Pivot Points Daily");
    setCursorLabelName("PP-R3", 0);
    setCursorLabelName("PP-R2", 1);
    setCursorLabelName("PP-R1", 2);
    setCursorLabelName("PP", 3);
    setCursorLabelName("PP-S1", 4);
    setCursorLabelName("PP-S2", 5);
    setCursorLabelName("PP-S3", 6);
    setCursorLabelName("MPP-R2-R3", 7);
    setCursorLabelName("MPP-R1-R2", 8);
    setCursorLabelName("MPP-R1-PP", 9);
    setCursorLabelName("MPP-S1-PP", 10);
    setCursorLabelName("MPP-S1-S2", 11);
    setCursorLabelName("MPP-S2-S3", 12);

    // R3
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarFgColor(Color.RGB(0,0,0), 0);
    setDefaultBarThickness(3, 0);

    // R2
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarFgColor(Color.RGB(0,0,0), 1);
    setDefaultBarThickness(3, 1);

    // R1
    setDefaultBarStyle(PS_SOLID, 2);
    setDefaultBarFgColor(Color.RGB(0,0,0), 2);
    setDefaultBarThickness(3, 2);

    // Pivot Point
    setDefaultBarStyle(PS_SOLID, 3);
    setDefaultBarFgColor(Color.RGB(0,0,0), 3);
    setDefaultBarThickness(3, 3);

    // S1
    setDefaultBarStyle(PS_SOLID, 4);
    setDefaultBarFgColor(Color.RGB(0,0,0), 4);
    setDefaultBarThickness(3, 4);

    // S2
    setDefaultBarStyle(PS_SOLID, 5);
    setDefaultBarFgColor(Color.RGB(0,0,0), 5);
    setDefaultBarThickness(3, 5)

    // S3
    setDefaultBarStyle(PS_SOLID, 6);
    setDefaultBarFgColor(Color.RGB(0,0,0), 6);
    setDefaultBarThickness(3, 6)

    // R2-R3 MP
    setDefaultBarStyle(PS_DASH, 7);
    setDefaultBarFgColor(Color.RGB(0,0,0), 7);
    setDefaultBarThickness(2, 7)

    // R1-R2 MP
    setDefaultBarStyle(PS_DASH, 8);
    setDefaultBarFgColor(Color.RGB(0,0,0), 8);
    setDefaultBarThickness(2, 8)

    // R1-PP MP
    setDefaultBarStyle(PS_DASH, 9);
    setDefaultBarFgColor(Color.RGB(0,0,0), 9);
    setDefaultBarThickness(2, 9)

    // S1-PP MP
    setDefaultBarStyle(PS_DASH, 10);
    setDefaultBarFgColor(Color.RGB(0,0,0), 10);
    setDefaultBarThickness(2, 10)

    // S1-S2 MP
    setDefaultBarStyle(PS_DASH, 11);
    setDefaultBarFgColor(Color.RGB(0,0,0), 11);
    setDefaultBarThickness(2, 11)

    // S2-S3 MP
    setDefaultBarStyle(PS_DASH, 12);
    setDefaultBarFgColor(Color.RGB(0,0,0), 12);
    setDefaultBarThickness(2, 12)

    }

    function main() {
    var bHour = getHour();
    var bMin = getMinute();
    newbar=(getBarState() == BARSTATE_NEWBAR);
    if (newbar) {
    if (bHour == 9 && bMin == 30) {
    DayClose = close(-1)
    setGlobalValue("globalDailyClose"+getSymbol(),DayC lose);
    if (high(-1)>DayHigh) DayHigh = high(-1);
    if (low(-1)<DayLow) DayLow = low(-1);
    setGlobalValue("globalDailyHigh"+getSymbol(),DayHi gh);
    setGlobalValue("globalDailyLow"+getSymbol(),DayLow );
    pp = (DayHigh+DayLow+DayClose)/3;
    r1 = 2*pp-DayLow;
    s1 = 2*pp-DayHigh;
    dr = DayHigh-DayLow;
    r2 = pp+dr;
    s2 = pp-dr;
    r3 = r2+dr;
    s3 = s2-dr;
    mr23 = round((r3+r2)/2,10);
    mr12 = round((r2+r1)/2,10);
    mr01 = round((r1+pp)/2,10);
    ms01 = round((s1+pp)/2,10);
    ms12 = round((s2+s1)/2,10);
    ms23 = round((s3+s2)/2,10);
    pp = round(pp,10);
    r1 = round(r1,10);
    s1 = round(s1,10);
    r2 = round(r2,10);
    s2 = round(s2,10);
    r3 = round(r3,10);
    s3 = round(s3,10);
    vArray = new Array(r3,r2,r1,pp,s1,s2,s3,mr23,mr12,mr01,ms01,ms1 2,ms23)
    drawTextAbsolute(1,pp,"PP",Color.black,null,Text.B OLD | Text.VCENTER,"Arial",10,"PivotTag11");
    drawTextAbsolute(1,r1,"R1",Color.black,null,Text.B OLD | Text.VCENTER,"Arial",10,"PivotTag13");
    drawTextAbsolute(1,r2,"R2",Color.black,null,Text.B OLD | Text.VCENTER,"Arial",10,"PivotTag14");
    drawTextAbsolute(1,r3,"R3",Color.black,null,Text.B OLD | Text.VCENTER,"Arial",10,"PivotTag15");
    drawTextAbsolute(1,s1,"S1",Color.black,null,Text.B OLD | Text.VCENTER,"Arial",10,"PivotTag16");
    drawTextAbsolute(1,s2,"S2",Color.black,null,Text.B OLD | Text.VCENTER,"Arial",10,"PivotTag17");
    drawTextAbsolute(1,s3,"S3",Color.black,null,Text.B OLD | Text.VCENTER,"Arial",10,"PivotTag18");
    drawTextAbsolute(1,mr23,"R2-R3",Color.black,null,Text.BOLD | Text.VCENTER,"Arial",10,"PivotTag25");
    drawTextAbsolute(1,mr12,"R1-R2",Color.black,null,Text.BOLD | Text.VCENTER,"Arial",10,"PivotTag26");
    drawTextAbsolute(1,mr01,"R1-PP",Color.black,null,Text.BOLD | Text.VCENTER,"Arial",10,"PivotTag27");
    drawTextAbsolute(1,ms01,"S1-PP",Color.black,null,Text.BOLD | Text.VCENTER,"Arial",10,"PivotTag28");
    drawTextAbsolute(1,ms12,"S1-S2",Color.black,null,Text.BOLD | Text.VCENTER,"Arial",10,"PivotTag29");
    drawTextAbsolute(1,ms23,"S2-S3",Color.black,null,Text.BOLD | Text.VCENTER,"Arial",10,"PivotTag30");
    }
    if (bHour == 9 && bMin == 31) {
    DayHigh = high(-1)
    DayLow = low(-1)
    }
    else {
    if (high(-1)>DayHigh) DayHigh = high(-1);
    if (low(-1)<DayLow) DayLow = low(-1);
    }
    }
    if (vArray == null) return;
    else return vArray;
    }

  • #2
    Fixed

    Guess I stumped everyone. I solved it.

    Comment

    Working...
    X