Announcement

Collapse
No announcement yet.

Using Global Vars accross formulas and charts

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

  • Using Global Vars accross formulas and charts

    I tried to declare some Global Variables in one study and use them in an other on the same chart, but did not work, unless they are called from within the same efs file.
    For example (to test it), I declared ADX a global variable. If I call it from my custom ADXM indicator, it plots correctly. However, If I call it from a diferent indicator, it plot a straight line (probably the first value) that does not change with every bar.
    Can anybody tell me how it can/should be done?

    Second question.
    Are Global variables available accross charts in the layout?

    Thanks,
    mbuta
    Mihai Buta

  • #2
    There are two types of globals. One I will call "local Global" (odd as that sounds) and the other "universal Global".

    The first is done by declaring a variable outside of main(),
    preMain() and any other function you might have. This is local only to the instance of the EFS.

    The second is done by using setGlobalValue() and
    getGlobalValue(). These will set/get variables universally across all EFS formulas running in an instance of eSignal.

    G
    Garth

    Comment


    • #3
      Re: 'Using Global Vars accross formulas and charts'

      Hello G,
      Thanks for your reply.
      Is what I thought and I tried to use it this way.
      However, the ADX value I get is not changed every bar, altgough I update it
      (setGlobalVariable) evry bar. Why?

      Thanks,
      Mihai
      ----- Original Message -----
      From: <[email protected]>
      To: <[email protected]>
      Sent: Tuesday, February 04, 2003 9:11 PM
      Subject: Reply to post 'Using Global Vars accross formulas and charts'


      > Hello mbuta,
      >
      > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      >
      Mihai Buta

      Comment


      • #4
        Mihai,

        I'm not sure why, this usually works for me. One possibility I can think of is that you might be running one on a different (longer) interval?

        If you want, post up your code and I will look at it (or if you want you can make a small test case).

        If you do, let me know what charts (symbol, interval) you are running on so I can try to see if I can debug. No promises on results, but I would be happy to look it over.

        Garth
        Garth

        Comment


        • #5
          Hi Garth,
          Here are my two efs files. They are both on the same chart.
          One comment. I had to declare the "MyADX" in my file, otherwise I get compilation error.
          I assume that this is a valid way to declare global-global variables.

          This file generates the Global Variable "MyADX".

          /************************************************** **************************************************

          ************************************************** ************************************************** */
          //var study = new ADXDMStudy(14, 14);
          var study; var myADX; var myPDI; var myNDI;

          function preMain() {
          setStudyTitle("ADX");

          }

          function main(ADXLength) {
          if (ADXLength == null) {ADXLength = 14;}

          var nBarState = getBarState()
          if (nBarState == BARSTATE_ALLBARS) { // this will only occur once
          study = new ADXDMStudy(ADXLength, ADXLength);
          }
          var vADX = study.getValue(ADXDMStudy.ADX);
          var vPDI = study.getValue(ADXDMStudy.PDI);
          var vNDI = study.getValue(ADXDMStudy.NDI);

          if (vADX < vPDI & vADX < vNDI){setBarFgColor(Color.yellow,0);}
          else {setBarFgColor(Color.red);}
          if (vADX > vPDI & vADX > vNDI) {setBarThickness(3,0);}
          else {setBarThickness(2,0);}

          setCursorLabelName("ADX",0); setCursorLabelName("DI+",1); setCursorLabelName("DI-",2);
          setBarFgColor(Color.lime,1); setBarFgColor(Color.magenta,2);

          setGlobalValue("myADX", vADX);
          var vValue = getGlobalValue("myADX");


          return new Array(vValue, vPDI, vNDI);
          }


          This file attempts to use it.


          function preMain() {
          setStudyTitle("ADX");

          }

          function main(ADXLength) {

          var vValue = getGlobalValue("myADX");


          return (vValue);
          }

          Thank you.
          Mihai Buta

          Comment


          • #6
            Hi,

            OK, I think I see what is confusing to you, but first some general comments.

            You should check for null returns from you ADX study calls, and just return if they are null:

            if (vADX == null || vPDI == null || vNDI == null)
            return;


            You not only don't have to, but shouldn't declare MyADX as a var. It runs fine here without such a declaration.

            However - I think what you are expecting to see is both charts drawing historical values for ADX the same. This will not happen.
            There is nothing to synch up the historical time values on the charts. So, if I run the first EFS and it draws all those lines, when I run the second EFS, and it asks for MyADX global, all it will get is the most recent value of MyADX (ie: The last one). This is indeed what is happening.

            If you run the second EFS first, of course it will plot nothing as MyADX hasn't been set.

            However in RT it will all be syched up ok, as both the EFS studies will be called for each tick of data. However, you have to realize that the order is not predictive, so that it is possible the second EFS could run with a one bar lag. It isn't on mine right now, but it could.
            Garth

            Comment


            • #7
              Re: Reply to post 'Using Global Vars accross formulas and charts'

              Hi G,

              Thank you for your reply.
              I kinda suspected that it is a "synchronisation" problem.
              If what you say is true this means that the Global variables are unusable.
              How can one develop formulas and strategies (backtesting) if we cannot see
              what happens for the duration of the chart?
              Yes, I expect to see a duplicate ADX and I think you guys should do
              something to make it possible. Otherwise you are at significan disadvantage
              of your competition (TradeStation, for example).
              Same thing is true for referencing variables, function, etc., which you do
              not ofer at this time (unless it is in the return of a function/formula.
              For example,
              value = study3.getValue(MAStudy.MA, -2)
              should return the MA for 2 bars ago.
              Note: The Wizard assumes that this works and generates the code but, of
              course, does not work.

              Thanks,
              Mihai Buta

              Thanks,
              Mihai Buta

              ----- Original Message -----
              From: <[email protected]>
              To: <[email protected]>
              Sent: Thursday, February 06, 2003 9:37 AM
              Subject: Reply to post 'Using Global Vars accross formulas and charts'


              > Hello mbuta,
              >
              > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              >
              Mihai Buta

              Comment


              • #8
                Hi Mihai,


                Just to be clear, I don't work for eSignal. I'm just a user that has been coding EFS since it was first developed (well, pretty early in anycase).

                I disagree that universal globals are useless, I use them effectively for many things. But I do agree that for what you are trying to do, they don't help much...though there are complicated work arounds that I could give you if you want them.

                I also disagree that eSignal is at disadvatage to TS and others - in fact part of the reason I picked them was that there was only one other chartings package who could let me code what I wanted to. So it was a natual choice. I do agree however, there is work to be done, and Matt and have talked about many possible ways of fixing some of the issues you raise.

                value = study3.getValue(MAStudy.MA, -2)
                should return the MA for 2 bars ago.
                Note: The Wizard assumes that this works and generates the code but, of
                course, does not work.
                [
                Why do you think this doesn't work? If you have defined study3 correctly, this will in fact work, if you defined Study3 correctly.
                Garth

                Comment

                Working...
                X