Announcement

Collapse
No announcement yet.

Volume Display

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

  • Volume Display

    Hi,

    1st off, thanks for such a fantastic trading platform. And thanks to the folks who answer these questions. It has really helped me.

    The reason is, I'm not even good enough at programming to be dangerous. I was looking through the efs's that are listed and saw something that sparked my interest, the ForceIndex.

    It shows volume displayed in a useful way - if the current bar closed lower than the previous bar, the volume bar is displayed less than zero, rather than just the usual red line up.

    Also, the volume is multiplied by the close difference, whether up or down, and a moving average.

    Here's my question, I'd like to simply display volume from a down bar as a histogram that displays below zero, by the volume amount of that particular bar. Of course with an up bar, a positive volume line would be shown as usual.

    I've been trying a few things and this is what I have so far - but since I don't know what I'm doing, it doesn't work ...

    From the magnificent programming abilities of the folks here, I was hoping you could get a bit of a chuckle from this and perhaps spend about as much time as 1/n as I have, where n has been a larger number than I'd like to specify !

    And thanks to Steve Hare who helped me before and Alexis who I am also indebted to.

    Best Regards, Glenn Swiatek San Mateo, CA



    var bInit = false;

    function preMain() {
    setStudyTitle("gV");
    setCursorLabelName ("Var0", 0);
    setDefaultBarFgColor(Color.yellow, 0);
    setPlotType(PLOTTYPE_HISTOGRAM, 0);
    setPriceStudy(false);
    }


    function main () {
    if ( bInit == false ) {

    DeltaC = close(0) - close(-1) ;
    Voly0 = volume(0) ;

    bInit = true;
    }


    myDeltaC = DeltaC.getValue(0);
    myVoly = Voly0.getValue(0);

    Voly1 = myDeltaC * myVoly ;
    AbsV1 = Math.abs(Voly1) ;
    Voly2 = Voly1 / AbsV1 ;

    return (Voly2);
    }

  • #2
    Re: Volume Display

    Glenn
    Here is a commented revision of your script that should do what you are trying to accomplish [assuming I understood you correctly]
    Alex

    PHP Code:
    var bInit false;

    function 
    preMain() {
        
    setStudyTitle("gV");
        
    setCursorLabelName ("Var0"0);
        
    setDefaultBarFgColor(Color.yellow0);
        
    setPlotType(PLOTTYPE_HISTOGRAM0);
        
    setPriceStudy(false); 
    }

    DeltaC null;//global variable
    Voly null;//as above

    function main () {

        if ( 
    bInit == false ) { 
            
    //initialize the global variables
            
    DeltaC close();//this is now a series [note no 0 in close(0) which would be a value]
            
    Voly0 volume();//as above
            
    bInit true
        } 

        var 
    myDeltaC DeltaC.getValue(0)-DeltaC.getValue(-1);//calculate the equation for myDeltaC
                                                              //using the current and previous values 
                                                              //of the DeltaC series
        
    var myVoly Voly0.getValue(0);//assign the current value of the Volume series to myVoly
        
        
    var Voly2 0;//local variable
        
        
    if(myDeltaC>0){//if the difference is greater than 0
            
    Voly2 myVoly;//assign the value of the volume to Voly2
        
    }else{//else
            
    Voly2 = -myVoly;//assign a negative volume value to Voly2
        
    }

        return (
    Voly2);//return Voly2

    Originally posted by fastflyer
    Hi,

    1st off, thanks for such a fantastic trading platform. And thanks to the folks who answer these questions. It has really helped me.

    The reason is, I'm not even good enough at programming to be dangerous. I was looking through the efs's that are listed and saw something that sparked my interest, the ForceIndex.

    It shows volume displayed in a useful way - if the current bar closed lower than the previous bar, the volume bar is displayed less than zero, rather than just the usual red line up.

    Also, the volume is multiplied by the close difference, whether up or down, and a moving average.

    Here's my question, I'd like to simply display volume from a down bar as a histogram that displays below zero, by the volume amount of that particular bar. Of course with an up bar, a positive volume line would be shown as usual.

    I've been trying a few things and this is what I have so far - but since I don't know what I'm doing, it doesn't work ...

    From the magnificent programming abilities of the folks here, I was hoping you could get a bit of a chuckle from this and perhaps spend about as much time as 1/n as I have, where n has been a larger number than I'd like to specify !

    And thanks to Steve Hare who helped me before and Alexis who I am also indebted to.

    Best Regards, Glenn Swiatek San Mateo, CA



    var bInit = false;

    function preMain() {
    setStudyTitle("gV");
    setCursorLabelName ("Var0", 0);
    setDefaultBarFgColor(Color.yellow, 0);
    setPlotType(PLOTTYPE_HISTOGRAM, 0);
    setPriceStudy(false);
    }


    function main () {
    if ( bInit == false ) {

    DeltaC = close(0) - close(-1) ;
    Voly0 = volume(0) ;

    bInit = true;
    }


    myDeltaC = DeltaC.getValue(0);
    myVoly = Voly0.getValue(0);

    Voly1 = myDeltaC * myVoly ;
    AbsV1 = Math.abs(Voly1) ;
    Voly2 = Voly1 / AbsV1 ;

    return (Voly2);
    }

    Comment


    • #3
      Glenn
      You could slightly simplify the script I posted in my previous reply by calculating a 1 period Momentum of the Close rather than calculating the difference between the values of the current and prior Closes. To do this you would replace
      DeltaC = close();
      with
      DeltaC = mom(1);
      and then replace
      var myDeltaC = DeltaC.getValue(0)-DeltaC.getValue(-1);
      with
      var myDeltaC = DeltaC.getValue(0);
      The result will be the same since the Momentum measures the difference between two values at the defined period
      As to your original script the main reasons why it was not working were that you were calculating DeltaC and Voly0 only once inside the bInit routine and then trying to retrieve their values as if they were series which they were not.
      Alex

      Comment


      • #4
        Thank You

        Thanks Again Alexis,

        I used it today and it worked the first time.

        Best Regards,

        Glenn

        Comment


        • #5
          Re: Thank You

          Glenn
          You are most welcome
          Alex


          Originally posted by fastflyer
          Thanks Again Alexis,

          I used it today and it worked the first time.

          Best Regards,

          Glenn

          Comment

          Working...
          X