Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using open price variaton to yesterday's close as a parameter

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

    Using open price variaton to yesterday's close as a parameter

    I would like to set a variable value to be used on my strategy which value depends on open price to yesterday close (today first price / yesterday last trade price - RHT).
    How can I do that?
    Last edited by dafonseca; 04-19-2013, 06:42 AM.

    #2
    dafonseca, you could access the values needed with the CurrentDayOHL().CurrentOpen and PriorDayOHLC().PriorClose properties in NinjaScript.




    You would then calculate your value in a variable and use as desired in your strategy conditions.

    Comment


      #3
      Interesting! But where should I define it:
      on Initialized()?
      OnBarUpdate() ->Bars.FirstbarOfSession??

      private doublr PriorClose = PriorDayOHLC().PriorClose;

      Comment


        #4
        Correct, in the OnBarUpdate's FirstBarOfSession you would be able to calculate / store it for reference.

        Comment


          #5
          One more question..
          my strategy uses intrument[0] and [1].
          I ve tested and it sometimes is taking PriorClose[0] and PriorClose[1].
          I want my strategy (below) to get priorClosePrice of the instrument [1] instead of instrument [0].
          How can I get [1] all ways?

          protected override void OnBarUpdate()
          {
          if (Bars.FirstBarOfSession)
          {

          priorClosePrice = PriorDayOHLC().PriorClose[1];

          } ...................

          Comment


            #6
            dafonseca, that would be expected in a MultiSeries environment, since you would then see bar update calls for each series, you can filter and limit these calls for your code via an additional check for BarsInProgress -

            Comment


              #7
              Great!
              Now, supposing I do not want to use priorClose all day long, but instead the Medians price [many hours ago].
              How it will work in case instrument[1] only trades RHT. if now is 10.30 can I consider the Medians[] would be yesterday price at 12.30??? (considering 5 hours lag)
              Do I have to reconsider it when instrument [1] trades EHT, such as ES futures, etc..?
              protected override void OnBarUpdate()
              {
              priorClosePrice2 = Medians[300] (supposing 1 minute bars = 5 hours).
              } ..

              Comment


                #8
                dafonseca, for the session templates used for your MultiSeries scripts, please keep this in mind -

                If a multi-series script adds an additional Bars object that already exists on the chart, the script will use the preexisting series instead of creating a new one to conserve memory. This includes that series' session template as applied from the chart. If the Bars object does not exist on the chart, the session template of the added Bars object will be the session template of the primary Bars object. If the primary Bars object is using the "<Use instrument settings>" session template then the additional Bars objects will use the default session templates as defined for their particular instruments in the Instrument Manager.

                The bar index you use would be relative to the series / BarsInProgress context.

                Comment


                  #9
                  Bars.FirstBarUpdate X PriorClose

                  I need to get yesterday's closing prices for the three instruments which i use on my strategy. Below is part of my code. But the variables are not returning expected values, What am I doing wrong??
                  protected override void OnBarUpdate()
                  {

                  if (BarsInProgress == 0 && Bars.FirstBarOfSession)
                  {
                  priorClosePriceAsset = PriorDayOHLC().PriorClose[0];
                  }
                  if (BarsInProgress == 1 && Bars.FirstBarOfSession)
                  {
                  priorClosePriceVX = PriorDayOHLC().PriorClose[1];
                  }
                  if (BarsInProgress == 2 && Bars.FirstBarOfSession)
                  {
                  priorClosePriceNQ = PriorDayOHLC().PriorClose[2];
                  }

                  Comment


                    #10
                    dafonseca, what values are you getting then vs which you are expecting from this output? The PriorDayOHLC() indicator would work according to the used session template boundaries - which session do you select for the chart from which you run the script?

                    Comment


                      #11
                      Originally posted by dafonseca View Post
                      I need to get yesterday's closing prices for the three instruments which i use on my strategy. Below is part of my code. But the variables are not returning expected values, What am I doing wrong??
                      protected override void OnBarUpdate()
                      {

                      if (BarsInProgress == 0 && Bars.FirstBarOfSession)
                      {
                      priorClosePriceAsset = PriorDayOHLC().PriorClose[0];
                      }
                      if (BarsInProgress == 1 && Bars.FirstBarOfSession)
                      {
                      priorClosePriceVX = PriorDayOHLC().PriorClose[1];
                      }
                      if (BarsInProgress == 2 && Bars.FirstBarOfSession)
                      {
                      priorClosePriceNQ = PriorDayOHLC().PriorClose[2];
                      }
                      You are using BarsInProgress as a filter, so your index should be '0' for all your barSeries.

                      Comment


                        #12
                        Originally posted by koganam View Post
                        You are using BarsInProgress as a filter, so your index should be '0' for all your barSeries.
                        I got it.. It is working know.
                        In case I do not use the filter BarsInProgress , using [0] [1] [2] would work? (and I will get the closing price for all instruments)

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        649 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        370 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        574 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        576 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X