Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        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 -

            BertrandNinjaTrader Customer Service

            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.
                BertrandNinjaTrader Customer Service

                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?
                    BertrandNinjaTrader Customer Service

                    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 Option Whisperer, Today, 09:55 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post Option Whisperer  
                        Started by geddyisodin, 04-25-2024, 05:20 AM
                        8 responses
                        58 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by halgo_boulder, 04-20-2024, 08:44 AM
                        2 responses
                        22 views
                        0 likes
                        Last Post halgo_boulder  
                        Started by mishhh, 05-25-2010, 08:54 AM
                        19 responses
                        6,189 views
                        0 likes
                        Last Post rene69851  
                        Started by gwenael, Today, 09:29 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post gwenael
                        by gwenael
                         
                        Working...
                        X