• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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!
    Paul H.NinjaTrader Customer Service

    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, 01: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).
        Paul H.NinjaTrader Customer Service

        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 ksarin, Today, 12:39 PM
          3 responses
          9 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by ttodua, Today, 12:03 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by tomtr27, Today, 11:35 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Uregon, Today, 07:30 AM
          2 responses
          9 views
          0 likes
          Last Post bltdavid  
          Started by Induna, 02-20-2020, 05:38 AM
          4 responses
          26 views
          0 likes
          Last Post NinjaTrader_Kate  
          Working...
          X