Announcement

Collapse
No announcement yet.

Global Values (again)

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

  • Global Values (again)

    Is it possible to use a variable in the "varname" parm of the setGlobalValue(" varname" ) clause? By which I mean, can one construct a name based on variables and/or literals with the concatenation operator, or given that one must put it in quotes, (as are all the examples in the doco), is it then a string literal?

    What I want to do is create a global variable which has the current ticker symbol embedded in it, and not hard-code the symbol name. If this EFS were then attached to several open charts, then there would be an equal number of variables in the global pool, all of them having different variable names, and so all having different values.

    For example, this is what I have now:
    setGlobalValue("NQTrendIsUp",TrendIsUp);
    I would like to construct the first parameter, and prepend the symbol name using getSymbol(), etc, and not hard code the "NQ".
    Thanks
    George
    Last edited by wombat953; 08-04-2003, 04:01 AM.

  • #2
    Probably...

    I think you can do this...

    I would attempt it as follows...

    var GV1String = ""+getSymbol()+"TrendUP";
    setGlobalValue(GV1String, value);

    I don't see where this would be a problem.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Brad - many thanks.
      Let me better explain what I am trying to do, and you can tell me if your suggestion will work.

      I have an EFS which retrieves values from the global variable pool, (placed there by another EFS).
      I may have this (latter) EFS concurrently attached to multiple open charts for various symbols i.e. to ES, NQ, and so on. So there are to be be different values for different symbols, each placed there by the same EFS.

      The idea being that I want to code only one EFS which can retrieve the "right" value, for its symbol (and similarly, that the single EFS which populates the variable pool) , along the lines you have suggested.

      More simply put, a value is placed in the pool indicating if a trend is up, down or flat. Multiple symbols will - of course - have different values for trend, and so I need a different value for each symbol, placed there (and subsequently retrieved) by a general purpose EFS.

      Right now, I have separate EFS for each symbol which hard-codes the global variable to suit the symbol, and as you can imagine, this is a maintenance nighmare. Will your solution do the job?
      Thanks
      George

      Comment


      • #4
        George,

        Why not try a simple test case, you can use the GlobalValueTest.efs as a starting point (should be in the formula/other folder).

        If that doesn't work, then try using eval() on the symbol name variable and see if that helps.

        I suspect one of the two ways will work...

        Garth
        Garth

        Comment


        • #5
          global variables...

          George,

          My solution MAY help you resolve the issues of having multiple GVs on multiple charts. It will certainly help to automate the "naming" of the variables.

          The issues of "management" with all these GVs is up to you.

          If you have say 10 charts creating the GVs and one that reads them, then the one that reads the GV needs to know which variables are available - or scan through all potential variables.

          It would appear you are creating a potentially BIG file.

          Take it slow and test with only one or two GV until you get it right. Then expand with the rest of the GVs.

          Hope this helps.

          Brad
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Garth, Brad
            I think I have it now:

            getTrend(); //my own function which returns 2 variables;see below
            var UpVal = getSymbol()+"TrendIsUp";
            var DownVal = getSymbol()+"TrendIsDown";
            setGlobalValue("UpVal",TrendIsUp); setGlobalValue("DownVal",TrendIsDown);
            UpTrend=getGlobalValue("UpVal");
            DownTrend=getGlobalValue("DownVal");

            My understanding of programming (and JavaScript) is that the two variables UpVal and DownVal (themselves defined with their ticker symbol embedded as part of their variable names), will be assigned the appropriate values for the returned function variables TrendIsup and TrendIsDown(for each chart currently active).
            For chart of ticker ES, we have variables called:
            ES#FTrendIsUp
            ES#FTrendIsDown
            and for NQ#F, 2 more variables:
            NQ#FTrendIsUp
            NQ#TrendIsDown, etc, for as many active charts with the EFS attached/loaded.

            Access by another EFS is as follows:
            var UpVal = getSymbol()+"TrendIsUp";
            var DownVal = getSymbol()+"TrendIsDown"
            UpTrend=getGlobalValue("UpVal");
            DownTrend=getGlobalValue("DownVal");

            In other words, UpVal/DownVal will translate to different variable names depending on which chart (ticker) the EFS is associated with., and so, habe the appropriate trend values for those symbols.

            I believe this right......

            George

            Comment


            • #7
              Gentlemen
              Correction: Brad had it right initially:
              var UpVal = ""+getSymbol()+"TrendIsUp";
              var DownVal = ""+getSymbol()+"TrendIsDown";
              setGlobalValue(UpVal,TrendIsUp); setGlobalValue(DownVal,TrendIsDown);
              UpTrend=getGlobalValue(UpVal);
              DownTrend=getGlobalValue(DownVal);

              George

              Comment


              • #8
                Thanks George..

                Glad I could help....

                Brad
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment

                Working...
                X