Announcement

Collapse
No announcement yet.

Help with a efsInternal series

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

  • Help with a efsInternal series

    Hi,
    The following code doesn't work.

    What I'm trying to do is build a CCI that is different then the standard one "CCI(14,hlc3())", As a first step I want to duplicate the standard one. So first I have a series for the SMA Typical Price (SMATP) using "high(0) + low(0) + close(0))/3" for the Typical Price (TP), which works fine.

    Then I want to caculate the Moving Deviation (MD) which is the SMA of the absolute value of the difference of the last SMATP and past N (in this case 14) TPs. I used the code example for esfInternal which works fine using close() or hlc3() to build the MD, but it doesn't work. Maybe I should just code it up using arrays, but I wanted to try using series (would it be better to use arrays?).

    Any help would be greatly appreciated.

    Thanks Tom


    PHP Code:
    function preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("CCI");
        
    setCursorLabelName("CCI",0);
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarThickness(2,0);
    }


    // global vars for Series Objects
    var tpSeries null;
    var 
    MY_tpSMA null;

    var 
    bInit false;  // initialization flag

    function main() {
        
    // initialize Series objects, occurs only once.
        
    if (bInit == false) {
            
    tpSeries efsInternal("Typical_Price");
            
    tpSMA sma(14tpSeries);
            
    bInit true;
        }
        
        
    // assign current value of Series to local vars for conditions
        
    MY_tpSMA tpSeries.getValue();
        
    myMD sma(14,efsInternal("Moving_Deviation",tpSMA,1,tpSeries()));

        return 
    MY_tpSMA 
    }

    function 
    Typical_Price() {
        return (
    high(0) + low(0) + close(0))/3;
    }

    function 
    Moving_Deviation(tp,length,tpseries) {
        
    MD Math.abs(tp tpseries.getvalue(-length));
        return 
    MD;


  • #2
    Tom
    You don't need to use efsInternal() to calculate the standard CCI.
    For an example of how to calculate the indicator using hlc3() as the source see the CCI.efs which is posted here
    You could then adapt this script to your requirements.
    Alex

    Comment


    • #3
      Thank you very much Alexis.

      I knew there must be a simpler way.

      Tom

      Comment


      • #4
        Tom
        You are most welcome
        Alex

        Comment

        Working...
        X