Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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, 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).
        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 Waxavi, Today, 02:00 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by alifarahani, Today, 09:40 AM
          5 responses
          23 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Kaledus, Today, 01:29 PM
          4 responses
          12 views
          0 likes
          Last Post Kaledus
          by Kaledus
           
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          16 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by PhillT, Today, 02:16 PM
          2 responses
          7 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Working...
          X