Announcement

Collapse
No announcement yet.

Help please on 2 simple efs

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

  • Help please on 2 simple efs

    I have written two simple efs that work ok but i'm not sure if this is the most efficient way of doing these please comment.

    1/ This function just draws a blue line on the chart at 9:30 so I can see pre mkt vs mkt bars.

    function preMain()
    {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */

    setPriceStudy(true);
    setStudyTitle("Mkt Open");
    setShowCursorLabel(false);

    }


    var i = 0;

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    // If it 930am

    if (
    getHour() == 9 &&
    getMinute() == 30

    )
    {

    i = getCurrentBarIndex();
    drawLineAbsolute(i, (close()*1+1000), i, (close()*1-1000), PS_SOLID, 1, Color.blue, "Open");

    }

    return null;

    }

    2/ This function draws a time box at the bottom left corner of the cart and counts down the current bar time.

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Bar Time");
    setShowCursorLabel(false);
    }

    var vTimeStamp = null;
    var vInt = null;

    function main() {
    if (!isIntraday() || getCurrentBarIndex() < -1) return;
    var nState = getBarState();
    var vClockTime = new Date()*1;

    if (vInt == null) vInt = (getInterval()*60000); // convert to milliseconds
    if (nState == BARSTATE_NEWBAR) {
    vTimeStamp = getValue("Time")*1 + vInt;
    }

    var vTimeLeft = (vTimeStamp - vClockTime);
    if (vTimeLeft < 0) return;

    var vHr = 0;
    var vMin = 0;
    var vSec = 0;

    if (vInt > 3600000) {
    vHr = Math.floor(vTimeLeft/3600000);
    vTimeLeft -= (vHr*3600000);
    }
    if (vInt > 60000) {
    vMin = Math.floor(vTimeLeft/60000);
    vTimeLeft -= (vMin*60000);
    }
    vSec = Math.floor(vTimeLeft/1000);

    if (vHr < 10) vHr = ("0" + vHr);
    if (vMin < 10) vMin = ("0" + vMin);
    if (vSec < 10) vSec = ("0" + vSec);

    vTimeLeft = (" " + vHr + ":" + vMin + ":" + vSec + " ");
    //debugPrintln(vTimeLeft);
    drawTextAbsolute(5, 15, vTimeLeft, Color.black, Color.white,
    Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.FRAME | Text.BOLD | Text.CENTER,
    null, 10, "TR");

    //drawTextAbsolute(-70, 45, vTimeLeft, Color.black, Color.white,
    // Text.BOLD|Text.LEFT|Text.FRAME|Text.RELATIVETOTOP, null, 12, "TR");

    return;
    }

    Thanks for your help
    Attached Files
    Simon Allen

  • #2
    Looks OK to me. Why don't you open up the EFS Performance Monitor and ENABLE IT, then see if these scripts run under 1.0 or 2.0 ms total access time. If so, you should be good to go.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment

    Working...
    X