Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars.GetTime() with LowestBar() and/or Highest() problems

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

    Bars.GetTime() with LowestBar() and/or Highest() problems

    Hi All,
    I am relatively new to NinjaTrader. I have been working with and writing NinjaScripts. I have a problem while using LowestBar() and HighestBar() with Bars.GetTime().

    While it seems the values returned by HighestBar() and LowestBar() are correct the DateTime and highestbarsago & lowestbarsago will print incorrect values in Draw.TextFixed. The Print() will print the correct values but

    Shouldn't this work?

    highestbarsago = HighestBar(High, (CurrentBars[0] < LookBackMax ? CurrentBars[0] : LookBackMax)); // Limit HighestBar Lookback to input value
    lowestbarsago = LowestBar(Low, (CurrentBars[0] < LookBackMax ? CurrentBars[0] : LookBackMax)); // Limit LowestBar Lookback to input value
    rescaleoldmin = Low[lowestbarsago];
    rescaleoldmax = High[highestbarsago];
    rescaleoldrange = rescaleoldmax - rescaleoldmin;

    dtmax = Bars.GetTime(highestbarsago);
    dtmin = Bars.GetTime(lowestbarsago);
    string str = "\n" + dtmax + " Bars: " + highestbarsago + " High: " + rescaleoldmax + "\n" + dtmin + " Bars: " + lowestbarsago + " Low: " + rescaleoldmin;
    Draw.TextFixed(this, ProcDescript + "FixedTextBottomLeft", str, TextPosition.BottomLeft);

    Print(ProcDescript + " CurrentBars[0]: " + CurrentBars[0] + " " + Bars.GetTime(CurrentBars[0]) + " highestbarsago: " + highestbarsago + " High: " + High[highestbarsago] +
    " lowestbarsago: " + lowestbarsago + " Low: " + Low[lowestbarsago] + " rescaleoldmin: " + rescaleoldmin + " rescaleoldmax: " + rescaleoldmax +
    " Reset Range Scale >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >> >>>>>>>>>>>>");

    Importantly it does yeild the correct vales for highestbarsago and lowestbarsago and rescaleoldmin & rscaleoldmax(correct High and Low values are attained). Problem is with Bars.GetTime(); It is not returning the correct Date Time for the barsago values. Is there something I may have missed? Test code attached.
    Attached Files

    #2
    Hello MartinT,

    Your assumption is correct however the GetTime method takes an Index and not a BarsAgo. To use GetTime you would have to use CurrentBars[0] - lowestbarsago to get the index. Alternatively you can just use the time series:

    Code:
    dtmax =Time[highestbarsago];
    dtmin = Time[lowestbarsago];


    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse,

      Thanks a Heap! That will help for sure.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      585 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      340 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X