Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mirror Range Bars

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

    Mirror Range Bars

    Hi, i'm trying to develop the same mirror bars of this link: https://ninjatraderecosystem.com/use...ad/mirrorbars/ but in range bar type.
    I tried to follow the same logic of the link above but with no success, what i'm missing?
    Thanks in advance for the help
    Attached Files

    #2
    Hello CIFil,

    Thank you for your post.

    What I'd do is compare the original Mirror Bars to a time based bar type to see which conditions get reversed. I think you may be running into trouble with this section not having reversed logic to calculate negative prices:

    if (close.ApproxCompare(barLow + rangeValue) > 0)
    {
    double newClose = barLow + rangeValue; // Every bar closes either with high or low
    if (newClose.ApproxCompare(barClose) < 0)
    UpdateBar(bars, newClose, barLow, newClose, time, 0);

    // If there's still a gap, fill with phantom bars
    double newBarOpen = newClose + tickSize;
    while (close.ApproxCompare(newClose) > 0)
    {
    newClose = Math.Min(close, newBarOpen + rangeValue);
    AddBar(bars, newBarOpen, newClose, newBarOpen, newClose, time, close.ApproxCompare(newClose) > 0 ? 0 : volume);
    newBarOpen = newClose + tickSize;
    }
    }
    else if ((barHigh - rangeValue).ApproxCompare(close) > 0)
    {
    double newClose = barHigh - rangeValue; // Every bar closes either with high or low
    if (barClose.ApproxCompare(newClose) > 0)
    UpdateBar(bars, barHigh, newClose, newClose, time, 0);

    // if there's still a gap, fill with phantom bars
    double newBarOpen = newClose - tickSize;
    while (newClose.ApproxCompare(close) > 0)
    {
    newClose = Math.Max(close, newBarOpen - rangeValue);
    AddBar(bars, newBarOpen, newBarOpen, newClose, newClose, time, newClose.ApproxCompare(close) > 0 ? 0 : volume);
    newBarOpen = newClose - tickSize;
    }
    }

    I'd try adding some prints in there to print what is actually being calculated for those "new" values to make sure they make sense with the calculated open and close prices of the bars.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello CIFil,

      Thank you for your post.

      What I'd do is compare the original Mirror Bars to a time based bar type to see which conditions get reversed. I think you may be running into trouble with this section not having reversed logic to calculate negative prices:

      if (close.ApproxCompare(barLow + rangeValue) > 0)
      {
      double newClose = barLow + rangeValue; // Every bar closes either with high or low
      if (newClose.ApproxCompare(barClose) < 0)
      UpdateBar(bars, newClose, barLow, newClose, time, 0);

      // If there's still a gap, fill with phantom bars
      double newBarOpen = newClose + tickSize;
      while (close.ApproxCompare(newClose) > 0)
      {
      newClose = Math.Min(close, newBarOpen + rangeValue);
      AddBar(bars, newBarOpen, newClose, newBarOpen, newClose, time, close.ApproxCompare(newClose) > 0 ? 0 : volume);
      newBarOpen = newClose + tickSize;
      }
      }
      else if ((barHigh - rangeValue).ApproxCompare(close) > 0)
      {
      double newClose = barHigh - rangeValue; // Every bar closes either with high or low
      if (barClose.ApproxCompare(newClose) > 0)
      UpdateBar(bars, barHigh, newClose, newClose, time, 0);

      // if there's still a gap, fill with phantom bars
      double newBarOpen = newClose - tickSize;
      while (newClose.ApproxCompare(close) > 0)
      {
      newClose = Math.Max(close, newBarOpen - rangeValue);
      AddBar(bars, newBarOpen, newBarOpen, newClose, newClose, time, newClose.ApproxCompare(close) > 0 ? 0 : volume);
      newBarOpen = newClose - tickSize;
      }
      }

      I'd try adding some prints in there to print what is actually being calculated for those "new" values to make sure they make sense with the calculated open and close prices of the bars.

      Please let us know if we may be of further assistance to you.
      Hi Kate, thanks for the answer but i can't understand the ApproxCompare method, could you please explain a real life/ practice example that can help to understand it?
      (I've already read the documentation : https://ninjatrader.com/it/support/h...roxcompare.htm and i've not understand anyway)
      Sorry for the misunderstanding but i'm quite new in programming and thanks in advance for answer

      Comment


        #4
        Hello ClFil,

        Thank you for your reply.

        It has to do with issues that can arise with floating-point arithmetic. This page of our help guide may be more helpful in understanding what ApproxCompare() would be used for:



        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        607 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        353 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
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X