Announcement

Collapse
No announcement yet.

Problem ADDING TEXT labels to chart lines.

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

  • Problem ADDING TEXT labels to chart lines.

    I have an EFS that prints the open low high and close of the previous day on the chart. I wanted to label the lines so I could ID them easily. This worked (after an hour of research) but only one line gets labeled. I made an entry for each vOpen vClose vHigh etc.. Is there a limit on drawTexAbsolute that you can only use it once in the script? If someone can tell me what I'm doing wrong or just edit it up and repost it I'd be greatful. I'm not a programmer but I play one on tv.

    for (x=4; x<5; x++) {

    drawTextAbsolute( -x, vOpen+.03, "*Prev Open*", Color.black, Color.white, Text.ONTOP | Text.CENTER, "Courier", 8, x );
    }

    Well hell I dont know if there is a message length limit here but here is the whole script.

    /************************************************** ****************************************
    Copyright © eSignal, a division of Interactive Data Corporation. 2005. All rights reserved.
    This sample eSignal Formula Script (EFS) may be modified and saved under a new filename;
    however, eSignal is no longer responsible for the functionality once modified.
    eSignal reserves the right to modify and overwrite this EFS file with each new release.
    @version 3.0 by Alexis Montenegro for eSignal
    ************************************************** *****************************************/

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("PreviousDayDailyBars");
    setCursorLabelName("PD-O", 0); // Open
    setCursorLabelName("PD-H", 1); // High
    setCursorLabelName("PD-L", 2); // Low
    setCursorLabelName("PD-C", 3); // Close

    setDefaultBarStyle(PS_SOLID, 0); // Open
    setDefaultBarStyle(PS_SOLID, 1); // High
    setDefaultBarStyle(PS_SOLID, 2); // Low
    setDefaultBarStyle(PS_SOLID, 3); // Close

    setDefaultBarFgColor(Color.red, 0); // Open
    setDefaultBarFgColor(Color.olive, 1); // High
    setDefaultBarFgColor(Color.navy, 2); // Low
    setDefaultBarFgColor(Color.blue, 3); // Close

    setDefaultBarThickness(2, 0); // Open
    setDefaultBarThickness(4, 1); // High
    setDefaultBarThickness(4, 2); // Low
    setDefaultBarThickness(2, 3); // Close

    setPlotType(PLOTTYPE_FLATLINES, 0); // Open
    setPlotType(PLOTTYPE_FLATLINES, 1); // High
    setPlotType(PLOTTYPE_FLATLINES, 2); // Low
    setPlotType(PLOTTYPE_FLATLINES, 3); // Close
    }

    var bInit = false;
    var xOpen = null;
    var xHigh = null;
    var xLow = null;
    var xClose = null;

    function main() {

    if(isMonthly() || isWeekly() || isDaily())
    return;

    if(bInit == false){
    xOpen = open(inv("D"));
    xHigh = high(inv("D"));
    xLow = low(inv("D"));
    xClose = close(inv("D"));
    bInit = true;
    }

    var vOpen = xOpen.getValue(-1);
    var vHigh = xHigh.getValue(-1);
    var vLow = xLow.getValue(-1);
    var vClose = xClose.getValue(-1);
    if(vOpen == null || vHigh == null || vLow == null || vClose == null)
    return;



    for (x=4; x<5; x++) {
    drawTextAbsolute ( -x, vOpen, "*Prev Open*", Color.black, Color.white, Text.ONTOP | Text.CENTER, "Courier", 8, x );
    }

    for (w=4; w<5; w++) {
    drawTextAbsolute ( -w, vClose, "*Prev Close*", Color.black, Color.white, Text.ONTOP | Text.CENTER, "Courier", 8, w );
    }

    for (y=4; y<5; y++) {
    drawTextAbsolute ( -y, vHigh, "*Prev High*", Color.black, Color.white, Text.ONTOP | Text.CENTER, "Courier", 8, y );
    }

    for (f=4; f<5; f++) {
    drawTextAbsolute ( -f, vLow, "*Prev Low*", Color.black, Color.white, Text.ONTOP | Text.CENTER, "Courier", 8, f );
    }


    return new Array (vOpen,vHigh,vLow,vClose);
    }

  • #2
    Geoff
    You are only getting one label because you are assigning the same tagID parameter to all the drawTextAbsolute() commands (see the link for an explanation of the parameters).
    In fact x, w, y and f are all equal to 4 hence only one graphical object with that tagID - specifically the last one - will be drawn.
    To fix this first remove all the for loops which are not necessary and then assign a unique tagID parameter to each drawTextAbsolute() command. As a tagID you could use the same text string you wish to draw on the chart eg
    drawTextAbsolute(4, vOpen, "*Prev Open*", Color.black, Color.white, Text.ONTOP | Text.CENTER, "Courier", 8, "PrevOpen");
    Remember to also replace with a value the x, w, y and f in the first parameter of each drawTextAbsolute() command
    Alex

    Comment

    Working...
    X