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

Shift of the maximum value over a specific number of bars

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

    Shift of the maximum value over a specific number of bars

    Hello!
    I am sorry to bring a Metatrader’s term to this forum. I am struggling since one week already with this topic, but I am failing to solve the problem. I hope you could help me understanding this term.
    I have this function from Metatrader4:
    HTML Code:
    for (int i = 0; i <= 10; i++)
    {
    double a = iHighest(NULL, 0, MODE_LOW, Period, i);
    }
    I instantly thought this was equal to higher low in Ninjatrader8, because of iHighest and MODE_LOW. I then set the Period to 1, considering a single bar. “a” should be the low of the corresponding bar. But if I have
    HTML Code:
    double b = iHighest(NULL, 0, MODE_HIGH, Period, i);
    , according to my understanding, “b” should be the higher high. Considering a single bar, this should be the high of the bar. So that I have used the function MAX(High, 1) - MAX(Low, 1). With the operation b - a, the result will always be positive, regardless if the bar is bullish or bearish. This is not what I want to have.

    In Google, I found the definition of iHighest as followed: Returns the shift of the maximum value over a specific number of bars depending on type.
    But I want there my specific number of bars to be 1.
    In Ninjatrader documentation, I also found this:
    int highestBarsAgo = HighestBar(High, Bars.BarsSinceNewTradingDay);
    double highestPrice = High[highestBarsAgo];
    With this, I would already be out of range in my loop.
    Could someone advise me what could the the equivalent of double a = iHighest(NULL, 0, MODE_LOW, Period, i) in Ninjatrader?
    Any help would be very appreciate.

    Thanks!

    #2
    Hi Stan, thanks for posting.

    To find the highest high price over a certain period, use the MAX method. This example gives the highest high price over 20 bars:

    double value = MAX(High, 20)[0];

    The reason you would use this kind of method is to evaluate what the highest high price is over x amount of bars. If you only need to evaluate one bar, the prices can be accessed in the OHLC price arrays. The lowest period you can pass to MAX is 1 e.g. MAX(High, 1)[0] will return either the last bar or the most recent bar high price. This can also be written Math.Max(High[1], High[0]);

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Many thanks ChrisL!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by JonesJoker, 04-22-2024, 12:23 PM
      8 responses
      41 views
      0 likes
      Last Post JonesJoker  
      Started by timko, Today, 06:45 AM
      0 responses
      3 views
      0 likes
      Last Post timko
      by timko
       
      Started by Waxavi, 04-19-2024, 02:10 AM
      2 responses
      37 views
      0 likes
      Last Post poeds
      by poeds
       
      Started by chbruno, Yesterday, 04:10 PM
      1 response
      44 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Max238, Today, 01:28 AM
      1 response
      25 views
      0 likes
      Last Post CactusMan  
      Working...
      X