Conversion of MetaTrader4 to NinjaTrader

410 views Asked by At

I am trying to write an indicator originally from MT4 into NT7. I have the following calculations in MT4:

     dayi = iBarShift(Symbol(), myPeriod, Time[i], false);
     Q = (iHigh(Symbol(), myPeriod,dayi+1) - iLow(Symbol(),myPeriod,dayi+1));

     L = iLow(NULL,myPeriod,dayi+1);
     H = iHigh(NULL,myPeriod,dayi+1);
     O = iOpen(NULL,myPeriod,dayi+1);  
     C = iClose(NULL,myPeriod,dayi+1);

myperiod is a variable where I place the period in minutes (1440 = 1day). What are the equivalent functions in NT7 to iBarShift, iHigh and so on?

Thanks in advance

1

There are 1 answers

0
Sugah Shane On

For NinjaTrader:

iLow = Low or Lows for multi-time frame
iHigh = High or Highs
iOpen = Open or Opens
iClose = Close or Closes

So an example would be

double low = Low[0]; // Gets the low of the bar at index 0, or the last fully formed bar (If CalculateOnBarClose = true)

In order to make sure you are working on the 1440 minute time frame, you will need to add the following in the Initialize() method:

Add(PeriodType.Minute, 1440);

If there are no Add statements prior to this one, it will place it at index 1 (O being the chart default index) in a 2 dimensional array. So to access the low of the 1440 minute bar at index 0 would be:

double low = Lows[1][0];

For iBarShift look at

int barIndex = Bars.GetBar(time);

which will give you the index of the bar with the matching time. If you need to use this function on the 1440 bars (or other ones), use the BarsArray property to access the correct Bar object and then use the GetBar method on it. For example:

int barIndex = BarsArray[1].GetBar(time);

Hope that helps.