Announcement

Collapse
No announcement yet.

Multiple S/R Lines till Price Penetrates

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

  • Multiple S/R Lines till Price Penetrates

    I'm struggling with some logic and would appreciate some input / suggestions how how best to tackle an EFS enhancement I'm working on.

    I currently have a EFS script that calculates some specific price targets based on recent price action. I have these levels marked on the chart with a drawRelative function.

    What I am trying to achieve is to extend a horizontal line from the price level target, to the right, until such time as price action penetrates this level. In effect I have multiple Support & Resistance lines being drawn until such time as price touches them.

    I am manually drawing these lines in currently, but I believe there has to be a way to get EFS to do it automatically.

    I looked into the 'Filled_Gaps' code here for some ideas, and if you increase the limit #, behaves similar to what I am looking to achieve, the restriction is I cannot seem to get this script to handle multiple price levels simulatenously.

    Any and all ideas welcomed and greatly appreciated.

  • #2
    here you go..

    This is how I handle it...

    First, you need to mark the beginning point for all of these lines (I assume this will be the beginning of the day)..

    Next, you need to set conditionals for "if touched" for each line.

    In general, my little set of code will handle all of this for you...

    PHP Code:
    var nLastRawTime null;
    var 
    BarCounter 0;
    var 
    newDayBar 0;

    var 
    s1 null;
    var 
    s1_touched false;
    var 
    2s null;
    var 
    s2_touched false;
    var 
    r1 null;
    var 
    r1_touched false;
    var 
    r2 null;
    var 
    r2_touched false;

    function 
    main() {


      if (
    getValue("rawtime",0) != nLastRawTime) {
      
    //  New Bar
        
    nLastRawTime getValue("rawtime",0);
        
    BarCounter += 1;

        if (
    getDay(0) != getDay(-1)) {
          
    //--  New Day
          
    newDayBar BarCounter;

         
    // calc your S&R levels at the beginning of the new day (or however/whenever you want.  You also have to reset the "touched" variables at this time.
           
    s1_touched false;
           
    s2_touched false;
           
    r1_touched false;
           
    r2_touched false;
        }
      }


      
    //  Now, you can draw these lines until these levels are touched with simple logic.

      
    if (low() <= s1) { s1_touched true;  }
      if (
    low() <= s2) { s2_touched true;  }
      if (
    high() >= r1) { r1_touched true;  }
      if (
    high() >= r2) { r2_touched true;  }

      if (!
    s1_touched) {
        
    drawLineRelative((newDayBar -BarCounter), s10s1PS_SOLID1Color.blue"s1"+getDay(0));
      }
      if (!
    s2_touched) {
        
    drawLineRelative((newDayBar -BarCounter), s20s2PS_SOLID1Color.blue"s2"+getDay(0));
      }

      if (!
    r1_touched) {
        
    drawLineRelative((newDayBar -BarCounter), r10r1PS_SOLID1Color.red"r1"+getDay(0));
      }
      if (!
    r2_touched) {
        
    drawLineRelative((newDayBar -BarCounter), r20r2PS_SOLID1Color.red"r2"+getDay(0));
      }


    }  
    // end of main 
    Notice I'm using "getDay(0)" in the TAG field for all drawLine functions. The reason for this is each line is redrawn from the beginning of the day to the current bar until it is touched. To simplify, I'm drawing a single line from the beginning of the day till now with each draw function. I'm NOT drawing individual line segments on each bar.

    When the level is touched, it stops drawing the line at the point it was touched - but the line will remain on the chart (visible).

    Hope this helps you out.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      I cannot thank you enough for your code - you have exceeded the level of response I had expected to my question!

      You have certainly helped me understand the logic needed to handle the start/end marking principle.

      Comment

      Working...
      X