Announcement

Collapse
No announcement yet.

how to get trailing newhigh adjusted

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

  • how to get trailing newhigh adjusted

    hi, i am a beginner of write custom efs. i want to get the adjusted newhigh, if not have new high, keep the pre value. How to get it? thanks very much.
    some code like follows, but it doesn't work.

    function main() {
    var NH=0;
    var HighPrice=0;
    var ad=0;
    HighPrice=hhv(20,high());
    var ad=(close(0)-close(-1))/2;

    if(getValue("high")<HighPrice(-1))
    NH=LowPrice(-1)+ad(0);
    return new array(getSeries(NH));
    }

  • #2
    lufund
    Before getting into the logic required to do what you want you need to be aware that there are several errors in the code you posted
    In the following line of code
    if(getValue("high")<HighPrice(-1))
    the syntax to retrieve the previous value of HighPrice is incorrect. To retrieve a value from a series (with the exception of the price series open(), high(), low() close() and volume()) you need to use the .getValue() method. In your case that line of code would need to be written as follows
    if(getValue("high")<HighPrice.getValue(-1))
    In the following line of code
    NH=LowPrice(-1)+ad(0);
    ad(0) is not valid syntax because that variable is not a series and even if it were you would need to retrieve its values using the getValue() method.
    In the following line of code
    return new array(getSeries(NH));
    the first error is that you are using the getSeries() function to retrieve NH which is not a series but a single value.
    Secondly return new array should be return new Array (EFS/JavaScript is a case sensitive language) and lastly you should not be using return new Array but just return because you are not returning an array but a single value.
    As to the logic required to do what you are trying to accomplish you can find a generic example enclosed below
    If - as you indicate - you are unfamiliar with programming in efs and are interested in learning you may want to start by reviewing the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
    Alex

    PHP Code:
    var CurrentNH  0;//global variable
    var PrevNH =0;
    //other global variables here
     
    function main(){
     
        if(
    getBarState()==BARSTATE_NEWBAR){//at every first tick of a new bar
            
    PrevNH CurrentNH;//transfer the most recent value of CurrentNH to PrevNH
        
    }
     
        
    //here you calculate your HighPrice and ad variables
        
    var HighPrice hhv(20,high());
        var 
    ad = (close(0)-close(-1))/2
     
        if(
    high(0)>HighPrice.getValue(-1)){//if the current High is greater than HighPrice at the prior bar
            
    CurrentNH low(-1)+ad;//calculate the value of CurrentNH
        
    } else {//else
            
    CurrentNH PrevNH;//assign PrevNH to CurrentNH
        
    }
     
        
    //rest of your code
     
        
    return CurrentNH


    Originally posted by lufund
    hi, i am a beginner of write custom efs. i want to get the adjusted newhigh, if not have new high, keep the pre value. How to get it? thanks very much.
    some code like follows, but it doesn't work.

    function main() {
    var NH=0;
    var HighPrice=0;
    var ad=0;
    HighPrice=hhv(20,high());
    var ad=(close(0)-close(-1))/2;

    if(getValue("high")<HighPrice(-1))
    NH=LowPrice(-1)+ad(0);
    return new array(getSeries(NH));
    }

    Comment

    Working...
    X