Announcement

Collapse
No announcement yet.

Percentage change from open?

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

  • Percentage change from open?

    Hi everyone,

    I am having difficulty tracking the percentage change from the open for a stock compared to the SPY in real-time. The problem I am having is that I do not know how to obtain the open price for the day and then, in turn, compare that to the current price.

    Some help would be great!

    Thanks.

    Jake

  • #2
    Re: Percentage change from open?

    Jake
    To retrieve the Open of an external interval [ie an interval that is different from the one plotted on the chart] you need to use the inv() function inside the open() function and pass the interval that you want for your calculations. For the description and syntax of the inv() function together with several examples of its use (including one for the daily Open) see the link to the corresponding article in the EFS KnowledgeBase
    To calculate the percentage change you would use the following equation
    ((Current_Close-Daily_Open)/Daily_Open)*100
    If you then want to calculate the same equation for an external symbol and interval you need to use the sym() function which allows you to pass to the open() function a symbol and/or interval that are different from ther one being charted (see the examples at the linked article)
    Hope this helps
    Alex


    Originally posted by sunyata_trader
    Hi everyone,

    I am having difficulty tracking the percentage change from the open for a stock compared to the SPY in real-time. The problem I am having is that I do not know how to obtain the open price for the day and then, in turn, compare that to the current price.

    Some help would be great!

    Thanks.

    Jake

    Comment


    • #3
      Alexis,

      Thank you for your help! Your solution worked perfectly. Here's the code:

      PHP Code:
      var SPYOpen open(0sym("SPY,D"));     
      debugPrintln("SPY's open was:"+SPYOpen);     
      var 
      SPYClose close(0,"SPY");     
      var 
      SPYPercentChange = ((SPYClose SPYOpen)/SPYOpen)*100;     
      var 
      StockOpen open(0inv("D"));     debugPrintln("Stock's open was:"+StockOpen);     
      var 
      StockClose close(0);     
      var 
      StockPercentChange = ((StockClose StockOpen)/StockOpen)*100;        

      return Array(
      SPYPercentChangeStockPercentChange); 
      Best,
      Jake

      Comment


      • #4
        Data only goes back so far

        Hi Alexis,

        I have run into another problem. For some reason the indicator no longer has data values for the Stock's daily open after 2 and a half days. At that time, the indicator just stops. Why do you think this would be? I would like to back at the historical action of this indicator.

        Thanks.

        Jake

        Comment


        • #5
          Jake
          You are most welcome
          Although the syntax you used in the following line will work
          var SPYClose = close(0,"SPY");
          that is the [legacy] efs1 syntax which syncs the values of the external symbols and/or intervals by bar index rather than by date and time as the efs2 functions do [which ensures a proper syncing] so you should change that to
          var SPYClose = close(0,sym("SPY"));
          Alex


          Originally posted by sunyata_trader
          Alexis,

          Thank you for your help! Your solution worked perfectly. Here's the code:

          PHP Code:
          var SPYOpen open(0sym("SPY,D"));     
          debugPrintln("SPY's open was:"+SPYOpen);     
          var 
          SPYClose close(0,"SPY");     
          var 
          SPYPercentChange = ((SPYClose SPYOpen)/SPYOpen)*100;     
          var 
          StockOpen open(0inv("D"));     debugPrintln("Stock's open was:"+StockOpen);     
          var 
          StockClose close(0);     
          var 
          StockPercentChange = ((StockClose StockOpen)/StockOpen)*100;        

          return Array(
          SPYPercentChangeStockPercentChange); 
          Best,
          Jake

          Comment

          Working...
          X