Register Login
Forums    February 9, 2012
TradersStudio Forums
Multiple outputs from a function
Last Post 09-01-2007 09:13 AM by Alexander Satulov. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Tom Himel
New Member
New Member
Posts:14

--
08-27-2007 04:27 AM

    Is it possible to have multiple outputs from a function?  In TradeStation, this is done by having function arguments used for outputs. If it is possible, what is the syntax, both for the function declaration and the calling routine?

    Thanks.

    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    08-29-2007 11:19 AM

    Yes, you need to declare the variables by ref.

    In general functions look for this one as your example

    Function ParabolicSAR(AfStep, AfLimit, ByRef oParCl, ByRef oParOp, ByRef oPosition, ByRef oTransition) As BarArray

     

     

    Richard Denning
    New Member
    New Member
    Posts:12

    --
    08-29-2007 01:54 PM
    If I understand correctly, the ByRef means the function can change the value that was passed to it, but I don't follow how you get two or more outputs from the function.

    Could you post a simple expample of calling a 2 output function together with the function code?

    Thanks
    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    08-31-2007 11:46 PM

    Please look at the sample code for the function I talked about able. It's in TradersStudio. If you look at the calling system and the function code it will be clear, it returns multiple values because you can set them in the function and use them in the calling program.

     

    Alexander Satulov
    New Member
    New Member
    Posts:5

    --
    09-01-2007 09:13 AM
    There are two ways to pass parameters to function: by values and by reference. In former case a function would work with the copies of the original parameters, thus no changing the originals. In the latter case a function would work directly with the originals, modifying them, and this can be used for returning multiple values from the function.
    For example:
    You have somewhere else two functions f1 and f2 defined

    function f1(byval v1, byval v2r)
    dim a as integer
    a = v1
    v1=v2
    v2=a
    ' return anything what you like here
    f1=v1+v2
    end function

    function f1(byref r1, byref r2)
    dim a as integer
    a = r1
    r1=r2
    r2=a
    ' return anything what you like here
    f2=r1+r2
    end function

    dim e1 as integer = 2
    dim e2 as integer = 4
    dim ret as integer = 0

    ret = f1(e1, e2) 'pass by value
    ' The result here: ret = 6, e1 = 2, e2 = 4. As you see though the f1 swapped the values inside, the outside values remain the same

    ret = f2(e1, e2) 'pass by reference
    ' The result here: ret = 6, e1 = 4, e2 = 2. As you see the f2 actually swapped the original variables outside of the function
    ' So here you returned as many as three results: ret, e1, e2. Use e1 and e2 as your additional returns from the function f2.
    If you want to pass two entries and have two new results then you would declare a function like this
    function myFunction(byval p1, byval p2, byref p3, byref p4), where p1 and p2 are your entries, and p3 and p4 are your results
    You are not authorized to post a reply.


     TradersStudio, Inc. ® Copyright 2004-2012 All Rights Reserved   Terms Of Use  Privacy Statement