Announcement

Collapse
No announcement yet.

Can ema() study return null?

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

  • Can ema() study return null?

    In this example, would v34EMA ever be null after this line:

    v34EMA = ema(34,0);

    was executed?




    Originally posted by Alexis C. Montenegro
    John
    In addition to what Steve said if you want to use .toFixed() you need to run a null check on the value first.
    The enclosed revision of your script should now work
    Alex

    PHP Code:
    var v34EMA null;

    function 
    preMain() {

        
    setPriceStudy(true);



    function 
    main() {

        
    v34EMA ema(34,0);
        if(
    v34EMA==null) return;
        
    //return("34="+v34EMA);
        
    return("34="+v34EMA.toFixed(3));


  • #2
    Hello Avery,

    Yes it would. It will return null for the first 33 bars in the chart because the study requires 34 bars before it will return a valid number. To test for this, you can use the debugPrintln() function and view the results in the formula output window after running the test script on a chart.

    PHP Code:
    function main() {
        var 
    v34EMA ema(340);
        if (
    v34EMA == nulldebugPrintln("Bar " getCurrentBarIndex() + " 34EMA is " v34EMA);
        
        return 
    v34EMA;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Thanks again, Jason.

      I am finally moving along the learning curve!

      Comment


      • #4
        You're most welcome.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X