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

Previous day high low open close price in C#

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

    Previous day high low open close price in C#

    Hi Team,
    I will be using 5 minutes time timeframe for intraday but I need previous day with timeframe of day Low, High, Open and Close Price details.
    How can I get the details while I am in 5 minutes candle but looking for previous day DAY candle details




    #2
    Hello rajeshks1988,

    Thank you for your post.

    You could call the PriorDayOHLC indicator to get that information:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your quick reply.
      Could you please let me know how I can check today's Open Price.
      I can loop to all 5 candles but I wanted to know if there is any option to get Open price of the day?

      Comment


        #4
        Hello rajeshks1988,

        Thank you for your reply.

        You could call CurrentDayOHL().CurrentOpen[0] to get the current session open for the current bar:



        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thank you.

          Comment


            #6
            Hi Team,
            I am using following code for getting previous day hig low


            double previousDayClose = PriorDayOHLC().PriorClose[0];
            double previousDayHigh = PriorDayOHLC().PriorHigh[0];
            double previousDayOpen = PriorDayOHLC().PriorOpen[0];
            double previousDayLow = PriorDayOHLC().PriorLow[0];

            But Getting value as 0 for high low open and close.

            can you suggest me.
            I am trying in offline market but it suppose to work right.

            Comment


              #7
              Sorry I am able to get the previous Day data but not matching the value with previous close price.

              Can you please suggest why

              MY stock previous close 1350 but here I am getting 1360.

              Comment


                #8
                Hello rajeshks1988,

                Thank you for your reply.

                Since the PriorDayOHLC calculates from intraday data, while daily bars use the settlement close, it would be expected that they would be different.

                If you wish to get the prior day settlement close, you would need to add an additional 1 day series in your code, ensure you have at least 1 daily bar before calculating, and then reference the close price of the daily bar like so:

                Code:
                 protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"Enter the description for your new custom Indicator here.";
                Name = "ExampleGetPriorDaySettlementClose";
                Calculate = Calculate.OnBarClose;
                IsOverlay = false;
                DisplayInDataBox = true;
                DrawOnPricePanel = true;
                DrawHorizontalGridLines = true;
                DrawVerticalGridLines = true;
                PaintPriceMarkers = true;
                ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive = true;
                }
                else if (State == State.Configure)
                {
                AddDataSeries(BarsPeriodType.Day, 1);
                }
                }
                
                protected override void OnBarUpdate()
                {
                if(CurrentBars[1] < 1)
                return;
                
                double mySettlementPrice = Closes[1][1];
                }
                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  I do not see the exact previous open, close, high and low values of previous Day candle.

                  Sometime I get values of high,open, low but not close value accurately.

                  so basically I am unable to get the exact information of all the values in C# strategy.

                  example, used below code for getting details of Axis Bank for 21/01/2021(on 22/01/2021 day using below code) values appeared as Low:673.6 High:690.8 Open:676.45 Close:689.5)
                  double previousDayClose = PriorDayOHLC().PriorClose[0];
                  double previousDayHigh = PriorDayOHLC().PriorHigh[0];
                  double previousDayOpen = PriorDayOHLC().PriorOpen[0];
                  double previousDayLow = PriorDayOHLC().PriorLow[0];

                  But actual Low:669.75 High:695 Open:680.75 & Close:675.85


                  I have also attached the trading platform candles which is not similar if you observe, so why do I see such difference?
                  Attached Files
                  Last edited by rajeshks1988; 01-23-2021, 02:46 PM.

                  Comment


                    #10
                    Hello rajeshks1988,

                    Thank you for your reply.

                    This is due to the daily bars being settlement adjusted whereas the PriorDayOHLC() uses intraday data, which means the Close price is not settlement adjusted and would be expected as I mentioned in my last post:

                    Originally posted by NinjaTrader_Kate View Post
                    Hello rajeshks1988,

                    Thank you for your reply.

                    Since the PriorDayOHLC calculates from intraday data, while daily bars use the settlement close, it would be expected that they would be different.

                    If you wish to get the prior day settlement close, you would need to add an additional 1 day series in your code, ensure you have at least 1 daily bar before calculating, and then reference the close price of the daily bar like so:

                    Code:
                     protected override void OnStateChange()
                    {
                    if (State == State.SetDefaults)
                    {
                    Description = @"Enter the description for your new custom Indicator here.";
                    Name = "ExampleGetPriorDaySettlementClose";
                    Calculate = Calculate.OnBarClose;
                    IsOverlay = false;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    DrawHorizontalGridLines = true;
                    DrawVerticalGridLines = true;
                    PaintPriceMarkers = true;
                    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive = true;
                    }
                    else if (State == State.Configure)
                    {
                    AddDataSeries(BarsPeriodType.Day, 1);
                    }
                    }
                    
                    protected override void OnBarUpdate()
                    {
                    if(CurrentBars[1] < 1)
                    return;
                    
                    double mySettlementPrice = Closes[1][1];
                    }
                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by pvincent, 06-23-2022, 12:53 PM
                    14 responses
                    238 views
                    0 likes
                    Last Post Nyman
                    by Nyman
                     
                    Started by TraderG23, 12-08-2023, 07:56 AM
                    9 responses
                    383 views
                    1 like
                    Last Post Gavini
                    by Gavini
                     
                    Started by oviejo, Today, 12:28 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post oviejo
                    by oviejo
                     
                    Started by pechtri, 06-22-2023, 02:31 AM
                    10 responses
                    125 views
                    0 likes
                    Last Post Leeroy_Jenkins  
                    Started by judysamnt7, 03-13-2023, 09:11 AM
                    4 responses
                    59 views
                    0 likes
                    Last Post DynamicTest  
                    Working...
                    X