Announcement

Collapse
No announcement yet.

Dynamic Bands

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

  • Dynamic Bands

    Is there an efs available which will allow me to draw horizontal lines a predefined number of ticks above and below the current price, and update as the current price changes ? If not, are there any examples of something similar which I might be able to modify ? TIA

  • #2
    clayb1
    The enclosed efs will draw in real time horizontal lines at user defined values above and below the current price. Default values are ±0.10 and ±0.25 and can be modified through Edit Studies.
    Alex

    PHP Code:
    function preMain() {

        
    setPriceStudy(true);
        
    setStudyTitle("Lines");
        
    setCursorLabelName("Line1",0);
        
    setCursorLabelName("Line1",1);
        
    setCursorLabelName("Line1",2);
        
    setCursorLabelName("Line1",3);
        
        var 
    fp1 = new FunctionParameter("Upper2"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(0);        
        
    fp1.setDefault(0.25);
        
        var 
    fp2 = new FunctionParameter("Upper1"FunctionParameter.NUMBER);
        
    fp2.setLowerLimit(0);        
        
    fp2.setDefault(0.10);
        
        var 
    fp3 = new FunctionParameter("Lower1"FunctionParameter.NUMBER);
        
    fp3.setLowerLimit(0);        
        
    fp3.setDefault(0.10);
        
        var 
    fp4 = new FunctionParameter("Lower2"FunctionParameter.NUMBER);
        
    fp4.setLowerLimit(0);        
        
    fp4.setDefault(0.25);    
    }

    function 
    main(Upper2,Upper1,Lower1,Lower2) {

        
    clearLineTool(LineTool.HORZ);

        var 
    U2 close()+Upper2;
        var 
    U1 close()+Upper1;
        var 
    L1 close()-Lower1;
        var 
    L2 close()-Lower2;
        
        
    addLineTool(LineTool.HORZU21Color.blue"Up2");
        
    addLineTool(LineTool.HORZU11Color.blue"Up1");
        
    addLineTool(LineTool.HORZL11Color.red"Lo1");
        
    addLineTool(LineTool.HORZL21Color.red"Lo2");

        return new Array (
    formatPriceNumber(U2),formatPriceNumber(U1),
                          
    formatPriceNumber(L1),formatPriceNumber(L2));


    Comment


    • #3
      Great - that's exactly what I needed. Thank you !

      Comment


      • #4
        clayb1
        You are most welcome
        Alex

        Comment


        • #5
          Is there a way to post these but instead of current price it uses the first hour high or low and posts the bands .10 or .25 cents above and below that? Thanks for all your help.

          Comment


          • #6
            JIMMYZ
            Click here and you will find an efs that computes the High and Low of the first nn minutes.
            In it you can then easily transfer the commands to plot the horizontal lines replacing close() in the variables U2, U1, etc with vHigh and vLow which are the high and low set by the other efs.
            Alex

            Comment


            • #7
              thanks for the info alex. I am trying to work out the kinks with what I substituted. I used vhigh and vlow but I keep on getting error messages for not defining u1 even though its no longer in the formula. I appreciate all your efforts.

              Comment


              • #8
                JIMMYZ
                Post the efs with the modifications you have applied and I will try to walk you through correcting the errors
                Alex

                Comment


                • #9
                  Thanks alex,

                  here goes...

                  PHP Code:
                  function preMain() {

                      
                  setPriceStudy(true);
                      
                  setStudyTitle("Lines");
                      
                  setCursorLabelName("Line1",0);
                      
                  setCursorLabelName("Line1",1);
                      
                  setCursorLabelName("Line1",2);
                      
                  setCursorLabelName("Line1",3);
                      
                      var 
                  fp1 = new FunctionParameter("Upper2"FunctionParameter.NUMBER);
                      
                  fp1.setLowerLimit(0);        
                      
                  fp1.setDefault(0.25);
                      
                      var 
                  fp2 = new FunctionParameter("Upper1"FunctionParameter.NUMBER);
                      
                  fp2.setLowerLimit(0);        
                      
                  fp2.setDefault(0.10);
                      
                      var 
                  fp3 = new FunctionParameter("Lower1"FunctionParameter.NUMBER);
                      
                  fp3.setLowerLimit(0);        
                      
                  fp3.setDefault(0.10);
                      
                      var 
                  fp4 = new FunctionParameter("Lower2"FunctionParameter.NUMBER);
                      
                  fp4.setLowerLimit(0);        
                      
                  fp4.setDefault(0.25);    
                  }

                  function 
                  main(Upper2,Upper1,Lower1,Lower2) {

                      
                  clearLineTool(LineTool.HORZ);

                      var 
                  U2 close()+Upper2;
                      var 
                  vHigh close()+Upper1;
                      var 
                  vLow close()-Lower1;
                      var 
                  L2 close()-Lower2;
                      
                      
                  addLineTool(LineTool.HORZU21Color.blue"Up2");
                      
                  addLineTool(LineTool.HORZvHigh1Color.blue"Up1");
                      
                  addLineTool(LineTool.HORZvLow1Color.red"Lo1");
                      
                  addLineTool(LineTool.HORZL21Color.red"Lo2");

                      return new Array (
                  formatPriceNumber(U2),formatPriceNumber(vHigh),
                                        
                  formatPriceNumber(vLow),formatPriceNumber(L2));

                  If I did not want to use U2 and L2 would I just eliminate them?

                  Comment


                  • #10
                    JIMMYZ
                    Unless I misunderstood what you are trying to accomplish the efs you just posted will not do that.
                    You need to transfer the logic to draw the lines into the efs I indicated in my prior message else you have no way of determining the High and Low of the first nn minutes (which is what the other efs computes).
                    Once you have transferred the logic then you substitute close() with vHigh and vLow which are variables of the other efs
                    Alex

                    Comment


                    • #11
                      Ok I will try to blend the two together and see if I can make it work. Thanks.

                      Comment


                      • #12
                        Here is my effort and it will just draw the high and low without the addition and it only draws the horizontal lines only till 10:30 and then they stop. What could I be doing wrong? I'm dying to know where the logic flaw is in my thinking.

                        PHP Code:


                        function preMain() {

                            
                        setPriceStudy(true);
                            
                        setStudyTitle("Lines");
                            
                        setCursorLabelName("Line1",1);
                            
                        setCursorLabelName("Line1",2);
                            
                        setPlotType(PLOTTYPE_FLATLINES,0);
                            
                        setPlotType(PLOTTYPE_FLATLINES,1);
                            
                        setDefaultBarFgColor(Color.blue,0);
                            
                        setDefaultBarFgColor(Color.red,1);
                            
                            var 
                        fp1 = new FunctionParameter("Start"FunctionParameter.NUMBER);
                            
                        fp1.setDefault(930);
                            
                            var 
                        fp2 = new FunctionParameter("End"FunctionParameter.NUMBER);
                            
                        fp2.setDefault(1030);
                            
                            var 
                        fp3 = new FunctionParameter("Upper1"FunctionParameter.NUMBER);
                            
                        fp3.setLowerLimit(0);        
                            
                        fp3.setDefault(0.25);
                            
                            var 
                        fp4 = new FunctionParameter("Lower1"FunctionParameter.NUMBER);
                            
                        fp4.setLowerLimit(0);        
                            
                        fp4.setDefault(0.25);
                        }

                        var 
                        vFlag true;
                        var 
                        vFlag2 true
                        var vHigh null;
                        var 
                        vLow null;
                        var 
                        vClose null;
                        var 
                        vDay1 null;
                        var 
                        vDay2 null;

                        function 
                        main(Upper1,Lower1,Start,End) {

                            if (
                        getBarState() == BARSTATE_NEWBAR) {
                                if (
                        vDay1 == null) {
                                    
                        vDay2 getDay(0);
                                } else {
                                    
                        vDay2 vDay1;
                                }
                                
                        vDay1 getDay(0);
                                if (
                        vDay1 != vDay2) {
                                    
                        vHigh null;
                                    
                        vLow null;
                                    
                        vFlag true;
                                    
                        vFlag2 false;
                                }
                                var 
                        vHour1 = (getHour()*100)+getMinute();
                                if(
                        vHour1 >= Start){
                                
                        vFlag2=true;
                                }
                                var 
                        vHour = (getHour()*100)+getMinute();
                                if (
                        vHour >= End) {
                                    
                        vFlag false;
                                    
                        vFlag2=false
                                
                        }
                            }

                            if (
                        vFlag == true&&vFlag2==true) {
                                if (
                        vHigh == null) {
                                    
                        vHigh high(0);
                                }
                                if (
                        vLow == null) {
                                    
                        vLow low(0);
                                }
                                
                        vHigh Math.max(high(0), vHigh);
                                
                        vLow Math.min(low(0), vLow);
                                
                        vClose close(0);
                            
                            
                            return new Array(
                        vHigh,vLow);
                        }   
                            
                        clearLineTool(LineTool.HORZ);
                            
                            var 
                        U1 vHigh()+Upper1;
                            var 
                        L1 vLow()-Lower1;
                                
                            
                        addLineTool(LineTool.HORZU11Color.blue"Up1");
                            
                        addLineTool(LineTool.HORZL11Color.red"Lo1");
                            
                            return new Array (
                        formatPriceNumber(U1),formatPriceNumber(L1));

                        Comment


                        • #13
                          Here is how I did it once.

                          var sTime=930;
                          var eTime=1000;
                          var trendHigh=0;
                          var trendLow=0;
                          var tag=0;
                          var doorbell=0;
                          var door = 0;
                          var end1=0;

                          function preMain(){

                          debugClear();

                          setPriceStudy(true);
                          setStudyTitle("RangeHandL");
                          setCursorLabelName("rangeH", 0);
                          setCursorLabelName("rangeL", 1);
                          setDefaultBarStyle(PS_SOLID, 0);
                          setDefaultBarStyle(PS_SOLID, 1);
                          setDefaultBarFgColor(Color.green, 0);
                          setDefaultBarFgColor(Color.red, 1);
                          setDefaultBarThickness(3, 0);
                          setDefaultBarThickness(3, 1);
                          setPlotType(PLOTTYPE_SQUAREWAVE, 0);
                          setPlotType(PLOTTYPE_SQUAREWAVE, 1);

                          var fp1 = new FunctionParameter("sTime", FunctionParameter.NUMBER);
                          fp1.setName("sTime"); fp1.setLowerLimit(0); fp1.setDefault(930);

                          var fp2 = new FunctionParameter("eTime", FunctionParameter.NUMBER);
                          fp2.setName("eTime"); fp2.setLowerLimit(0); fp2.setDefault(1000);
                          }

                          function main(sTime, eTime){

                          mktTime=getHour()*100+getMinute()*1;

                          if(sTime==null) sTime=930;
                          if(eTime==null) eTime=1000;

                          if(mktTime*1==sTime*1){
                          tag=0;
                          trendHigh=open();
                          trendLow=open();
                          doorbell=0;
                          door=0;
                          end1 = 0;
                          }

                          if(mktTime>=sTime && mktTime < eTime){

                          if(high()>trendHigh)
                          trendHigh=high()

                          if(low()<trendLow)
                          trendLow=low()

                          setBarFgColor(Color.green, 0);
                          setBarFgColor(Color.red, 1);
                          setBarThickness(1, 0);
                          setBarThickness(1, 1);

                          }

                          return new Array(trendHigh, trendLow);
                          }

                          Comment


                          • #14
                            JIMMYZ
                            Here is the efs corrected of the errors.
                            FYI you can apply the same changes to the script David Loomis posted and obtain similar results. The only thing you will need to change are the names of the variables used (trendHigh instead of vHigh, etc).
                            Alex
                            Attached Files

                            Comment


                            • #15
                              Thanks a million! I appreciate all your effort and for taking the time in correcting my errors. I try to get better as I go along and will try to give back information if and when I can.

                              Comment

                              Working...
                              X