Announcement

Collapse
No announcement yet.

How to place ADDBAND to volume MA

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

  • How to place ADDBAND to volume MA

    If you take the Builtin "Volume MA" EFS

    function main(nInputLength) {
    if(nInputLength == null)
    nInputLength = 10;

    var nLength = nInputLength;
    var i;
    var vSum = 0.0;
    var vValue;

    vValue = volume(0, -nLength);

    if(vValue == null) {
    return;
    }

    for(i = 0; i < nLength; i++) {
    vSum += vValue[i];
    }

    return (vSum / nLength);

    How would you add "addband" to this formula. I like to place 1 or 2 mental guide lines on the study so it gives me a good idea of how things are doing.

  • #2
    addBand(80.0, PS_SOLID, 1, Color.red, 1);

    will place a red solid band at 80,

    addBand()

    addBand( dValue, nStyle, nThickness, Color, TagName )


    · dValue: y-axis value to place the band
    · nStyle: the pen style to draw with
    · nThickness: thickness of the line (in pixels)
    · Color: a RGB color value
    · TagName: A unique identifier for this text object.

    Example:

    addBand(80.0, PS_SOLID, 1, Color.red, 1);

    Pen Styles

    Colors

    Comment


    • #3
      Earl
      The enclosed code will add two bands to the indicator and will enable you to set their values through Edit Studies.
      This way you don't have to use the Editor every time you want to add/change/delete bands.
      Alex

      PHP Code:
      function preMain() {
        
          
      setPriceStudy(false);
          
      setStudyTitle("maVol");
          
      setCursorLabelName("maVol"0);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarFgColor(Color.black0);
          
      setDefaultBarThickness(10);
          
      setPlotType(PLOTTYPE_LINE0);
              
          var 
      fp1 = new FunctionParameter("MALength"FunctionParameter.NUMBER);
          
      fp1.setLowerLimit(1);        
          
      fp1.setDefault(10);
          
          var 
      fp2 = new FunctionParameter("Band1"FunctionParameter.NUMBER);
          
      fp2.setLowerLimit(0);        
          
      fp2.setDefault(0); 
          
          var 
      fp3 = new FunctionParameter("Band2"FunctionParameter.NUMBER);
          
      fp3.setLowerLimit(0);        
          
      fp3.setDefault(0); 
          
      }

      function 
      main(MALength,Band1,Band2) {

          var 
      nLength MALength;
          var 
      i;
          var 
      vSum 0.0;
          var 
      vValue;

          
      vValue volume(0, -nLength);

          if(
      vValue == null) {
          return;
         }
        
          for(
      0nLengthi++) {
              
      vSum += vValue[i];    
          }
         
          
      addBand(Band1,PS_SOLID,1,Color.blue,1);       
          
      addBand(Band2,PS_SOLID,1,Color.red,2);   
        
          return 
      Math.round(vSum/nLength); 


      Comment

      Working...
      X