Announcement

Collapse
No announcement yet.

Question on Generic Broker code example ..gbroker_tester.efs

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

  • Question on Generic Broker code example ..gbroker_tester.efs

    Based on the post that included the sample code, I understand:

    - That the purpose of the "Trade" switch is to enable or disable the trade buttons.

    - Although not necessary for this mouse driven trade event it was included to illustrate how to disable the function when a formula is loading or reloading.

    - Trading will automatically become disabled and this technique should be included in any realtime formulas that are submitting trades.


    What portions of an EFS during various barstates get reloaded and what variables get reset is something I don't fully understand, how does this technique accomplish this?

    What is the reason for making this a "big G" (setGlobalVariable) variable?

    Once the switch is set to enable via the setGlobalVariable wouldn't it remain set independent of any subsequent EFS loads and reloads?

    Would this technique work if I was using this EFS loaded into multiple charts executing realtime trades given that the variable name is the same?

    If not could I concatenate the symbol name to the globalvariable name setGlobalVariable("trade"+getsymbol(), vEnable) to use a unique name?

    If formulas are triggering trades in realtime using EFS conditionals should the status of this flag be checked first to insure that trades are not executed on historical bars during a load or reload?

    Right now I check for BARSTATE_NEWBAR and a Barindex of 0 to set a boolean realtime flag. For strategies run on Renko charts I also found that for some reason I also had to check for barindex of 0 prior to sending the order to eliminate redundant orders.
    Should I add this additional check of the vEnable flag.

    Thanks very much.
    Last edited by demarcog; 01-18-2007, 09:53 PM.
    Glen Demarco
    [email protected]

  • #2
    Re: Question on Generic Broker code example ..gbroker_tester.efs

    Hello Glen,

    Originally posted by demarcog
    Based on the post that included the sample code, I understand:

    - That the purpose of the "Trade" switch is to enable or disable the trade buttons.

    - Although not necessary for this mouse driven trade event it was included to illustrate how to disable the function when a formula is loading or reloading.

    - Trading will automatically become disabled and this technique should be included in any realtime formulas that are submitting trades.


    What portions of an EFS during various barstates get reloaded and what variables get reset is something I don't fully understand, how does this technique accomplish this?
    When a study gets reloaded, the entire EFS is reprocessed over the entire chart. An EFS reload has nothing to do with a specific bar state. The bar states indicate the state of the bar as it gets processed by the EFS. You may want to review the bar states from Tutorial 4: Understanding Bar State and Bar Indexing.

    All global variables get reset, or re-initialized, when a reload occurs based on any of the manual events that generate a reload.
    - Change Symbol
    - Change Interval
    - Change Time Template
    - Edit Study Parameters
    - Right-click Reload
    - Manual Chart Refresh (Ctrl + click server status label "OK")

    The only exception is the reloadEFS() function. This programmatic reload does not reset the global variables. Therefore, any global variables that you would need to be reset when calling this function needs to be done in main() at BARSTATE_ALLBARS.

    PHP Code:
    function main() {
        if (
    getBarState() == BARSTATE_ALLBARS) {  // occurs once at the start of a reload.
            // reset globals here
        
    }
        ...
        ...



    What is the reason for making this a "big G" (setGlobalVariable) variable?
    It is the required syntax for the function. Remember that JavaScript is a case sensitive language.

    Once the switch is set to enable via the setGlobalVariable wouldn't it remain set independent of any subsequent EFS loads and reloads?
    Nope, because the global variable, vEnable, gets reset upon a reload of the EFS, which sets the application Global Trade variable back to false. After Enabling the GBroker_Tester.efs, try a right-click reload and you will see the "Disabled" label in the lower left corner. If you implement this Trade logic in the same manner as this test formula and wrap any of your Generic Broker calls inside a conditional statement that checks for a true value of the Trade variable, those calls will be disabled upon a reload event.

    Would this technique work if I was using this EFS loaded into multiple charts executing realtime trades given that the variable name is the same?

    If not could I concatenate the symbol name to the globalvariable name setGlobalVariable("trade"+getsymbol(), vEnable) to use a unique name?
    You got it. However, if you happen to have more than one chart with the same symbol, this wouldn't work. For that scenario you could concatenate getInvokerID(), which returns the ID number of the chart. Each chart has a unique ID.

    If formulas are triggering trades in realtime using EFS conditionals should the status of this flag be checked first to insure that trades are not executed on historical bars during a load or reload?
    Yes, absolutely.

    Right now I check for BARSTATE_NEWBAR and a Barindex of 0 to set a boolean realtime flag. For strategies run on Renko charts I also found that for some reason I also had to check for barindex of 0 prior to sending the order to eliminate redundant orders.
    Should I add this additional check of the vEnable flag.

    Thanks very much.
    Yes, you should also check for bar index of 0 to enable GB trade functions for any chart type.
    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
      Re: Re: Question on Generic Broker code example ..gbroker_tester.efs

      ...
      Originally posted by JasonK
      [B]Hello Glen,







      It is the required syntax for the function. Remember that JavaScript is a case sensitive language.

      Sorry for not stating that properly when I said "big G" I was trying to make the distinction between a global variable defined outside of main via the the normal: var vName which I refer to as little "g" and big G a variable defined via the setGlobalValue() function. My understanding is that a little g variable defined outside of main becomes accessable to all functions within that EFS. The big G variable is in a sense defined outside of the entire EFS via the setGlobalVariable() and as such available to all EFS's.

      I was asking why you used the setGlobalVariable() function and only saw in the code where it was getting initialized once and wondered how it got reset?

      I also was unclear how if I have several charts with this EFS loaded given that there is really only one "copy" of the big G variable named "Trade" shared by all runninf EFS's, how changing this variable for one chart doesn't effect all other running EFS's.

      As, always thanks very much for this very helpful response.

      Glen
      Last edited by demarcog; 01-19-2007, 10:08 AM.
      Glen Demarco
      [email protected]

      Comment


      • #4
        Sorry for the bad format, I left an extra quote tag in and can't edit it for some reason, if someone can make it available before responding I'd like to format it correctly and delete this post.

        thanks guys...
        Last edited by demarcog; 01-19-2007, 09:41 AM.
        Glen Demarco
        [email protected]

        Comment


        • #5
          Glen
          You should be able to edit the post now
          Alex

          Comment


          • #6
            Re: Re: Question on Generic Broker code example ..gbroker_tester.efs

            Originally posted by JasonK
            Hello Glen,



            When a study gets reloaded, the entire EFS is reprocessed over the entire chart. An EFS reload has nothing to do with a specific bar state. The bar states indicate the state of the bar as it gets processed by the EFS. You may want to review the bar states from Tutorial 4: Understanding Bar State and Bar Indexing.

            All global variables get reset, or re-initialized, when a reload occurs based on any of the manual events that generate a reload.
            - Change Symbol
            - Change Interval
            - Change Time Template
            - Edit Study Parameters
            - Right-click Reload
            - Manual Chart Refresh (Ctrl + click server status label "OK")

            The only exception is the reloadEFS() function. This programmatic reload does not reset the global variables. Therefore, any global variables that you would need to be reset when calling this function needs to be done in main() at BARSTATE_ALLBARS.

            PHP Code:
            function main() {
                if (
            getBarState() == BARSTATE_ALLBARS) {  // occurs once at the start of a reload.
                    // reset globals here
                
            }
                ...
                ...






            That's exactly what i need to know, I understand the barstates/barindex (thanks to you) but was unclear during the reloadEFS() what was going on in my code.

            So basically, a reloadEFS(), will reload main and leave the globals alone which seems like the desired behavior?

            However, if I'm relying on those variables being reset back to their initialization values, then the best time to do that and for a reloadEFS() is the BARSTATE_ALLBARS state?
            Glen Demarco
            [email protected]

            Comment


            • #7
              Originally posted by Alexis C. Montenegro
              Glen
              You should be able to edit the post now
              Alex
              Thanks you very much Alex, I'm trying to do too many things at one time.
              Glen Demarco
              [email protected]

              Comment


              • #8
                Glen
                To avoid the problem of not being able to edit your posts make sure that you include a line with some text before the quote box if this is at the top of your message.
                Alex

                Comment


                • #9
                  Re: Re: Re: Question on Generic Broker code example ..gbroker_tester.efs

                  Hello Glen,

                  Originally posted by demarcog
                  ...

                  Sorry for not stating that properly when I said "big G" I was trying to make the distinction between a global variable defined outside of main via the the normal: var vName which I refer to as little "g" and big G a variable defined via the setGlobalValue() function. My understanding is that a little g variable defined outside of main becomes accessable to all functions within that EFS. The big G variable is in a sense defined outside of the entire EFS via the setGlobalVariable() and as such available to all EFS's.
                  Your understanding is correct. A var outside of main() is a global variable only to the EFS formula where it is declared. When using setGlobalValue(), the variable becomes global to all EFS formulas. Think of these types of variables as application globals. Some user's have also referred to them as "universal" globals.

                  I was asking why you used the setGlobalVariable() function and only saw in the code where it was getting initialized once and wondered how it got reset?
                  The answer lies with this first condition inside main().

                  PHP Code:
                  ...
                      if (
                  bEdit == true) {
                              if (
                  Enable != null) {
                                  
                  vEnable Enable+"";
                                  
                  setGlobalValue("Trade"vEnable);
                              }
                  .... 
                  All variables are reset upon a manual reload event. The variable, bEdit, gets reset to true and the function parameter, Enable, also gets reset to false, which results in the Trade application global getting reset to false.

                  I also was unclear how if I have several charts with this EFS loaded given that there is really only one "copy" of the big G variable named "Trade" shared by all runninf EFS's, how changing this variable for one chart doesn't effect all other running EFS's.

                  As, always thanks very much for this very helpful response.

                  Glen
                  Previously, you mentioned concatenating getSymbol() to the variable name to prevent this problem. I suggested concatenating getInvokerID() as a better alternative.

                  setGlobalVariable("Trade"+getInvokerID(), vEnable);

                  This gives each formula running it's own unique big G variable so that their logic will not interfere with any others.


                  Originally posted by demarcog
                  That's exactly what i need to know, I understand the barstates/barindex (thanks to you) but was unclear during the reloadEFS() what was going on in my code.

                  So basically, a reloadEFS(), will reload main and leave the globals alone which seems like the desired behavior?
                  Some like it, some don't, it really depends on the specific code in question. I would recommend not using reloadEFS() if you can help it. It has a tendency to make formulas inefficient depending on how often it is allowed to execute.

                  However, if I'm relying on those variables being reset back to their initialization values, then the best time to do that and for a reloadEFS() is the BARSTATE_ALLBARS state?
                  Correct.
                  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


                  • #10
                    Re: Re: Re: Re: Question on Generic Broker code example ..gbroker_tester.efs





                    The answer lies with this first condition inside main().

                    PHP Code:
                    ...
                        if (
                    bEdit == true) {
                                if (
                    Enable != null) {
                                    
                    vEnable Enable+"";
                                    
                    setGlobalValue("Trade"vEnable);
                                }
                    .... 
                    All variables are reset upon a manual reload event. The variable, bEdit, gets reset to true and the function parameter, Enable, also gets reset to false, which results in the Trade application global getting reset to false.
                    Ah, sorry I missed that v in the setGlobalValue("Trade",vEnable)
                    thought you were enabling it each time through.....

                    Previously, you mentioned concatenating getSymbol() to the variable name to prevent this problem. I suggested concatenating getInvokerID() as a better alternative.

                    setGlobalVariable("Trade"+getInvokerID(), vEnable);

                    This gives each formula running it's own unique big G variable so that their logic will not interfere with any others.
                    Thanks for that useful suggestion and all your help....

                    Glen



                    Some like it, some don't, it really depends on the specific code in question. I would recommend not using reloadEFS() if you can help it. It has a tendency to make formulas inefficient depending on how often it is allowed to execute.



                    Correct. [/B][/QUOTE]
                    Glen Demarco
                    [email protected]

                    Comment


                    • #11
                      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


                      • #12
                        Can someone please tell me where to find gbroker_tester.efs?

                        Thanks

                        Comment

                        Working...
                        X