Announcement

Collapse
No announcement yet.

Time vertical lines

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

  • #16
    While using the script I found that if the timeArr or selected time0,time1,etc menu options aren't in chronological order it will plot incorrectly so I added a sort function to automatically sort the array from lowest time value to highest keeping the corresponding colors and line thicknesses.
    PHP Code:
    var arrLen null;
    function 
    preMain() {

        var 
    aFPArray = new Array();
        
    setPriceStudy(true);
        
    setStudyTitle("Vertical.q3 Time Plots");
        var 
    timeArr = [800,930,935,940,1030,1115,1600];
        var 
    lineClr = [Color.grey,Color.white,Color.aqua,Color.aqua,Color.darkgrey,Color.darkgrey,Color.navy];
        var 
    lineThick = [1,1,1,1,1,1,1];
        
    arrLen timeArr.length;
        var 
    x=0y=0i=0j=0;
        
    aFPArray[x] = new FunctionParameter("NumberOfLinesToDraw"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Draw The 1st ? Lines");//i.e., if NumberOfLinesToDraw==1 one line is drawn every time the 1st "time0" bar time is reached, if it==2 then two lines are drawn for "time0" and "time1", etc., NOTE: times and corresponding color/thickness will be automatically sorted in chronological order
            
    setLowerLimit(1);
            
    setUpperLimit(arrLen);
            for (
    0timeArr.lengthj++) {
                
    addOption(1);
            }
            
    setDefault(timeArr.length);
        }
        for(
    0timeArr.lengthi++){
            
    y="time"+i;
            
    aFPArray[x] = new FunctionParameter(yFunctionParameter.NUMBER);
            
    with(aFPArray[x++]){
                
    setLowerLimit(1);
                
    setDefault(timeArr[i]);
            }

            
    y="lineClr"+i;
            
    aFPArray[x] = new FunctionParameter(yFunctionParameter.COLOR);
            
    with(aFPArray[x++]){
                
    setDefault(lineClr[i]);
            }

            
    y="lineThick"+i;
            
    aFPArray[x] = new FunctionParameter(yFunctionParameter.NUMBER);
            
    with(aFPArray[x++]){
                
    setLowerLimit(1);
                for (
    0timeArr.lengthj++) {
                    
    addOption(j+1);
                }
                
    setDefault(lineThick[i]);
            }
        }
        
    aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setDefault(false);
        }
        
    aFPArray[x] = new FunctionParameter("enableSubStudy"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setDefault(false);
        }
        
    aFPArray[x] = new FunctionParameter("displayParam"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setDefault(false);
        }
    }

    var 
    bInit=false;
    var 
    paramArr=[];
    function 
    main(NumberOfLinesToDraw,
                  
    time0,time1,time2,time3,time4,time5,time6,
                  
    lineClr0,lineClr1,lineClr2,lineClr3,lineClr4,lineClr5,lineClr6,
                  
    lineThick0,lineThick1,lineThick2,lineThick3,lineThick4,lineThick5,lineThick6,
                  
    TodayOnly,enableSubStudy,displayParam) {

        if(
    isDWM()) return;
        var 
    drawIt true;
        if(
    TodayOnly && !is_Today()) drawIt false;

        if(!
    bInit){
            
    setShowTitleParametersdisplayParam );
            Array.
    prototype.min = function() {
              return 
    Math.min.apply(nullthis);
            };
            var 
    args = Array.prototype.slice.call(arguments);
            var 
    tempArr = [];
            var 
    0temp=null;
            for(
    03+= 1){
                
    tempArr.push([]);
            }
            for(
    0arrLen+= 1){
                if(
    args[i+1] != nulltempArr[0][i] = args[i+1];
                if(
    args[i+arrLen+1] != nulltempArr[1][i] = args[i+arrLen+1];
                if(
    args[i+2*arrLen+1] != nulltempArr[2][i] = args[i+2*arrLen+1];
            }
            
    paramArr=sort2D_Array(tempArr)[0];
            
    bInit=true;
        }
        
        if(
    drawItDrawTrigger(paramArrNumberOfLinesToDraw);
     
        return 
    null;

    }
    var 
    flag0 0flag1 0timeCtr=0;
    function 
    DrawTrigger(paramArrNumberOfLinesToDraw){

        var 
    0;
        var 
    barTm = (hour(0)*100)+minute(0);

        if(
    flag1 == && barTm paramArr[0][timeCtr+1]) flag1 0;

        if(
    flag0 == && barTm >= paramArr[0][paramArr[0].length -1]){
            if(
    NumberOfLinesToDraw == paramArr[0].length && getCurrentBarCount()>1onAction0(paramArr[1][paramArr[1].length-1],paramArr[2][paramArr[2].length-1]);
            
    flag0 1;
            
    flag1 0;
        }

        if(
    flag1 == 0){
            for(
    0paramArr[0].length+= 1){
                if((
    barTm >= paramArr[0][i] && barTm <paramArr[0][i+1])){
                    if(
    <= NumberOfLinesToDraw-1onAction0(paramArr[1][i],paramArr[2][i]);
                    
    flag0 0;
                    
    flag1 1;
                    
    timeCtr i;
                }
            }
        }
    }

    function 
    onAction0(clrthick) {
        
    drawLineRelative(0, -9999999990999999999PS_SOLIDthickclr"line"+rawtime(0));
    }
    function 
    is_Today(){//"bCurrentDay" only works while the chart receives ticks so it's always false when Mkt is closed
        
    var bCurrentDay false;
        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
        } 
        return 
    bCurrentDay;

    function 
    sort2D_Array(arr){
        var 
    arrT = [];
        for(
    03+= 1){
            
    arrT.push([]);
        }
        var 
    idxCtr=0;
        while (
    arr[0].length 0){
            var 
    arrLen=arr[0].length;
            var 
    index null;
            var 
    value arr[0].min();
            for (var 
    0arrLenj+=1) {
              if (
    arr[0][j] == value) {
                if(
    arr[0][j]!=null){
                    
    arrT[0][idxCtr]=arr[0][j];
                    
    arrT[1][idxCtr]=arr[1][j];
                    
    arrT[2][idxCtr]=arr[2][j];
                    
    idxCtr+=1;
                }
                
    removeElement(arrj)
              }
            }
        }
        return [
    arrT,arr];
    }
    function 
    removeElement(array, index){    
        if (
    index > -1) {
            array[
    0].splice(index1);//removes the element at specified index
            
    array[1].splice(index1);//removes the element at specified index
            
    array[2].splice(index1);//removes the element at specified index
            
    return true;
        }
        return 
    false;

    Wayne

    Comment


    • #17
      Removed unused menu item
      PHP Code:
      var arrLen null;
      function 
      preMain() {

          var 
      aFPArray = new Array();
          
      setPriceStudy(true);
          
      setStudyTitle("Vertical.q3 Time Plots");
          var 
      timeArr = [800,930,935,940,1030,1115,1600];
          var 
      lineClr = [Color.grey,Color.white,Color.aqua,Color.aqua,Color.darkgrey,Color.darkgrey,Color.navy];
          var 
      lineThick = [1,1,1,1,1,1,1];
          
      arrLen timeArr.length;
          var 
      x=0y=0i=0j=0;
          
      aFPArray[x] = new FunctionParameter("NumberOfLinesToDraw"FunctionParameter.NUMBER);
          
      with(aFPArray[x++]){
              
      setName("Draw The 1st ? Lines");//i.e., if NumberOfLinesToDraw==1 one line is drawn every time the 1st "time0" bar time is reached, if it==2 then two lines are drawn for "time0" and "time1", etc., NOTE: times and corresponding color/thickness will be automatically sorted in chronological order
              
      setLowerLimit(1);
              
      setUpperLimit(arrLen);
              for (
      0timeArr.lengthj++) {
                  
      addOption(1);
              }
              
      setDefault(timeArr.length);
          }
          for(
      0timeArr.lengthi++){
              
      y="time"+i;
              
      aFPArray[x] = new FunctionParameter(yFunctionParameter.NUMBER);
              
      with(aFPArray[x++]){
                  
      setLowerLimit(1);
                  
      setDefault(timeArr[i]);
              }

              
      y="lineClr"+i;
              
      aFPArray[x] = new FunctionParameter(yFunctionParameter.COLOR);
              
      with(aFPArray[x++]){
                  
      setDefault(lineClr[i]);
              }

              
      y="lineThick"+i;
              
      aFPArray[x] = new FunctionParameter(yFunctionParameter.NUMBER);
              
      with(aFPArray[x++]){
                  
      setLowerLimit(1);
                  for (
      0timeArr.lengthj++) {
                      
      addOption(j+1);
                  }
                  
      setDefault(lineThick[i]);
              }
          }
          
      aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
          
      with(aFPArray[x++]){
              
      setDefault(false);//set to true to only display lines for the current day but only if the current day is actively trading.  In other words if it is Saturday or Sunday the lines won't plot on Friday or at all if TodayOnly is set to true
          
      }
          
      aFPArray[x] = new FunctionParameter("displayParam"FunctionParameter.BOOLEAN);
          
      with(aFPArray[x++]){
              
      setDefault(false);
          }
      }

      var 
      bInit=false;
      var 
      paramArr=[];
      function 
      main(NumberOfLinesToDraw,
                    
      time0,time1,time2,time3,time4,time5,time6,
                    
      lineClr0,lineClr1,lineClr2,lineClr3,lineClr4,lineClr5,lineClr6,
                    
      lineThick0,lineThick1,lineThick2,lineThick3,lineThick4,lineThick5,lineThick6,
                    
      TodayOnly,displayParam) {

          if(
      isDWM()) return;
          var 
      drawIt true;
          if(
      TodayOnly && !is_Today()) drawIt false;

          if(!
      bInit){
              
      setShowTitleParametersdisplayParam );
              Array.
      prototype.min = function() {
                return 
      Math.min.apply(nullthis);
              };
              var 
      args = Array.prototype.slice.call(arguments);
              var 
      tempArr = [];
              var 
      0temp=null;
              for(
      03+= 1){
                  
      tempArr.push([]);
              }
              for(
      0arrLen+= 1){
                  if(
      args[i+1] != nulltempArr[0][i] = args[i+1];
                  if(
      args[i+arrLen+1] != nulltempArr[1][i] = args[i+arrLen+1];
                  if(
      args[i+2*arrLen+1] != nulltempArr[2][i] = args[i+2*arrLen+1];
              }
              
      paramArr=sort2D_Array(tempArr)[0];
              
      bInit=true;
          }
          
          if(
      drawItDrawTrigger(paramArrNumberOfLinesToDraw);
       
          return 
      null;

      }
      var 
      flag0 0flag1 0timeCtr=0;
      function 
      DrawTrigger(paramArrNumberOfLinesToDraw){

          var 
      0;
          var 
      barTm = (hour(0)*100)+minute(0);

          if(
      flag1 == && barTm paramArr[0][timeCtr+1]) flag1 0;

          if(
      flag0 == && barTm >= paramArr[0][paramArr[0].length -1]){
              if(
      NumberOfLinesToDraw == paramArr[0].length && getCurrentBarCount()>1onAction0(paramArr[1][paramArr[1].length-1],paramArr[2][paramArr[2].length-1]);
              
      flag0 1;
              
      flag1 0;
          }

          if(
      flag1 == 0){
              for(
      0paramArr[0].length+= 1){
                  if((
      barTm >= paramArr[0][i] && barTm <paramArr[0][i+1])){
                      if(
      <= NumberOfLinesToDraw-1onAction0(paramArr[1][i],paramArr[2][i]);
                      
      flag0 0;
                      
      flag1 1;
                      
      timeCtr i;
                  }
              }
          }
      }

      function 
      onAction0(clrthick) {
          
      drawLineRelative(0, -9999999990999999999PS_SOLIDthickclr"line"+rawtime(0));
      }
      function 
      is_Today(){//"bCurrentDay" only works while the chart receives ticks so it's always false when Mkt is closed
          
      var bCurrentDay false;
          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
          } 
          return 
      bCurrentDay;

      function 
      sort2D_Array(arr){
          var 
      arrT = [];
          for(
      03+= 1){
              
      arrT.push([]);
          }
          var 
      idxCtr=0;
          while (
      arr[0].length 0){
              var 
      arrLen=arr[0].length;
              var 
      index null;
              var 
      value arr[0].min();
              for (var 
      0arrLenj+=1) {
                if (
      arr[0][j] == value) {
                  if(
      arr[0][j]!=null){
                      
      arrT[0][idxCtr]=arr[0][j];
                      
      arrT[1][idxCtr]=arr[1][j];
                      
      arrT[2][idxCtr]=arr[2][j];
                      
      idxCtr+=1;
                  }
                  
      removeElement(arrj)
                }
              }
          }
          return [
      arrT,arr];
      }
      function 
      removeElement(array, index){    
          if (
      index > -1) {
              array[
      0].splice(index1);//removes the element at specified index
              
      array[1].splice(index1);//removes the element at specified index
              
      array[2].splice(index1);//removes the element at specified index
              
      return true;
          }
          return 
      false;

      Wayne

      Comment


      • #18
        I added the option to draw all lines/background up to the selected line # in option "DrawLines" or to only draw the one line selected line # in option "DrawLines".

        Draw_MultiTimeframe_Lines_or_Bg.efs

        Wayne
        Last edited by waynecd; 10-26-2016, 12:16 PM.

        Comment


        • #19
          Been using this custom time line vertical plot study efs it works perfectly. but want to add the option just to have the current period show, ie; from 4am onward for current session. Is there a simplistic way to add the code to this existing formula? If can get any help would be greatly appreciated.



          //debugClear();

          function preMain() {

          var aFPArray = new Array();
          setPriceStudy(true);
          setStudyTitle("Time - Price Pivots");
          var timeArr = [800,930,940,950,1030,1100,1600];
          var lineClr = [Color.grey,Color.white,Color.aqua,Color.aqua,Color .darkgrey,Color.darkgrey,Color.navy];
          var lineThick = [1,1,1,1,1,1,1];
          var x=0, y=0, i=0, j=0;
          aFPArray[x] = new FunctionParameter("NumberOfLinesToDraw", FunctionParameter.NUMBER);
          with(aFPArray[x++]){
          setName("Draw The 1st ? Lines");//i.e., if NumberOfLinesToDraw==1 one line is drawn every time the 1st "time0" bar time is reached, if it==2 then two lines are drawn for "time0" and "time1", etc.
          setLowerLimit(1);
          setUpperLimit(7);
          for (j = 0; j < lineThick.length; j++) {
          addOption(j + 1);
          }
          setDefault(7);
          }
          for(i = 0; i < timeArr.length; i++){
          y="time"+i;
          aFPArray[x] = new FunctionParameter(y, FunctionParameter.NUMBER);
          with(aFPArray[x++]){
          setLowerLimit(1);
          setDefault(timeArr[i]);
          }

          y="lineClr"+i;
          aFPArray[x] = new FunctionParameter(y, FunctionParameter.COLOR);
          with(aFPArray[x++]){
          setDefault(lineClr[i]);
          }

          y="lineThick"+i;
          aFPArray[x] = new FunctionParameter(y, FunctionParameter.NUMBER);
          with(aFPArray[x++]){
          setLowerLimit(1);
          for (j = 0; j < lineThick.length; j++) {
          if (lineThick[j] != null) addOption(j+1);
          }
          setDefault(1);
          }
          }
          aFPArray[x] = new FunctionParameter("displayParam", FunctionParameter.BOOLEAN);
          with(aFPArray[x++]){
          setDefault(false);
          }
          }

          var bInit=false;
          var paramArr=[];
          function main(NumberOfLinesToDraw,
          time0,time1,time2,time3,time4,time5,time6,
          lineClr0,lineClr1,lineClr2,lineClr3,lineClr4,lineC lr5,lineClr6,
          lineThick0,lineThick1,lineThick2,lineThick3,lineTh ick4,lineThick5,lineThick6,
          displayParam) {

          if(isDWM()) return;
          if(!bInit){
          setShowTitleParameters( displayParam );
          var i = 0, temp=null;
          for(i = 0; i < 3; i += 1){
          paramArr.push([]);
          }
          for(i = 0; i < 7; i += 1){
          temp = eval("time" + i);
          if(temp != null) paramArr[0][i] = temp;
          temp = eval("lineClr" + i);
          if(temp != null) paramArr[1][i] = temp;
          temp = eval("lineThick" + i);
          if(temp != null) paramArr[2][i] = temp;
          }
          bInit=true;
          }

          DrawTrigger(paramArr, NumberOfLinesToDraw);

          return null;

          }

          var flag0 = 0, flag1 = 0, timeCtr=0;
          var DrawTriggerInit=false;
          function DrawTrigger(paramArr, NumberOfLinesToDraw){

          var i = 0;
          var barTm = (hour(0)*100)+minute(0);

          if(!DrawTriggerInit){
          for(i = 0; i < paramArr[0].length; i += 1){
          if(paramArr[1][i] != null) setDefaultBarFgColor(paramArr[1][i],i);
          if(paramArr[2][i] != null) setDefaultBarThickness(paramArr[2][i],i);
          }
          DrawTriggerInit=true;
          }

          if(flag1 == 1 && barTm > paramArr[0][timeCtr+1]) flag1 = 0;

          if(flag0 == 0 && barTm >= paramArr[0][paramArr[0].length -1]){
          if(NumberOfLinesToDraw == paramArr[0].length && getCurrentBarCount()>1) onAction0(paramArr[1][paramArr[1].length-1],paramArr[2][paramArr[2].length-1]);
          flag1 = 0;
          flag0 = 1;
          }

          if(flag1 == 0){
          for(i = 0; i < paramArr[0].length; i += 1){
          if((barTm >= paramArr[0][i] && barTm <paramArr[0][i+1])){
          if(i <= NumberOfLinesToDraw-1) onAction0(paramArr[1][i],paramArr[2][i]);
          flag0 = 0;
          flag1 = 1;
          timeCtr = i;
          }
          }
          }
          }

          function onAction0(clr, thick) {
          drawLineRelative(0, 0, 0, 999999,PS_SOLID, thick, clr, "line"+rawtime(0));
          }

          Comment

          Working...
          X