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

Getting the highs and lows of current session, RTH and AH

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

    Getting the highs and lows of current session, RTH and AH

    Hi,

    I'm attempting to acquire the high and low of the day and use those data points as a variable to take action from. I came across a post with a sample and this is working fine for the high, but is way off for the low. The low of the day right now is 3808 and it is showing 3657 so it's got to be going all the way back to Sunday open for that. The instrument I'm using is /MES.

    Code:
    //return high and low of RTH session
    if (regularTradingHours)
    {
    if (Bars.IsFirstBarOfSession)
    {
    Print("Calculating trading day for " + Time[0]);
    // use the current bar time to calculate the next session
    sessionIterator.GetNextSession(Time[0], true);
    
    // store the desired session information
    beginTime = sessionIterator.ActualSessionBegin;
    }
    
    var startBarsAgo = Bars.GetBar(beginTime);
    Print("startBarsAgo = " + startBarsAgo);
    double highestHigh = MAX(High, CurrentBar - startBarsAgo + 1)[0];
    
    // Now that we have the start and end bars ago values for the specified time range we can calculate the lowest low for this range
    var lowestLow = MIN(Low, CurrentBar - startBarsAgo + 1)[0];
    // Set the plot values
    HighestHigh[0] = highestHigh;
    LowestLow[0] = lowestLow;
    Draw.TextFixed(this, "highLowText", HighestHigh[0] + " High | " + LowestLow[0] + " Low", TextPosition.TopLeft);
    
    HighestHigh[0] = HighestHigh[1];
    LowestLow[0] = LowestLow[1];
    }
    So this kind of works, but something is off here and it doesn't work during AH.

    Hoping for some guidance or a working example as I'm having a difficult time figuring this one out.


    Thanks!

    #2
    Hello DogEars, thanks for your post.

    The CurrentDatOHL indicator will provide daily OHL for the bar series you give to it. The primary series of the script can be the ETH template and you can add an RTH data series using this AddDataSeries overload:
    AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)

    You can then set up two CurrentDayOHL indicators in the script. One will take the primary series and the other will take the secondary series e.g.
    CurrentDayOHL(BarsArray[0]);
    CurrentDayOHL(BarsArray[1]);

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I missed that one. I'll check it out and see how it goes.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by hazylizard, Today, 08:38 AM
      0 responses
      4 views
      0 likes
      Last Post hazylizard  
      Started by Max238, Today, 01:28 AM
      5 responses
      42 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by giulyko00, Yesterday, 12:03 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by habeebft, Today, 07:27 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChristopherS  
      Started by AveryFlynn, Today, 04:57 AM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X