Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

mapping price to bounded indicator

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

    mapping price to bounded indicator

    I would like to show a ratio between price and a particular bounded indicator such as the RSI but I'm having trouble working out and applying the proper algorithm to map unbounded price to bounded RSI. Unfortunately there does not appear to be a mapping function in C#.

    The algo i found online is as follows:

    OldRange = (OldMax - OldMin)
    NewRange = (NewMax - NewMin)
    NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin

    Assuming I can use this, I'm having difficulty knowing what numbers
    to put in place of the variables.

    would OldRange = Close[0] - Close[1] ?
    would NewRange = 100 - 0 ? // or simply 100
    what would be the value for OldValue ? //would it be Close[0] ?

    Based on my assumptions NT code would be as follows

    Code:
    //-----in variables------------------
                private double oldRange;
                private double newRange = 100;
                private double newValue;    
        
    // ----- in OnBarUpdate---------------------    
                double oldRange = Close[0] - Close[1];
                newValue = (((Close[0] - Close[1]) * newRange) / oldRange) + 0;
    does this seem right or does anyone know a better way?

    My ultimate goal is to examine the ratio between price and RSI bar by bar to detect "mini-divergences" to study and evaluate their usefulness for predicting the next bars direction.

    Thanks in advance for any help.

    #2
    Hello ShruggedAtlas,

    Thanks for your post.

    I do not have any information that I can contribute to your thread. Support forum members who can help are always welcome to post!

    Comment


      #3
      Perhaps you could help me with the following problem then. I am getting the dreaded Value outside of valid range error which I believe is because of a divide by zero instance.

      My code is as follows:

      Code:
              protected override void OnBarUpdate()
              {
                  if (CurrentBar < BarsRequired)
                      return;
                  
                  double r = CUMRSI(5,3)[0] - CUMRSI(5,3)[1];                    
                  double oldRange = Close[0] - Close[1];
                  
                  if (r == 0)
                  {
                      newValue = (((Close[0] - Close[1]) * newRange) / oldRange) + 0;
                      Ratio.Set(newValue / .01);                
                  }
                  else
                  {
                      newValue = (((Close[0] - Close[1]) * newRange) / oldRange) + 0;
                      Ratio.Set(newValue / r);
                  }            
              }
      I have attempted to check if r is zero to prevent the issue but it's still not working. if I just arbitrarily pick a number greater than zero for r then it plots correctly which is why I believe the issue is a divide by zero problem.

      Perhaps someone could give guidance on how to avoid this issue?

      Also, would this topic be better placed if it were in the indicator development section?
      Last edited by ShruggedAtlas; 07-28-2015, 02:01 PM.

      Comment


        #4
        Hello ShruggedAtlas,

        Thanks for your post.

        I think your thread is okay in this location.

        My recommendation would be to go through the exercise of using print statements to see what the values are prior to the error. If you haven't reviewed this before it may be of some assistance, along with the links at the end of it: http://ninjatrader.com/support/forum...ead.php?t=3418

        You might also use a try-catch block. http://www.dotnetperls.com/catch (I tried to get an MSDN example but their website is not responding).

        Comment


          #5
          Originally posted by ShruggedAtlas View Post
          Perhaps you could help me with the following problem then. I am getting the dreaded Value outside of valid range error which I believe is because of a divide by zero instance.

          My code is as follows:

          Code:
                  protected override void OnBarUpdate()
                  {
                      if (CurrentBar < BarsRequired)
                          return;
                      
                      double r = CUMRSI(5,3)[0] - CUMRSI(5,3)[1];                    
                      double oldRange = Close[0] - Close[1];
                      
                      if (r == 0)
                      {
                          newValue = (((Close[0] - Close[1]) * newRange) / oldRange) + 0;
                          Ratio.Set(newValue / .01);                
                      }
                      else
                      {
                          newValue = (((Close[0] - Close[1]) * newRange) / oldRange) + 0;
                          Ratio.Set(newValue / r);
                      }            
                  }
          I have attempted to check if r is zero to prevent the issue but it's still not working. if I just arbitrarily pick a number greater than zero for r then it plots correctly which is why I believe the issue is a divide by zero problem.

          Perhaps someone could give guidance on how to avoid this issue?

          Also, would this topic be better placed if it were in the indicator development section?
          That is because your zero-check is on the wrong variable. You should be checking the divisor in your divisions. i.e., oldRange

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          572 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          331 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          549 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          550 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X