Announcement

Collapse
No announcement yet.

Syntax for Esignal formulas?

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

  • Syntax for Esignal formulas?

    I really need this document. I am trying to get a $TRIN ma for an indicator. The built in function will not let me add a symbol to the MA. Can someone help me with this?

    Thank you
    When all is said and done, more will be said than done.
    -- unknown

  • #2
    Hello T1,

    I'm assuming you wanted to plot this while your chart displays a different symbol. Let me know if you had a different intention.

    The built in function for MAStudy doesn't accept "symbol" as a parameter. It uses the symbol of your chart by default. We have to calculate the moving average ourselves if we want to plot that data with a chart of a different symbol.

    The formula I've created for you below will plot the simple moving average of $TRIN for 10 bars in an indicator pane. You can also right-click and edit the study to change the symbol or the number of bars (nLength) for this indicator.

    Code:
    var vSymbol = "";
    
    function preMain() {
        setPriceStudy(false);
        setStudyTitle("Symbol, MA: ");
        setCursorLabelName(vSymbol + " MA ");
    }
    
    function ma(nSymbol, nLength) {
        if (nSymbol == null) {
            return null;
        }
        if (nLength == null) {
            nLength = 10;
        }
        var i;
        var vSum = 0.0;
        var vValue;
    
        vValue = getValue("Close", 0, -nLength, nSymbol);
    
        if(vValue == null) {
            return null;
        }
    
        for(i = 0; i < nLength; i++) {
            vSum += vValue[i];
        }
    
        return (vSum / nLength);
    
    }
    
    function main(nSymbol, nLength) {
        if (nSymbol == null) {
            nSymbol = "$TRIN";
        }
        if (nLength == null) {
            nLength = 10;
        }
        if (getBarState() == BARSTATE_ALLBARS) {
            vSymbol = nSymbol;
            preMain();
        }
        var MA = ma(nSymbol, nLength);
    
        return MA;
    }
    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
      Excellent, Thank you for the response

      eom
      When all is said and done, more will be said than done.
      -- unknown

      Comment


      • #4
        addBand give me an error

        Jason,

        Thank you for the post.

        I tried to add addBand as below

        I added this to the premain.

        /* Add Bands to appear in the study window */
        addBand(1.4, PS_SOLID, 2, Color.black);
        addBand(0.6, PS_SOLID, 2, Color.black);

        I get an error message that the 5th parameter is invalid.

        I do not see a 5th parameter.

        Help!

        Thanks

        Tim
        When all is said and done, more will be said than done.
        -- unknown

        Comment


        • #5
          the 5th paramter is a unique label. If this is in premain, then all you really have to do is something like:

          addBand(1.4, PS_SOLID, 2, Color.black, "UpperBand");
          addBand(0.6, PS_SOLID, 2, Color.black, "LowerBand");
          Garth

          Comment


          • #6
            Thanks, worked great!

            This does not seem to be documented. I hope someone is taking notes
            When all is said and done, more will be said than done.
            -- unknown

            Comment

            Working...
            X