Announcement

Collapse
No announcement yet.

price range function

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

  • price range function

    For the selected number of bars/ticks <<length>> and the number of sub-intervals <<bars>> this small function shows the range of the price movement to the right of the price bars.

    Might be helpful for certain strategies....

    Axel


    Code:
    // Copyright Axel Palme     price range function
    // length gives the number of intervals/ticks used for calculation
    // bars defines the number of bars into which length is divided
    // the function divides the data stream of defined <<length>> into <<bars>> sub-intervals
    // for each subinterval a bar is drawn to the right of the price bars from low to high
    // the part of the bar above close() level is red below green 
    function preMain()
       {
    //  setComputeOnClose();                        // standard is use of tick data chck alse EFS>TOOLS>SETTINGS
       setPriceStudy(true);
       setStudyTitle("price range");
    
       var fp = new FunctionParameter( "length", FunctionParameter.NUMBER);
       with (fp) 
          {
          setName("length");
          addOption(10);       addOption(20);       addOption(30);       addOption(40);
          addOption(50);       addOption(60);       addOption(70);       addOption(80);
          addOption(90);       addOption(100);      addOption(150);      addOption(200);
          setLowerLimit(1);    setDefault(50);
          }
       var fp = new FunctionParameter( "bars", FunctionParameter.NUMBER);
       with (fp) 
          {
          setName("bars");
          addOption(1);       addOption(2);       addOption(3);       addOption(4);
          addOption(5);       addOption(6);       addOption(7);       addOption(8);
          addOption(9);       addOption(10);       addOption(11);       addOption(12);
          setLowerLimit(1);    setDefault(5);
          } 
       var fp = new FunctionParameter( "hypertrade", FunctionParameter.STRING);
       with (fp) 
          {
          setName("hypertrade");
          setDefault("                   .");
          } 
       }
    function main(length,bars,hypertrade) 
       {
        if(getCurrentBarIndex() == 0) 
          {
          clearLineTool(LineTool.SEGMENT);
          var PerBar = Math.floor(length/bars);        // data per bar
          drawTextRelative(3, 12, bars+"*"+PerBar, Color.black, null, Text.ONTOP | Text.BOLD | Text.RIGHT |
                        Text.RELATIVETOTOP, "Arial", 11, "M"); 
          var c = close();
          drawShapeRelative(2,c,Shape.RIGHTTRIANGLE,null,Color.blue,null,3);
          addLineTool(LineTool.SEGMENT,2,c,3+bars,c, 2, Color.blue, 2);
          var lows = getValue("Low",0,-length);
          var highs = getValue("High",0,-length);
          for(i=1;i<=bars;i++)
             {
             var min =10000;
             while(lows.length >length-i*PerBar)
                {min = Math.min(min,lows.pop())};
             var max =0;
             while(highs.length >length-i*PerBar)
                {max = Math.max(max,highs.pop())};
             if (c <= max) {addLineTool(LineTool.SEGMENT, i+2, ((c>min)?c:min), i+2, max, 4, Color.red,1)};
             if (c >= min) {addLineTool(LineTool.SEGMENT, i+2, ((c<max)?c:max), i+2, min, 4, Color.green,1)};
             }
          }
       }
    Axel
Working...
X