Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

identify higher highs

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

    identify higher highs

    i've searched for this on here and followed the links.

    i want to draw divergence lines on a momentum indicator.

    if price makes a new high in a certain amount of bars, and momentum does not make a new high:

    i want to have a line drawn from the peak of the momentum at the same bar that price made its last high within the period to i suppose would be momentum[0] technically where the new high has been identified.

    that being said, i have tried to start at the easiest point i could and get the higher high of price and whenever price makes a new high within my 2 hour timeframe i want an arrow to plot above the high of that bar where the latest high was reached.

    this is kicking my butt. i really need help. perhaps something is off in my code? its a 21 period momentum im going to use. 1 or 3 minute chart.



    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1);
    return;
    Value[0] = CurrentBar == 0 ? 0 : Input[0] - Input[Math.Min(CurrentBar, Period)];



    Momentum Mom = Momentum(Period);
    double PreviousPriceHigh = double.MinValue;
    int PreviousHighBar= -1;

    int LookBackPeriod = 120;


    for (int i = 1; i < LookBackPeriod; i++)

    if (High[0]> PreviousPriceHigh)
    {
    PreviousPriceHigh = High[i];
    PreviousHighBar = i;
    Print("Bar " + i + " Price: " + High[i] + " Time: " + Time[0]);

    Draw.ArrowUp(this, "HigherHigh",true,PreviousHighBar,High[0],Brushes.White);

    }


    }

    any help at all would be so greatly appreciated.​

    #2
    Hello ccagle,

    Rather than using a loop you can just use the HighestBar method to find the highest bar in a period. That gives you a BarsAgo so that can also be used to know where in time that happened in addition to the price.

    Comment


      #3
      I figured out how to get this to work for my purposes of finding higher highs and higher lows. i did it and incorporated it into momentum levels at each high and each low. i will be adding this indicator i made to the ecosystem so look for "Momentum Divergence" if you want it. here is a snippet of how i got it to work.

      the key point to understand is that current bar and bars ago is a right to left orientation. current bar being 0 and 1 bars ago is 1 2 bars ago is 2 etc. but when you look at the bars in their entirety to find the bar index they go from left to right. earliest bar on the chart is 0. this is what i have discovered.

      NinjaTrader_Jesse have a look and let me know what you think of this implementation to find the higher highs and higher lows

      protected override void OnBarUpdate()
      {
      if(CurrentBar <= Period)
      {
      //if there are less than Period bars, exit method
      return;
      }

      if(CurrentBar == 0)
      {
      //If first bar, assign 0 to Value[0]
      Value[0] = 0;
      }
      else
      {
      //If not first bar, assign the value of momentum at close of that bar
      double smallestOfTwoNums = Input[Math.Min(CurrentBar, Period)]; //either going to return current bar or period if current bar is greater than period
      Value[0] = Input[0] - smallestOfTwoNums;

      // //Input: Primary historical data input
      }
      Momentum Mom = Momentum(Period);

      if(High[0] > valueOfHighest)
      {
      valueOfHighest = High[0];
      Draw.Line(this, $"HighBar {CurrentBar}", 0, Mom[0], -1, Mom[0], Brushes.Green);
      // Draw.TriangleUp(this, $"HighBar {CurrentBar}", true, 0, Mom[0], Brushes.Green);
      indexOfLastHighMarker = CurrentBar;
      }
      if(CurrentBar - indexOfLastHighMarker > Period)
      {
      valueOfHighest = High[0];
      Draw.Line(this, $"Reset High at bar {CurrentBar}", 0, Mom[0], -1, Mom[0], Brushes.White);
      // Draw.TriangleUp(this, $"Reset High at bar {CurrentBar}", true, 0, Mom[0], Brushes.Blue);
      indexOfLastHighMarker = CurrentBar;
      }
      if(Low[0] < valueOfLowest)
      {
      valueOfLowest = Low[0];
      Draw.Line(this, $"LowBar {CurrentBar}", 0, Mom[0], -1, Mom[0], Brushes.Red);
      // Draw.TriangleDown(this, $"LowBar {CurrentBar}", true, 0, Mom[0], Brushes.Red);
      indexOfLastLowMarker = CurrentBar;

      }
      if(CurrentBar - indexOfLastLowMarker > Period)
      {
      valueOfLowest = Low[0];
      Draw.Line(this, $"Reset Low at bar {CurrentBar}", 0, Mom[0], -1, Mom[0], Brushes.Orange);
      // Draw.TriangleDown(this, $"Reset Low at bar {CurrentBar}", true, 0, Mom[0], Brushes.Orange);
      indexOfLastLowMarker = CurrentBar;
      }
      }​

      Comment


        #4
        Hello ccagle,

        If that works for the purpose you wanted then you can test that out and use it, I can't provide any direct feedback if that would or would not be good for trading purposes.

        Comment


          #5
          No i wasnt looking for feedback on the strategy itself. just the method at which i find higher highs and higher lows. i read through the documentation for ages until i realized that the bar index starts at the first bar on the chart and goes left to right where the current bar/bars ago is read right to left from latest bar. so i wanted to know what you thought about using current bar with bar index and if thats how it should be or if this is a workaround i found that could be optimized. sorry for the nebulous nature of my initial response.

          Comment


            #6
            Hello ccagle,

            CurrentBar is the Index which is being processed right now, when OnBarUpdate is called that is the index of the bar being processed. Indexing starts at 0 (leftmost bar) and ends with the Count - 1 or 2 depending on the Calculate setting. You are free to use CurrentBar as a way to identify specific bars instead of using a number of bars ago. Either system works if you are targeting the correct bars in your equation/logic.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            617 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            358 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            561 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            566 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X