Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breakout of previous High/Low

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

    Breakout of previous High/Low

    I am trying to write a strategy that includes a breakout of a previous High/Low of x bars ago. I am detecting the correct previous bar with the highest high or lowest low but my problem is detecting when the previous High/Low gets broken. I have it looking for a cross above/below but it doesn't work because when a hew high/low is hit, the previous high/low gets reset. I'm sure I'm missing something simple to get this to work. I attached the current code I'm using.....
    Attached Files

    #2
    Hello mlarocco,

    I believe in this case you would need to use a class level variable and then find the highest and lowest values after you check the cross condition. That would let you delay reading the new highest/lowest values by 1 bar. That would look like the following:

    Code:
    private int highestBarsAgo;
    private int lowestBarsAgo;
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 60)
    return;
    
    //evaluate high price from highest bars ago value
    double HighestPrice = High[highestBarsAgo];
    double LowestPrice = Low[lowestBarsAgo];
    
    Print ("Highest Bar is " + highestBarsAgo);
    Print("Highest price is " + HighestPrice);
    Print("Current High is " + High[0]);
    
    // Set 1
    if (CrossAbove(High, HighestPrice, 1))
    {
    BarBrush = Brushes.Blue;
    }
    
    // Set 2
    if (CrossBelow(Low, LowestPrice, 1))
    {
    BarBrush = Brushes.Yellow;
    }
    
    highestBarsAgo = HighestBar(High, 60);
    lowestBarsAgo = LowestBar(Low, 60);
    
    }

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello mlarocco,

      I believe in this case you would need to use a class level variable and then find the highest and lowest values after you check the cross condition. That would let you delay reading the new highest/lowest values by 1 bar. That would look like the following:

      Code:
      private int highestBarsAgo;
      private int lowestBarsAgo;
      
      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;
      
      if (CurrentBars[0] < 60)
      return;
      
      //evaluate high price from highest bars ago value
      double HighestPrice = High[highestBarsAgo];
      double LowestPrice = Low[lowestBarsAgo];
      
      Print ("Highest Bar is " + highestBarsAgo);
      Print("Highest price is " + HighestPrice);
      Print("Current High is " + High[0]);
      
      // Set 1
      if (CrossAbove(High, HighestPrice, 1))
      {
      BarBrush = Brushes.Blue;
      }
      
      // Set 2
      if (CrossBelow(Low, LowestPrice, 1))
      {
      BarBrush = Brushes.Yellow;
      }
      
      highestBarsAgo = HighestBar(High, 60);
      lowestBarsAgo = LowestBar(Low, 60);
      
      }
      Thanks, I will give it a try

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      43 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X