Announcement

Collapse
No announcement yet.

Bands based on Open Price

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

  • Bands based on Open Price

    I am trying to adapt the efs for todays Open (user time specified) to include upper and lower bands based on a user specified amount.
    I.e open @ 9:00 (user specified) = 120.50
    up band (user specified) = .50 , hence plots a line at 121.00 for the day
    lower band (user specified) = -.50 , plots line at 120.00 for the day

    I am useless at code! can someone help? I think this should be rather simple.

    Thanks in advance.

  • #2
    try:
    PHP Code:
    function preMain() {
        var 
    aFPArray = new Array();
        
    setPriceStudy(true);
        
    setCursorLabelName("TodayOpen");

        var 
    x=0;
        
    aFPArray[x] = new FunctionParameter("UserTime"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Start Time For Open (2300)");
            
    setLowerLimit(0);        
            
    setUpperLimit(2400);        
            
    setDefault(900);
        }
        
    aFPArray[x] = new FunctionParameter("LineLen"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Line Length");
            
    setLowerLimit(1);        
            
    setDefault(100);
        }
        
    aFPArray[x] = new FunctionParameter("LineOfffset"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Line Offset");
            
    setLowerLimit(0);        
            
    setDefault(.5);
        }
        
    aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setDefault(true);
        }
    }

    function 
    main(UserTime,LineLen,LineOfffset,TodayOnly) {
        var 
    xOpen  LineTag null;
        if(
    TodayOnlyLineTag 105;
        else 
    LineTag gID();
        if(
    isMonthly() || isWeekly() || isDaily()) return;
        if((
    hour(0)*100)+minute(0)==UserTime){
            
    drawLineRelative0open(0)+LineOfffsetLineLenopen(0)+LineOfffsetPS_SOLID2Color.blue"Up"+LineTag ); 
            
    drawLineRelative0open(0), LineLenopen(0), PS_SOLID2Color.red"OpenMid"+LineTag ); 
            
    drawLineRelative0open(0)-LineOfffsetLineLenopen(0)-LineOfffsetPS_SOLID2Color.blue"Lo"+LineTag ); 
        }
    }
    var 
    grID 0;
    function 
    gID() {
        
    grID ++;
        return( 
    grID );

    Wayne

    Comment


    • #3
      Hi Wayne
      thanks , that works great! The only thing that would be really useful is to have it plot on previous days, is there a way to do that?
      thanks

      Comment


      • #4
        I changed the true to false in and that worked! so thanks again.

        Comment


        • #5
          yw.

          The reason I added a "TodayOnly" option is that draw functions (drawtext..., drawshape..., etc) eat up alot of memory and if abused can cause eSignal to freeze (at least that is my experience) so I suggest the time template include only the needed # of days.

          Wayne

          Comment


          • #6
            I'm trying to get the value of the bands to display on the y axis, I have all the various display options in the settings correct, is there something that needs to be added to the code?
            Many thanks

            Comment


            • #7
              Hi,

              drawLineRelative won't plot on the y axis scale, just on the chart itself.
              If you just want to see the price, try this:

              PHP Code:
              //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price
              function preMain() {
                  var 
              aFPArray = new Array();
                  
              setPriceStudy(true);
                  
              setCursorLabelName("TodayOpen");

                  var 
              x=0;
                  
              aFPArray[x] = new FunctionParameter("UserTime"FunctionParameter.NUMBER);
                  
              with(aFPArray[x++]){
                      
              setName("Start Time For Open (2300)");
                      
              setLowerLimit(0);        
                      
              setUpperLimit(2400);        
                      
              setDefault(900);
                  }
                  
              aFPArray[x] = new FunctionParameter("LineLen"FunctionParameter.NUMBER);
                  
              with(aFPArray[x++]){
                      
              setName("Line Length");
                      
              setLowerLimit(1);        
                      
              setDefault(100);
                  }
                  
              aFPArray[x] = new FunctionParameter("LineOffset"FunctionParameter.NUMBER);
                  
              with(aFPArray[x++]){
                      
              setName("Line Offset");
                      
              setLowerLimit(0);        
                      
              setDefault(.5);
                  }
                  
              aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
                  
              with(aFPArray[x++]){
                      
              setDefault(true);
                  }
                  
              aFPArray[x] = new FunctionParameter("PriceOffset"FunctionParameter.NUMBER);
                  
              with(aFPArray[x++]){
                      
              setName("Price Offset");
                      
              setLowerLimit(0);        
                      
              setDefault(3);
                  }
                  
              aFPArray[x] = new FunctionParameter("plotPrice"FunctionParameter.STRING);
                  
              with(aFPArray[x++]){
                      
              setName("Plot Price At");
                      
              addOption("Open Only");
                      
              addOption("Open & Offset");
                      
              addOption("Offset Only");
                      
              addOption("None");
                      
              setDefault("Open & Offset");
                  }
              }
              var 
              nPrice=0;
              function 
              main(UserTime,LineLen,LineOffset,TodayOnly,plotPrice,PriceOffset) {
                  var 
              xOpen  LineTag null;
                  if(
              TodayOnlyLineTag 105;
                  else 
              LineTag gID();
                  if(
              isMonthly() || isWeekly() || isDaily()) return;
                  if((
              hour(0)*100)+minute(0)==UserTime){
                      
              nPrice open(0);
                      
              drawLineRelative0open(0)+LineOffsetLineLenopen(0)+LineOffsetPS_SOLID2Color.blue"Up"+LineTag ); 
                      
              drawLineRelative0open(0), LineLenopen(0), PS_SOLID2Color.red"OpenMid"+LineTag ); 
                      
              drawLineRelative0open(0)-LineOffsetLineLenopen(0)-LineOffsetPS_SOLID2Color.blue"Lo"+LineTag ); 
                  }
                  if(
              plotPrice.indexOf("Open")!=-1drawTextRelative(PriceOffsetnPricenPriceColor.rednullText.BOLD Text.LEFT Text.VCENTERnull12"TimeP");
                  if(
              plotPrice.indexOf("Offset")!=-1){
                      
              drawTextRelative(PriceOffsetnPrice+LineOffsetnPrice+LineOffsetColor.bluenullText.BOLD Text.LEFT Text.VCENTERnull12"TimeP_H");
                      
              drawTextRelative(PriceOffsetnPrice-LineOffsetnPrice-LineOffsetColor.bluenullText.BOLD Text.LEFT Text.VCENTERnull12"TimeP_L");
                  }
              }
              var 
              grID 0;
              function 
              gID() {
                  
              grID ++;
                  return( 
              grID );

              Wayne

              Comment


              • #8
                thanks ever so much that worked a treat!

                Comment


                • #9
                  yw

                  Wayne

                  Comment


                  • #10
                    Hi wayne, I'm back again! the band values generated dont seem to appear in the data window, is this an easy thing to add?
                    many thanks
                    Daniel

                    Comment


                    • #11
                      Originally posted by ferret View Post
                      Hi wayne, I'm back again! the band values generated dont seem to appear in the data window, is this an easy thing to add?
                      many thanks
                      Daniel
                      PHP Code:
                      //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price
                      function preMain() {
                          var 
                      aFPArray = new Array();
                          
                      setPriceStudy(true);
                          
                      setCursorLabelName("TodayOpen+Offset",0);
                          
                      setCursorLabelName("TodayOpen",1);
                          
                      setCursorLabelName("TodayOpen-Offset",2);
                          
                      setDefaultBarThickness(20);
                          
                      setDefaultBarThickness(21);
                          
                      setDefaultBarThickness(22);

                          var 
                      x=0;
                          
                      aFPArray[x] = new FunctionParameter("User_S_Time"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setName("Start Time For Open (900)");
                              
                      setLowerLimit(0);        
                              
                      setUpperLimit(2400);        
                              
                      setDefault(900);
                          }
                          
                      aFPArray[x] = new FunctionParameter("User_E_Time"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setName("End Time For Open (1630)");
                              
                      setLowerLimit(0);        
                              
                      setUpperLimit(2400);        
                              
                      setDefault(1630);
                          }
                          
                      aFPArray[x] = new FunctionParameter("LineOffset"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setName("Line Offset in Ticks");
                              
                      setLowerLimit(0);        
                              
                      setDefault(2);
                          }
                          
                      aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
                          
                      with(aFPArray[x++]){
                              
                      setDefault(true);
                          }
                      }
                      var 
                      bInit false;
                      var 
                      drawIt=false;
                      var 
                      nPrice=0;
                      var 
                      aa=bb=cc=0;
                      function 
                      main(User_S_Time,User_E_Time,LineOffset,TodayOnly) {
                          if(
                      isMonthly() || isWeekly() || isDaily()) return;
                          var 
                      nState getBarState();
                          var 
                      xOpen  null;
                          var 
                      clr1=getChartBG();
                          var 
                      clr2=getChartBG();
                          var 
                      lnOff LineOffset getMinTick();
                          if(!
                      bInit){
                              if(
                      User_S_Time>User_E_Time){
                                  
                      displayError(1050"Error: End Time is greater that Start Time.""T2");
                              }
                              
                      bInit=true;
                          }
                          if(
                      nState==BARSTATE_ALLBARS){
                              
                      bCurrentDay=false;
                          }
                          if(!
                      bCurrentDay && getDay(0) != getDay(-1)){
                              var 
                      xTime getValue("time");
                              var 
                      xDate = new Date();
                              var 
                      sTime = (xTime.getMonth()+1+"/"+xTime.getDate()+"/"+xTime.getFullYear());
                              var 
                      sToday = (xDate.getMonth()+1+"/"+xDate.getDate()+"/"+xDate.getFullYear());
                              if(
                      sTime == sToday){
                                  
                      bCurrentDay true;
                              }
                              if(!
                      bCurrentDay){
                                  return;
                              }
                          }
                          if(
                      TodayOnly){
                              if(
                      bCurrentDay){
                                  if((
                      hour(0)*100)+minute(0)==User_S_Time){
                                      
                      nPrice open(0);
                                      
                      drawIt=true;
                                  }
                              }else{
                                  
                      clr1=getChartBG();
                                  
                      clr2=getChartBG();
                              }
                          }else{
                              if((
                      hour(0)*100)+minute(0)==User_S_Time){
                                  
                      nPrice open(0);
                                  
                      drawIt=true;
                              }
                              if((
                      hour(0)*100)+minute(0)>=User_E_Time){
                                  
                      nPrice 0;
                                  
                      drawIt=false;
                              }
                          }
                          if(
                      drawIt){
                              if(
                      nPrice!=0){
                                  
                      bb=nPrice;
                                  
                      aa=bb+lnOff;
                                  
                      cc=bb-lnOff;
                                  
                      clr1=Color.blue;
                                  
                      clr2=Color.magenta
                              
                      }
                          }
                          
                      setBarFgColor(clr1,0);
                          
                      setBarFgColor(clr2,1);
                          
                      setBarFgColor(clr1,2);

                          return [
                      aa,bb,cc];
                      }
                      function 
                      displayError(a,b,ErrStr,lbl) {
                          
                      //removeText("xError");
                          
                      drawTextRelative(abErrStrColor.maroonColor.lightgreyText.FRAME Text.ONTOP Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnull16"xError"+lbl);

                      Click image for larger version

Name:	del.png
Views:	1
Size:	32.8 KB
ID:	242873

                      or
                      PHP Code:
                      //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price
                      function preMain() {
                          var 
                      aFPArray = new Array();
                          
                      setPriceStudy(true);
                          
                      setCursorLabelName("TodayOpen+Offset",0);
                          
                      setCursorLabelName("TodayOpen",1);
                          
                      setCursorLabelName("TodayOpen-Offset",2);
                          
                      setDefaultBarThickness(20);
                          
                      setDefaultBarThickness(21);
                          
                      setDefaultBarThickness(22);

                          var 
                      x=0;
                          
                      aFPArray[x] = new FunctionParameter("User_S_Time"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setName("Start Time For Open (900)");
                              
                      setLowerLimit(0);        
                              
                      setUpperLimit(2400);        
                              
                      setDefault(900);
                          }
                          
                      aFPArray[x] = new FunctionParameter("User_E_Time"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setName("End Time For Open (1630)");
                              
                      setLowerLimit(0);        
                              
                      setUpperLimit(2400);        
                              
                      setDefault(1630);
                          }
                          
                      aFPArray[x] = new FunctionParameter("LineOffset"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setName("Line Offset in Ticks");
                              
                      setLowerLimit(0);        
                              
                      setDefault(2);
                          }
                          
                      aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
                          
                      with(aFPArray[x++]){
                              
                      setDefault(true);
                          }
                          
                      aFPArray[x] = new FunctionParameter("PriceOffset"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setName("Price Offset");
                              
                      setLowerLimit(0);        
                              
                      setDefault(3);
                          }
                          
                      aFPArray[x] = new FunctionParameter("plotPrice"FunctionParameter.STRING);
                          
                      with(aFPArray[x++]){
                              
                      setName("Plot Price At");
                              
                      addOption("Open Only");
                              
                      addOption("Open & Offset");
                              
                      addOption("Offset Only");
                              
                      addOption("None");
                              
                      setDefault("Open & Offset");
                          }
                          
                      aFPArray[x] = new FunctionParameter("drawOpenTxt"FunctionParameter.BOOLEAN);
                          
                      with(aFPArray[x++]){
                              
                      setDefault(false);
                          }
                          
                      aFPArray[x] = new FunctionParameter("OpenTxtFont"FunctionParameter.NUMBER);
                          
                      with(aFPArray[x++]){
                              
                      setLowerLimit(5);
                              
                      setDefault(10);
                          }
                      }
                      var 
                      drawIt=false;
                      var 
                      nPrice=0;
                      var 
                      aa=bb=cc=0;
                      function 
                      main(User_S_Time,User_E_Time,LineOffset,TodayOnly,plotPrice,PriceOffset,drawOpenTxt,OpenTxtFont) {
                          if(
                      isMonthly() || isWeekly() || isDaily()) return;
                          var 
                      nState getBarState();
                          var 
                      xOpen  null;
                          var 
                      clr1=getChartBG();
                          var 
                      clr2=getChartBG();
                          var 
                      lnOff LineOffset getMinTick();
                          if(
                      nState==BARSTATE_ALLBARS){
                              
                      bCurrentDay=false;
                          }
                          if(!
                      bCurrentDay && getDay(0) != getDay(-1)){
                              var 
                      xTime getValue("time");
                              var 
                      xDate = new Date();
                              var 
                      sTime = (xTime.getMonth()+1+"/"+xTime.getDate()+"/"+xTime.getFullYear());
                              var 
                      sToday = (xDate.getMonth()+1+"/"+xDate.getDate()+"/"+xDate.getFullYear());
                              if(
                      sTime == sToday){
                                  
                      bCurrentDay true;
                              }
                              if(!
                      bCurrentDay){
                                  return;
                              }
                          }
                          if(
                      TodayOnly){
                              if(
                      bCurrentDay){
                                  if((
                      hour(0)*100)+minute(0)==User_S_Time){
                                      
                      nPrice open(0);
                                      
                      drawIt=true;
                                  }
                              }else{
                                  
                      clr1=getChartBG();
                                  
                      clr2=getChartBG();
                              }
                          }else{
                              if((
                      hour(0)*100)+minute(0)==User_S_Time){
                                  
                      nPrice open(0);
                                  
                      drawIt=true;
                              }
                              if((
                      hour(0)*100)+minute(0)>=User_E_Time){
                                  
                      nPrice 0;
                                  
                      drawIt=false;
                              }
                          }
                          if(
                      drawIt){
                              if(
                      nPrice!=0){
                                  
                      bb=nPrice;
                                  
                      aa=bb+lnOff;
                                  
                      cc=bb-lnOff;
                                  
                      clr1=Color.blue;
                                  
                      clr2=Color.magenta
                                  
                      if(drawOpenTxt){
                                      if(
                      plotPrice.indexOf("Open")!=-1drawTextRelative(PriceOffsetbbbbclr2nullText.BOLD Text.LEFT Text.VCENTERnullOpenTxtFont"TimeP");
                                      if(
                      plotPrice.indexOf("Offset")!=-1){
                                          
                      drawTextRelative(PriceOffsetaaaaclr1nullText.BOLD Text.LEFT Text.VCENTERnullOpenTxtFont"TimeP_H");
                                          
                      drawTextRelative(PriceOffsetccccclr1nullText.BOLD Text.LEFT Text.VCENTERnullOpenTxtFont"TimeP_L");
                                      }
                                  }
                              }
                          }
                          
                      setBarFgColor(clr1,0);
                          
                      setBarFgColor(clr2,1);
                          
                      setBarFgColor(clr1,2);

                          return [
                      aa,bb,cc];

                      Click image for larger version

Name:	del.png
Views:	1
Size:	33.0 KB
ID:	242874

                      Wayne
                      Last edited by waynecd; 07-22-2013, 04:07 PM.

                      Comment


                      • #12
                        Wayne thats great thank you! Would this be difficlut to adapt in to a trade system that can be back tested. i.e if high is > upper band then do short, cover @open?

                        Comment


                        • #13
                          In the thread: http://forum.esignal.com/showthread....117#post146117
                          Alexis Montenegro lists resources that will help you learn efs study development. For strategy development resources do a knowledgebase search for "strategy".

                          A second alternative is to hire a the professional programmer. A link can be found here: http://forum.esignal.com/showthread....om-study-built

                          Good luck.

                          Wayne

                          Comment

                          Working...
                          X