Announcement

Collapse
No announcement yet.

CallFunction - Passing Previous Bar Values

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

  • CallFunction - Passing Previous Bar Values

    Hi,

    I am using CallFunction to pass values from one efs which is called by another efs. That is working fine, except I now wish to pass a value from the called efs for the current bar (easy), but also for the PREVIOUS bar (which I'm not finding so easy to do).

    I'd be grateful if somebody would could explain to me (in simple terms please) how I pass an output value from one efs to another efs for both for the current bar and the previous bar.

    Many thanks.

    Deax.

  • #2
    Hello Deax,

    If my understanding of what you need is correct, I think all you need to do is use a global variable to store the return value for the current bar's callFunction() value and another global to record the ending value at NEWBAR. When that bar closes, the second global value will be storing the previous bar's closing value from your callFunction call like below.

    PHP Code:
    var value null;
    var 
    value1 null;  // store previous bar's closing value

    function main() {

        if (
    getBarState() == BARSTATE_NEWBARvalue1 value;
        
        
    value callFunction(...);
        
        return 
    value;

    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
      Hi Jason,

      I am trying to take a value (for the current bar) from a called efs and compare it with the value for the previous bar. So my coding to call the value is:

      var MACD = null;
      MACD = callFunction("CalledupMACD.efs", "main");
      if (MACD == null) return;
      var vMACD = MACD[1];
      if (vMACD == null) return;

      I was then trying to compare the previous bar's value of MACD with the current bar's to see if it was greater or less (to tell me if the MACD is falling or rising):

      I tried to do this using the following code:

      if ((vMACD(-1))<(vMACD(0)) ..............................

      but it doesn't seem to be working.

      I'd be grateful for your view of the coding of the above problem.

      Many thanks in advance.

      Deax.

      Comment


      • #4
        Hello Deax,

        You can't use vMACD(0). The () characters are the function call operators. vMACD(0) is telling JavaScript to run a function named vMACD() with a parameter of 0 being passed to it. Unless you've created a user-defined function in your formula named vMACD, the function does not exist. What you need to do is use the code snippet I provided previously and name the two global variables, vMACD and vMACD1.

        PHP Code:
        var vMACD null;
        var 
        vMACD1 null;  // store previous bar's closing value

        function main() {

            if (
        getBarState() == BARSTATE_NEWBARvMACD1 vMACD;
            
            var 
        myMACD callFunction(...);
            
        vMACD myMACD[1];
            
            if (
        vMACD1 vMACD) {
                
        // run this code
            
        }

            
            return 
        vMACD;

        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