Announcement

Collapse
No announcement yet.

Comparing Values Against a Range

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Comparing Values Against a Range

    What is the best way to compare values against a range? Note that I don't yet have a good grasp of arrays or ref.

    example 1: NR7

    How can I determine if a bar has the lowest range of the past 7 bars?

    example 2: Inside Day Variation

    How can I determine if a bar (the range contained within the high and the low) contains (has a higher high and a lower low than) the next x bars that follow?

    Thanks for any assistance.

    Mark

  • #2
    Hello underdog430,

    To learn more about arrays, click here. To learn more about ref(), click here.

    If I interpreted your post correctly, the code below will show you how to get your results.

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
    }

    function 
    main() {
        var 
    nLength 7;
        var 
    curHigh high()
        var 
    curLow low()
        if (
    curHigh == null || curLow == null)
            return;

        
        
    //  1. Determines if current bar's range is the lowest of last nLength bars.
        
    var pastHighs high(0, -nLength);
        if (
    pastHighs == null)
            return;
        var 
    pastLows low(0, -nLength);
        if (
    pastLows == null)
            return;
            
        var 
    curRange = (curHigh curLow);
        
        var 
    isLowest true;
        for (
    0nLength; ++i) {
            if ((
    pastHighs[i] - pastLows[i]) < curRange) {
                
    isLowest false;
                
    nLength
            
    }
        }
        if (
    isLowest == true) {
            
    // Open the formula output window to view these results.
            
    debugPrintln("Bar index " getCurrentBarIndex() + " has a lower range than the last " nLength " bars.");
        }

        
    //  2.  Determines if current bar's range has a higher high and lower low than the next nLength bars.
        //      Note:  This can only return valid results on historical data as the formula iterates through 
        //      your chart from the oldest bar to the newest.
        
    var futureHighs high(0nLength);
        if (
    futureHighs == null)
            return;
        var 
    futureLows low(0nLength);
        if (
    futureLows == null)
            return;
        
        var 
    HH true;
        var 
    LL true;
        for (
    0nLength; ++i) {
            if (
    futureHighs[i] > curHigh) {
                
    HH false;
                
    nLength;
            }
            if (
    futureLows[i] < curLow) {
                
    LL false;
                
    nLength;
            }
        }
        if (
    HH == true && LL == true) {
            
    // Open the formula output window to view these results.
            
    debugPrintln("Bar index " getCurrentBarIndex() + " has a higher high and lower low than the next " nLength " bars.");
        }
        
        return;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Help - if needed...

      Mark,

      I've coded systems that look for similar types of things (pivot points). The code is similar to what Jason has shown you. I have posted an example for you to review. Changing the "if" conditions will allow you to ID your conditions.

      PHP Code:
              var i;
              var 
      nLastLSB 0;
              var 
      nLastHSB 0;
              var 
      nLSBSet 0;
              var 
      nHSBSet 0;

              for(
      0>= -15i--) {
                if ( ((
      nHSBSet == 0) && (high(i) < high(i-1)) && (high(i-2) < high(i-1))) || ((nHSBSet == 0) && (high(i) == high(i-1)) && (high(i-2) < high(i-1)) ) ) {
                    
      nLastHSB high(i-1);
                    
      nHSBSet 1;
                }
                if ( ((
      nLSBSet == 0) && (low(i) > low(i-1)) && (low(i-2) > low(i-1))) || ((nLSBSet == 0) && (low(i) == low(i-1)) && (low(i-2) > low(i-1)) ) ) {
                    
      nLastLSB low(i-1);
                    
      nLSBSet 1;
                }
              } 
      // END OF FOR LOOP 
      This code looks back 15 bars for a defined pivot point and will return the last occurance of both a HIGH and LOW pivit point.

      To convert the code to look for the lowest price range for 15 bars, it might look like this....

      PHP Code:
               // look for lowest range over 15 bars
              
      var i;
              var 
      nlastrange 999999.99;
              var 
      nLastsmallrangebar 0;

              for(
      0>= -15i--) {
                if ( ((
      high(i-1)-low(i-1)) < (high(i)-low(i))) && ((high(i-1)-low(i-1)) < nlastrange)  ) {
                    
      nLastsmallrangebar i;
                    
      nlastrange = (high(i-1)-low(i-1));
                }
              } 
      // END OF FOR LOOP 
      This code will return the bar that has the smallest range and the size of that range.

      Hope this helps..

      Brad
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Thanks for your comments. I think I need more help with "for". I can kind of see how it creates a loop checking old values but I'm still not clear on what it does then. For example, how would you set it to check the last 5 highs and make the highest one the vPivot?

        Once I get a better understanding I'm interested in the Rectangle Trading System (Acme R) from Conway and Behle's "Professional Stock Trading". Conway has encouraged people to post the code for his systems on the TradeStation boards (it is provided in the book) so I would be surprised if he objected.

        Basically, if the range from the last 4 bars divided by the range for the 12 bars before that <= 0.3 and the range for the last 4 bars <= 30 period ATR, then you buy the next bar at or above the 4 bar high (plus an amount you decide on) or sell the next bar at or below the 4 bar low (minus an amount you decide on). Exits are based on profit targets and stop losses.

        Comment


        • #5
          Hello Mark,

          Here is an example of the for loop you need for finding vPivot. It will look at the five bars prior to the current bar. If you want to look at the five most recent bars including the current bar, change 1 and 6 to 0 and 5.

          PHP Code:
          var vPivot 0;
          for(
          16; ++i) {
               
          vPivot Math.max(vPivothigh(-i));

          The way to read this for loop goes something like this:
          "(i = 1;"
          i will start at 1.

          "i < 6;"
          If i is less than 6 (returns true/false), compute the code in the loop.

          "++i)"
          Then increment i by +1 and check the true/false condition for the loop again.

          Once i = 6 the loop ends. Hope this helps.
          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            OK, I'm trying to find the highest high and the lowest low for the past nRectangle number of bars on a moving basis. The problem with the code below is that it doesn't really operate on a moving basis (it doesn't limit itself to the past nRectangle number of bars). For example, if the low of the day is set at 9:30 and the bar lows rise steadily after that, vRectangleL doesn't rise with them. Do I need to modify the code or take a new approach?

            Thanks.

            PHP Code:
            // Highest High and Lowest Low for Rectangle

            for(i=1nRectangle; ++i) {
                
            vRectangleH Math.max(vRectangleHhigh(-i));
                
            vRectangleL Math.min(vRectangleLlow(-i));

            Comment


            • #7
              High and Low range...

              Underdog,

              O don't really understand you statement, but lets say that a low was set at 9:30, what is it that you want to try to accomplish?? Are you trying to identify the lowest low and highest high of n bars?? If so, then you would want to set the initial values to extreme levels to start with...like...

              PHP Code:
              // Highest High and Lowest Low for Rectangle
              vRectangleH = -99999;
              vRectangleL 99999;

              for(
              i=1nRectangle; ++i) {
                  
              vRectangleH Math.max(vRectangleHhigh(-i));
                  
              vRectangleL Math.min(vRectangleLlow(-i));

              This code should return the highest high and lowest low of nRectangle bars.

              Lets say you wanted to fing the highest high and lowest low of n bars from where a pattern was found. Then you would have to record the bar number and count the number of new bars after the pattern was formed to determine how far back to set nRectangle. Use my "time-stamping" functions for this as a solution.

              If you can describe what you are trying to accomplish in detail, then I will be able to provide more detailed assistance...

              Brad
              Brad Matheny
              eSignal Solution Provider since 2000

              Comment


              • #8
                Rectangle...

                Underdog,

                The rectangle is not reactive to the change in variable price.

                After you identify the new high and low, you would need to redraw the rectangle. This would cause the rectangle to redraw with the new prive variables. You would have to force the change in the rectangle size by re-issuing the DRAW functions to draw the rectangle.

                I hopd this is clear.

                To simplify things.... just changing the variable values will not cause the rectangle to redraw with the new shapes. The graphics have to be redrawn with the new values.

                Brad
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment


                • #9
                  Hi Underdog. If I understand you correctly, what you need to do after each bar is completed is to reinitialize your high and low variables to the open of the bar under construction.

                  Good Luck, Bob

                  Comment


                  • #10
                    OOPS, meant to say reinitialize to the open of the first bar of the rectangle.

                    Comment


                    • #11
                      OK, just got to reinitialize the variables. I've been tripped up by that kind of thing before. Thanks all.

                      Mark

                      Comment

                      Working...
                      X