I have been looking at the reference sample entitled Indicator: Calculating the highest high or lowest low for a specified time range (https://ninjatrader.com/support/foru...ad.php?p=44911). I need this functionality for both NT7 and NT8. I am running it within a strategy (no plotting required).
It seems the reference sample works, but it only covers a very small time period. I have tried to adapt it (fot NT7 initially) to cover much longer time periods (e.g. the past 12 months). I can easily calculate the required start/end DateTimes for the required periods. But I have encountered some strange interactions between the script and the Days2Load and BarsRequired settings and cannot get it to produce any meaningful results.
For example, even if I set Days to load in the Strategy Grid UI to 120 and Min. bars required there also to 5000 (say), and also Maximum bars look back being Infinite, I find that GetBar does not seem to find any bars (returns 0).
So, if my date range is start on 01-Jan-2018 and end on 14-Apr-2018 (a 103 day period), with 120 days loaded, BarsArray[0].Count is 25000 but GetBar returns zero.
The code is:
private int RangeOverTime(DateTime StartDT, DateTime EndDT, string hdr) { if (EndDT <= StartDT) // Start must be before end return -1 ; int startBarsAgo = GetBar(StartDT) ; // Number of bars ago for start time int endBarsAgo = GetBar(EndDT) ; // Number of bars ago for end time double highestHigh = MAX(High,startBarsAgo-endBarsAgo+1)[endBarsAgo] ; double lowestLow = MIN(Low,startBarsAgo-endBarsAgo+1)[endBarsAgo] ; int rot = (int)Math.Round((highestHigh-lowestLow)*(Instrument.FullName.Contains("JPY") ? 100.0 : 10000.0)) ; Print(hdr+": "+endBarsAgo.ToString().PadLeft(4)+" to "+startBarsAgo.ToString().PadLeft(4)+ " Range from "+StartDT.ToString("ddd dd-MMM-yy")+" to "+EndDT.ToString("ddd dd-MMM-yy")+" is "+rot) ; return rot ; }
[FONT="Courier New"]Mon : 0 to 0 Range from Mon 09-Apr-18 to Tue 10-Apr-18 is 3 Tue : 0 to 0 Range from Tue 10-Apr-18 to Wed 11-Apr-18 is 3 Wed : 0 to 0 Range from Wed 11-Apr-18 to Thu 12-Apr-18 is 3 Thu : 0 to 0 Range from Thu 12-Apr-18 to Fri 13-Apr-18 is 3 Fri : 0 to 0 Range from Fri 13-Apr-18 to Sat 14-Apr-18 is 3 WTD : 0 to 0 Range from Mon 09-Apr-18 to Sat 14-Apr-18 is 3 LsWk: 0 to 0 Range from Mon 02-Apr-18 to Fri 06-Apr-18 is 3 MTD : 0 to 0 Range from Sun 01-Apr-18 to Sat 14-Apr-18 is 3 LsMn: 0 to 0 Range from Thu 01-Mar-18 to Sat 31-Mar-18 is 3 YTD : 0 to 3872 Range from Mon 01-Jan-18 to Sat 14-Apr-18 is 392[/FONT]
[FONT="Courier New"]Mon : 0 to 0 Range from Mon 09-Apr-18 to Tue 10-Apr-18 is 4 Tue : 0 to 0 Range from Tue 10-Apr-18 to Wed 11-Apr-18 is 4 Wed : 0 to 0 Range from Wed 11-Apr-18 to Thu 12-Apr-18 is 4 Thu : 0 to 0 Range from Thu 12-Apr-18 to Fri 13-Apr-18 is 4 Fri : 0 to 0 Range from Fri 13-Apr-18 to Sat 14-Apr-18 is 4 WTD : 0 to 0 Range from Mon 09-Apr-18 to Sat 14-Apr-18 is 4 LsWk: 0 to 0 Range from Mon 02-Apr-18 to Fri 06-Apr-18 is 4 MTD : 0 to 0 Range from Sun 01-Apr-18 to Sat 14-Apr-18 is 4 LsMn: 0 to 0 Range from Thu 01-Mar-18 to Sat 31-Mar-18 is 4 YTD : 0 to 0 Range from Mon 01-Jan-18 to Sat 14-Apr-18 is 4[/FONT]
[FONT="Courier New"]Mon : 0 to 0 Range from Mon 09-Apr-18 to Tue 10-Apr-18 is 7 Tue : 0 to 0 Range from Tue 10-Apr-18 to Wed 11-Apr-18 is 7 Wed : 0 to 0 Range from Wed 11-Apr-18 to Thu 12-Apr-18 is 7 Thu : 0 to 0 Range from Thu 12-Apr-18 to Fri 13-Apr-18 is 7 Fri : 0 to 0 Range from Fri 13-Apr-18 to Sat 14-Apr-18 is 7 WTD : 0 to 0 Range from Mon 09-Apr-18 to Sat 14-Apr-18 is 7 LsWk: 0 to 0 Range from Mon 02-Apr-18 to Fri 06-Apr-18 is 7 MTD : 0 to 0 Range from Sun 01-Apr-18 to Sat 14-Apr-18 is 7 LsMn: 0 to 0 Range from Thu 01-Mar-18 to Sat 31-Mar-18 is 7 YTD : 0 to 0 Range from Mon 01-Jan-18 to Sat 14-Apr-18 is 7[/FONT]
Thanks.
Comment