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 MarionCron, Today, 11:43 PM
      0 responses
      1 view
      0 likes
      Last Post MarionCron  
      Started by kaywai, Today, 11:20 PM
      0 responses
      1 view
      0 likes
      Last Post kaywai
      by kaywai
       
      Started by JodieThur, Today, 11:11 PM
      0 responses
      2 views
      0 likes
      Last Post JodieThur  
      Started by cryfgg, Today, 06:01 PM
      0 responses
      18 views
      0 likes
      Last Post cryfgg
      by cryfgg
       
      Started by Tremblinghandtrader, Today, 04:56 PM
      0 responses
      33 views
      0 likes
      Last Post Tremblinghandtrader  
      Working...
      X