Announcement

Collapse
No announcement yet.

Spread Translations into EFS

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

  • Spread Translations into EFS

    Hello All,

    We received a question recently from a customer in another forum on how to translate the following spread calculation into EFS.

    (2.5 * MSFT(change from prior close) - (dell(change from prior close).

    The easiest way to accomplish this type of task is to break it down into smaller pieces and then put them together at the end.

    To get the change from the prior day's close for a specific symbol you would use the close() and the sym() function to reference the current (bar 0) and previous (bar -1) day's values like below.

    close(0, sym("MSFT,D") - close(-1, sym("MSFT,D")

    This would be the same for DELL.

    close(0, sym("DELL,D") - close(-1, sym("DELL,D")

    To put it all together, you would end up with the following EFS code.

    PHP Code:
    function main() {
        return 
    2.5 * ( (close(0,sym("MSFT,D"))-close(-1,sym("MSFT,D"))) - (close(0,sym("DELL,D"))-close(-1,sym("DELL,D"))) );

    Another way to do this to make it easier to read would be to assign each piece of the formula to a variable and then use the variables to perform the calculation.

    PHP Code:
    function main() {
        var 
    nChg1 = (close(0,sym("MSFT,D"))-close(-1,sym("MSFT,D")));
        var 
    nChg2 = (close(0,sym("DELL,D"))-close(-1,sym("DELL,D")));
        
        return 
    2.5 * ( nChg1 nChg2 );

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation
Working...
X