Announcement

Collapse
No announcement yet.

52-week High EFS Formula for Watch List column use

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

  • 52-week High EFS Formula for Watch List column use

    I want to display a column in a Watch List in eSignal 11.3.2532.1269 32-bit.

    I want the column to display the difference between last price and the 52-Week High.

    To activate this script, I right-mouse on the column heading in the Watch List then "Add Columns -> My Formulas" and select OffHigh.efs (the name of my script.)

    My problem is in getting the value of the 52-Week high. I'm using the upperDonchian function.
    I don't know if this a good approach or if there's a better way to accomplish this.


    As is, the script outputs "Hi null" diagnostic message.

    If I change line 20 to:

    xHigh52Week = upperDonchian(10, inv("W"));

    it works, but this is a 10-week high -- I want the 52-week high.

    How can I get the 52-week high value?

    I'd like to be able to get both:

    - 52-week high excluding today's high
    - 52-week high including today's high

    these would be different if the stock is making a new high today.

    Thanks in advance.

    PHP Code:
    /*
    Return value of difference between last price and 52-Week High 
    */

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Off 52 Week High");
        
    setCursorLabelName("Off Hi");
        
            
    // Appearance
        
    setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
    }

    var 
    bInit false;
    var 
    xHigh52Week  null;

    function 
    main() {

        if(
    bInit == false) {
            
    xHigh52Week upperDonchian(52inv("W"));
            
    bInit true;
        }
           
        
    // Use most recent trade as last price
        
    var vLastPrice getMostRecentTrade(); 
        
        if (
    vLastPrice == null) {
            
            
    // Use current close at last price
            
    vLastPrice close(0);
            if (
    vLastPrice == null) {
               return (
    "Prc Err");
            }
        }

        if (
    xHigh52Week == null) {
            return (
    "Hi Err");
        }
        
        var 
    vHigh xHigh52Week.getValue(0);
        if (
    vHigh == null) {
            return(
    "Hi null");
        }
        
        var 
    vOffHigh vLastPrice vHigh;
        
        if (
    vOffHigh 0) {
            return(
    "---");
        }

        return (
    vOffHigh);

    [B]
    Attached Files

  • #2
    Re: 52-week High EFS Formula for Watch List column use

    sysdev
    By default a Watch List loads only 50 bars so if you are using a study that requires more you need to apply a Time Template to the Watch List to load them.
    This is why you are getting null when you use a length of 52 and instead getting a value when using a length of 10
    Alex


    Originally posted by sysdev
    [B]I want to display a column in a Watch List in eSignal 11.3.2532.1269 32-bit.

    I want the column to display the difference between last price and the 52-Week High.

    To activate this script, I right-mouse on the column heading in the Watch List then "Add Columns -> My Formulas" and select OffHigh.efs (the name of my script.)

    My problem is in getting the value of the 52-Week high. I'm using the upperDonchian function.
    I don't know if this a good approach or if there's a better way to accomplish this.


    As is, the script outputs "Hi null" diagnostic message.

    If I change line 20 to:

    xHigh52Week = upperDonchian(10, inv("W"));

    it works, but this is a 10-week high -- I want the 52-week high.

    How can I get the 52-week high value?

    I'd like to be able to get both:

    - 52-week high excluding today's high
    - 52-week high including today's high

    these would be different if the stock is making a new high today.

    Thanks in advance.

    PHP Code:
    /*
    Return value of difference between last price and 52-Week High 
    */

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Off 52 Week High");
        
    setCursorLabelName("Off Hi");
        
            
    // Appearance
        
    setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
    }

    var 
    bInit false;
    var 
    xHigh52Week  null;

    function 
    main() {

        if(
    bInit == false) {
            
    xHigh52Week upperDonchian(52inv("W"));
            
    bInit true;
        }
           
        
    // Use most recent trade as last price
        
    var vLastPrice getMostRecentTrade(); 
        
        if (
    vLastPrice == null) {
            
            
    // Use current close at last price
            
    vLastPrice close(0);
            if (
    vLastPrice == null) {
               return (
    "Prc Err");
            }
        }

        if (
    xHigh52Week == null) {
            return (
    "Hi Err");
        }
        
        var 
    vHigh xHigh52Week.getValue(0);
        if (
    vHigh == null) {
            return(
    "Hi null");
        }
        
        var 
    vOffHigh vLastPrice vHigh;
        
        if (
    vOffHigh 0) {
            return(
    "---");
        }

        return (
    vOffHigh);

    Comment

    Working...
    X