Announcement

Collapse
No announcement yet.

Volume subchart - base 0, but max variable?

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

  • Volume subchart - base 0, but max variable?

    I want my volume (nonprice study) subchart scale to always have zero at the bottom - which I have done with setStudyMin( 0 ), but I would like it to "autoscale" so that the Max varies depending on what time frame I select.

    For example in the 5 minute frame the maximum might be 3,000, but in the 60 minute it could be 40,000. If I started with the 5 min time frame my subchart would be sized with the maximum sized bars near the top of my subchart - but if I switch to a different time frame the 0 is still there, but the maximum bars may be super-large, extending way past the top of my subchart. Or if the time frame is smaller the histogram bars are very small. Either way I have to drag the autoscale on the right which then cancels out my 0 (zero) base, and I have to do a lot of autosizing and dragging. Is there a way to set the maximum based on a percentage as opposed to an absolute value?

    Thanks.

  • #2
    Re: Volume subchart - base 0, but max variable?

    Rusty3
    If what you want is to “clip” volume spikes or larger than normal volume bars as they compress the other bars then one way to do it is shown in the script I provided in this thread
    Alex


    Originally posted by Rusty3
    I want my volume (nonprice study) subchart scale to always have zero at the bottom - which I have done with setStudyMin( 0 ), but I would like it to "autoscale" so that the Max varies depending on what time frame I select.

    For example in the 5 minute frame the maximum might be 3,000, but in the 60 minute it could be 40,000. If I started with the 5 min time frame my subchart would be sized with the maximum sized bars near the top of my subchart - but if I switch to a different time frame the 0 is still there, but the maximum bars may be super-large, extending way past the top of my subchart. Or if the time frame is smaller the histogram bars are very small. Either way I have to drag the autoscale on the right which then cancels out my 0 (zero) base, and I have to do a lot of autosizing and dragging. Is there a way to set the maximum based on a percentage as opposed to an absolute value?

    Thanks.

    Comment


    • #3
      Thanks for your instant reply!

      What I'd like to have is the volume subchart auto-scale with the highest bar, say, 5% from the top of the chart, i.e., occupying 95% of the subchart's height. The other bars could be proportionately scaled to the largest bar. I want to see all the volume bars (without clipping).

      Now I have to drag the right scale so I get all the bars within the window and then I have to drag the chart up or down, because the zero line has moved away from the bottom of the chart.

      Thanks.

      Comment


      • #4
        Rusty3
        In that case the enclosed script should provide you a basic example of what you want
        Alex

        PHP Code:
        var highestVol;
        function 
        main(){
            var 
        Vol volume(0);
            if(
        getBarState()==BARSTATE_ALLBARS){
                
        highestVol Vol;
            } else {
                
        highestVol Math.max(highestVol,Vol);
            }
            
        setStudyMax(highestVol);
            return 
        Vol;


        Originally posted by Rusty3
        Thanks for your instant reply!

        What I'd like to have is the volume subchart auto-scale with the highest bar, say, 5% from the top of the chart, i.e., occupying 95% of the subchart's height. The other bars could be proportionately scaled to the largest bar. I want to see all the volume bars (without clipping).

        Now I have to drag the right scale so I get all the bars within the window and then I have to drag the chart up or down, because the zero line has moved away from the bottom of the chart.

        Thanks.

        Comment


        • #5
          Thanks Alex, perfect!

          Since no good deed goes unpunished...is it possible you could show me how to integrate this study with customVolume.efs?

          (I haven't learned enough EFS yet to do it. If you can't, that's fine. Thanks for your help.

          Rusty3

          Vol_Max (your study)

          var highestVol;
          function main(){
          var Vol = volume(0);
          if(getBarState()==BARSTATE_ALLBARS){
          highestVol = Vol;
          } else {
          highestVol = Math.max(highestVol,Vol);
          }
          setStudyMax(highestVol);
          return Vol;
          }


          customVolume.efs

          var fpArray = new Array();

          function preMain() {

          setPriceStudy(false);
          setStudyTitle("Volume");
          setCursorLabelName("Vol",0);
          setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
          setPlotType(PLOTTYPE_HISTOGRAM,0);
          setDefaultBarThickness(1,0);
          askForInput();

          var x = 0;
          fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
          with(fpArray[x++]){
          setDefault();
          }
          fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
          with(fpArray[x++]){
          setDefault();
          }
          fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
          with(fpArray[x++]){
          setName("Color based on");
          addOption("Price");
          addOption("Volume");
          setDefault("Price");
          }
          fpArray[x] = new FunctionParameter("ColorUp", FunctionParameter.COLOR);
          with(fpArray[x++]){
          setName("Up Color");
          setDefault(Color.RGB(0x00,0x94,0xFF));
          }
          fpArray[x] = new FunctionParameter("ColorDn", FunctionParameter.COLOR);
          with(fpArray[x++]){
          setName("Down Color");
          setDefault(Color.RGB(0xFE,0x69,0x00));
          }
          fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
          with(fpArray[x++]){
          setName("Show Parameters");
          setDefault(false);
          }
          }

          var bInit = false;
          var vSymbol = null;

          function main(Symbol,Interval,Source,ColorUp,ColorDn,Params ) {

          if(bInit == false){
          if(Symbol == null) Symbol = getSymbol();
          if(Interval == null) Interval = getInterval();
          vSymbol = Symbol+","+Interval;
          setShowTitleParameters(eval(Params));
          bInit = true;
          }

          if(Source=="Price"){
          if (close(sym(vSymbol)) < open(sym(vSymbol)))
          setBarFgColor(ColorDn,0);
          else if (close(sym(vSymbol)) > open(sym(vSymbol)))
          setBarFgColor(ColorUp,0);
          else if (close(sym(vSymbol)) == open(sym(vSymbol)))
          setBarFgColor(Color.RGB(0x00,0x94,0xFF),0);
          }
          if(Source=="Volume"){
          if (volume(sym(vSymbol)) < volume(-1,sym(vSymbol)))
          setBarFgColor(ColorDn,0);
          else if (volume(sym(vSymbol)) > volume(-1,sym(vSymbol)))
          setBarFgColor(ColorUp,0);
          else if (volume(sym(vSymbol)) == volume(-1,sym(vSymbol)))
          setBarFgColor(Color.RGB(0x00,0x94,0xFF),0);
          }

          return volume(sym(vSymbol));
          }

          Comment


          • #6
            Double-click does exactly what I want!

            I discovered that double-clicking in the right margin of my sub-chart sizes my sub-chart exactly the way I want it. I.e., the chart is sized so zero is at the exact bottom of the sub-chart and the maximum bar height for the displayed bars is right near the top of the chart.

            Comment

            Working...
            X