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

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

    Comment


      #3
      Hi Jesse,

      Thanks a Heap! That will help for sure.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by giulyko00, Yesterday, 12:03 PM
      2 responses
      10 views
      0 likes
      Last Post giulyko00  
      Started by r68cervera, Today, 05:29 AM
      0 responses
      3 views
      0 likes
      Last Post r68cervera  
      Started by geddyisodin, Today, 05:20 AM
      0 responses
      6 views
      0 likes
      Last Post geddyisodin  
      Started by JonesJoker, 04-22-2024, 12:23 PM
      6 responses
      36 views
      0 likes
      Last Post JonesJoker  
      Started by GussJ, 03-04-2020, 03:11 PM
      12 responses
      3,241 views
      0 likes
      Last Post Leafcutter  
      Working...
      X