Announcement

Collapse
No announcement yet.

help: newbie coding problem

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

  • help: newbie coding problem

    Newbie having trouble coding the following:

    new value = (previous value)*0.9 + current value of sym("$ADD")*0.1

    What am I doing wrong?

    PHP Code:
    function main(nLength) {

        if(
    nLength == null)
            
    nLength 30;
            
        var 
    nSum = new Array;
        
    nSum 0;
        
        var 
    vValue getValue("Close"0, -nLength"$ADD");
        if(
    vValue == null) {
            return;
        }
        
        for(
    0nLengthi++) {
            
    nSum[i] = 0.9*nSum[i-1] + 0.1*vValue[i];
        }
             
        return (
    nSum);    


  • #2
    Re: help: newbie coding problem

    richard1000
    You may need to describe what you are trying to accomplish as it is not apparent from the context of your script
    Alex


    Originally posted by richard1000
    Newbie having trouble coding the following:

    new value = (previous value)*0.9 + current value of sym("$ADD")*0.1

    What am I doing wrong?

    PHP Code:
    function main(nLength) {

        if(
    nLength == null)
            
    nLength 30;
            
        var 
    nSum = new Array;
        
    nSum 0;
        
        var 
    vValue getValue("Close"0, -nLength"$ADD");
        if(
    vValue == null) {
            return;
        }
        
        for(
    0nLengthi++) {
            
    nSum[i] = 0.9*nSum[i-1] + 0.1*vValue[i];
        }
             
        return (
    nSum);    

    Comment


    • #3
      Hello Alex, maybe the following link will clear things up. link

      I'm trying to replicate how he calculates Advance Decline Oscillator(ADO) and display it as an indicator.

      Comment


      • #4
        richard1000
        Enclosed below is a revision of your script
        PHP Code:
        var vValue null;

        function 
        main() {

            if(
        vValue==nullvValue close(sym("$ADD"));
             var 
        nSum_1 ref(-1);

            if(
        vValue.getValue(0) == null ) {
                return;
            }
           
            var  
        nSum 0.9 nSum_1 0.1 vValue.getValue(0);
                 
            return (
        nSum);    

        Note that to retrieve the previous value of the indicator I used the ref() function. For information on this function see this article in the EFS KnowledgeBase. You may also want to see my reply in this post with regards to other methods of retrieving prior values of a custom variable
        Also note that rather than calling the external symbol using the legacy getValue() function which syncs it by bar index I used instead the efs2 functionality and called the external symbol using the sym() function which will sync it by date and time
        For information and examples on the efs2 close() and sym() functions used in the formula see this and this article in the EFS KnowledgeBase
        Alex


        Originally posted by richard1000
        Hello Alex, maybe the following link will clear things up. link

        I'm trying to replicate how he calculates Advance Decline Oscillator(ADO) and display it as an indicator.

        Comment


        • #5
          Thanks Alex. I would have never guessed about ref(-1). Got a lot to learn ...

          Comment


          • #6
            richard1000
            You are welcome
            Alex


            Originally posted by richard1000
            Thanks Alex. I would have never guessed about ref(-1). Got a lot to learn ...

            Comment

            Working...
            X