Announcement

Collapse
No announcement yet.

MA on Positive Volume Index and on Negative Volume Index

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

  • MA on Positive Volume Index and on Negative Volume Index

    How can I put MA on Negative Volume Index and on Negative Volume Index?

  • #2
    KONSTANIDIS
    With eSignal 7.9 and using the new EFS2 functions you can do that with the example enclosed below. You will need to insert in the marked space the calculations required for the Positive Volume Index or Negative Volume Index
    For information on EFS in general you may want to read through the EFS KnowledgeBase. For EFS2 specific functions see the EFS2 Function Reference available at the same link or by clicking the Help icon in the Formula Editor
    Alex

    PHP Code:
    function preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("MA of PVI");
        
    setCursorLabelName("PVI",0);
        
    setCursorLabelName("MAofPVI",1);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1);
    }

    function 
    main(Length){

        if(
    Length==nullLength 10;
        
        var 
    PVI efsInternal("calcPVI");
        var 
    MAofPVI sma(Length,PVI);
        
        return new Array (
    PVI,MAofPVI);
    }

    function 
    calcPVI(){

    //insert here the code to calculate the PVI or NVI

        
    return ;//insert here the returned value of PVI or NVI

    Comment


    • #3
      Thank you for your answer.
      I do not unsterstand what should I insert at the returned value of PVI or NVI.

      For clarity I send you the whole formula:

      function preMain() {
      setPriceStudy(false);
      setStudyTitle("MA of PVI");
      setCursorLabelName("PVI",0);
      setCursorLabelName("MAofPVI",1);
      setDefaultBarFgColor(Color.blue, 0);
      setDefaultBarFgColor(Color.red, 1);
      }

      function main(Length){

      if(Length==null) Length = 10;

      var PVI = efsInternal("calcPVI");
      var MAofPVI = sma(Length,PVI);

      return new Array (PVI,MAofPVI);
      }

      function calcPVI(){

      var vPVI = 1;

      function preMain() {

      setStudyTitle("Positive Volume Index");
      setCursorLabelName("PVI");
      }

      function main() {

      var vBarState = getBarState();

      if (vBarState == BARSTATE_NEWBAR) {

      // get data
      var vCurVolume = volume(-1);
      var vPrevVolume = volume(-2);
      var vCurClose = close(-1);
      var vPrevClose = close(-2);

      // validate date
      if (vCurVolume == null) return;
      if (vPrevVolume == null) return;
      if (vCurClose == null) return;
      if (vPrevClose == null) return;


      if (vCurVolume > vPrevVolume) {

      var vValue = ( (vCurClose - vPrevClose) / vPrevClose) * vPVI;
      vPVI += vValue;
      }

      }
      return vPVI;

      }

      return ; //insert here the returned value of PVI or NVI
      }

      Comment


      • #4
        KONSTANTINIDIS
        In the marked section you would insert only the part of code that actually computes the PVI (or NVI). Also if in the original script there are global variables (ie outside of function main() such as for example var vPVI = 1) then these need to be placed outside of the function (in this case outside of function calcPVI()
        Enclosed below is the revised script which you can use as an example to write the MA of NVI (or moving averages or other studies)
        Alex

        PHP Code:
        function preMain() {
            
        setPriceStudy(false);
            
        setStudyTitle("MA of PVI");
            
        setCursorLabelName("PVI",0);
            
        setCursorLabelName("MAofPVI",1);
            
        setDefaultBarFgColor(Color.blue0);
            
        setDefaultBarFgColor(Color.red1);
        }

        function 
        main(Length){

            if(
        Length==nullLength 10;
            
            var 
        PVI efsInternal("calcPVI");
            var 
        MAofPVI sma(Length,PVI);
            
            return new Array (
        PVI,MAofPVI);
        }

        var 
        vPVI 1;

        function 
        calcPVI(){

            var 
        vBarState getBarState();

            
        // get data
            
        var vCurVolume volume(-1);
            var 
        vPrevVolume volume(-2);
            var 
        vCurClose close(-1);
            var 
        vPrevClose close(-2);

            
        // validate date
            
        if (vCurVolume == null || vPrevVolume == null || vCurClose == null || vPrevClose == null) return;
                
            if (
        vBarState == BARSTATE_NEWBAR) {

                if (
        vCurVolume vPrevVolume) {
                    var 
        vValue = ( (vCurClose vPrevClose) / vPrevClose) * vPVI;
                    
        vPVI += vValue;
                }
            }
            
            return 
        vPVI;

        Comment


        • #5
          Dear Alex,

          Thank you so much! It was a plessure to work with you!
          Chris

          Comment


          • #6
            Chris
            You are most welcome
            Alex

            Comment

            Working...
            X