Announcement

Collapse
No announcement yet.

clean way to call function parameter outside of main?

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

  • clean way to call function parameter outside of main?

    I'm looking for a good way to call a function parameter outside of main WITHOUT using a global parameter.
    No global parameter, because I will run more than one copy of this script at a time on the same eSignal instance.

    The following PROTOTYPE doesn't work because vAlertDebug is not defined outside of Main. If I put a 'var vAlertDebug;' in the initialization area, will it be a duplicate declaration? I can create a 'var vAlertDebug2;' and assign it the value of vAlertDebug in Main() each time it is run. Or is there something else more elegant?

    Also, is there a way to know when a script is FIRST run and when EDIT STUDIES is used and something is changed?


    PROTOTYPE example:

    // Initialize Script Area

    // Pre-Main
    function preMain() {
    var fp1 = ~vAlertDebug~
    "true"
    "false"
    }

    // Main
    function main( vAlertDebug ) {
    fAlerts();
    }

    // Post-Main

    // Actions
    function fAlerts() {
    if( vAlertDebug == "true" ) { debugPrintln("DANGER WILL ROBINSON!"); )
    }


    Thanks,
    -function THEO( Man'sGotToKnowHisCompiler'sLimitations );

  • #2
    Ted:

    You can use an external variable to store the value and then reference the external variable from within your other functions to determine the state. External variables are 'global' in scope to the entire script but are 'local' to the instance of the script that is running.


    PROTOTYPE example:

    // Initialize Script Area

    var myExternalVariable=null;

    // Pre-Main
    function preMain() {
    var fp1 = ~vAlertDebug~
    "true"
    "false"
    }

    // Main
    function main( vAlertDebug ) {
    myExternalVariable = vAlertDebug;
    fAlerts();
    }

    // Post-Main

    // Actions
    function fAlerts() {
    if( myExternalVariable == "true" ) { debugPrintln("DANGER WILL ROBINSON!"); )
    }


    Alternatively, you could pass the value of the input parameter directly to the function fAlerts() as a function parameter.

    PROTOTYPE example:

    // Initialize Script Area

    // Pre-Main
    function preMain() {
    var fp1 = ~vAlertDebug~
    "true"
    "false"
    }

    // Main
    function main( vAlertDebug ) {
    fAlerts( vAlertDebug );
    }

    // Post-Main

    // Actions
    function fAlerts( nParam ) {
    if( nParam == "true" ) { debugPrintln("DANGER WILL ROBINSON!"); )
    }



    Chris

    Comment


    • #3
      just pass the function the parameters..

      Why don't you just pass the function the parameters it needs...


      PROTOTYPE example:

      // Initialize Script Area

      // Pre-Main
      function preMain() {
      var fp1 = ~vAlertDebug~
      "true"
      "false"
      }

      // Main
      function main( vAlertDebug ) {
      fAlerts(vAlertDebug );
      }

      // Post-Main

      // Actions
      function fAlerts(param1) {
      if( param1== "true" ) { debugPrintln("DANGER WILL ROBINSON!"); )
      }
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        I went for the function parameter passing.

        My Main() calls trading functions, which in turn call a lot size calculation function, all which live outside Main(). Most options are driven by FunctionParameters.

        I'm passing MULTIPLE parameters to the 'trading' function calls, which pass pertinent parameters in turn to a 'lot size calc' function call. Seems cleaner than reassigning a big list of variables ( vGlobal1 = vFP1, etc. ) each time I want to run it.

        Thanks,
        THEO

        Comment

        Working...
        X