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 cmoran13, 04-16-2026, 01:02 PM
        0 responses
        46 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        28 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        163 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X