Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieve 2 rth session back values

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

    Retrieve 2 rth session back values

    Hi,
    I need to do the logic below:

    I need to calculate the gap between RTH sessions (chart with 30 minutes bar and only RTH session) and i use the code below with the priorDayOHLC:
    Code:
    //             If the current date is not the same date as the current bar then its a new session
                if (currentDate != sessionIterator.GetTradingDay(Time[0]) || currentOpen == 0)
                {
    
                    // The current day OHLC values are now the prior days value so set
                    // them to their respect indicator series for plotting
                    priorDayClose    = currentClose;
                    priorDayHigh    = currentHigh;
                    priorDayLow        = currentLow;
    
                    priorDayClose = PriorDayOHLC().PriorClose[0];
                    priorDayHigh = PriorDayOHLC().PriorHigh[0];
                    priorDayLow = PriorDayOHLC().PriorLow[0];
    
                    // Initilize the current day settings to the new days data
                    currentOpen     =     Open[0];
                    currentHigh     =    High[0];
                    currentLow        =    Low[0];
                    currentClose    =    Close[0];
    
                    currentDate = sessionIterator.GetTradingDay(Time[0]);
                }
                else // The current day is the same day
                {
    
                    priorDayClose = PriorDayOHLC().PriorClose[0];
                    priorDayHigh = PriorDayOHLC().PriorHigh[0];
                    priorDayLow = PriorDayOHLC().PriorLow[0];
    
                }
            ​
    This code works fine but i need to skip the partial holidays rth session like yesterday (memorial day). So, in the current RTH, when i calculate the GAP, but i know that yesterday isn't a full session, i need to retrieve the OPEN, CLOSE, HIGH AND LOW values of friday (or the last full session). How can i do that?

    Please, can you help me providing the code?

    Thanks

    #2
    Hello Davide999,

    To calculate the gap between two times you can subtract one time from another to find a difference. THat difference could be added to the first time to see how long of a gap is between the two. . There is not a specifici property for the difference in time you are asking for, you would need to use logic to store that first time and then subtract it from another time to find a difference. The session iterator would give you the times for the defined session, if there is a holiday it would provide the holiday times as the start/end times as part of the session information.



    Comment


      #3
      Hello,
      Ok; another question: I added a new dataseries in my indicator like below:
      Code:
          protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"GAP";
                      Name                                        = "GAP";
                      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.Minute, 1);
                  }
      
                  else if (State == State.DataLoaded)
                  {
                      sessionIterator = new SessionIterator(Bars);
                  }
                  }    
              ​
      If i need the same timeframe from another indicator, i need to write the same command in the second indicator ("AddDataSeries(BarsPeriodType.Minute, 1);") or i can access to this ? How?
      I ask that because if i add multiple data series in all indicator i can degrade the performance.
      So, can I access to the 1 minute data series of indicator GAP from another indicator without add that to this one? How?

      Thanks

      Comment


        #4
        Hello Davide999,

        If you need additional data in your indicator you need to use AddDataSeries to do that. Each indicator that uses additional data needs its own AddDataSeries statements in its own code. If you reference another indicator that uses additional data you will need to add the same data to the parent indicator as well.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        636 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X