Announcement

Collapse
No announcement yet.

Any way to plot lagging data

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

  • Any way to plot lagging data

    I have a DLL which collects various data and makes it available to eSignal EFS.

    The main () procedure returns the value to plot for the current bar. My problem is that my EFS formula requests the data for the current (real-time) bar often before the DLL has it ready, and so I cannot calculate the value for main () to return.

    My DLL data is ready by the first tick into the next bar, so I find myself needing to return a value to plot one bar ago (as opposed to the current bar).

    Is there any way to do this?

    The only solution I have come up with is to "reloadEFS ()" once the data is ready, so that the entire formula is reloaded and replotted. This is inefficient and processor intensive.

  • #2
    Hello Bullman,

    I'm happy to say, you can ditch that reloadEFS() routine. What you need to use instead is setBar(), which will allow you to change the return values of previous bars.
    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
      Jason,

      Thanks for the tip, it works fine if I am returning a single value. But, if I am plotting more than one value, I cannot get setBar() to work for the 2nd, 3rd, ... values, whether I try updating all at once with an array or one at a time with an index.

      Is this a bug in setBar, or am I doing something wrong?


      // try 1 - only updates the first value in the array, ignores the rest
      updateValues = new Array (curExpAvgVol, curExpAvgDWVol, adjAvgVol);
      setBar (Bar.Value, - i, updateValues);

      // try 2 - only updates the first value in the array, ignores the rest
      setBar (Bar.Value, - i, new Array (curExpAvgVol, curExpAvgDWVol, adjAvgVol));

      // try 3 - still only updates the first value
      updateValues = new Array (curExpAvgVol, curExpAvgDWVol, adjAvgVol);
      len = updateValues.length;
      for (var j=0; j<len; j++) {
      setBar (Bar.Value, -i, j, updateValues [j]);
      }

      // this works - updates the first value
      setBar (Bar.Value, - i, curExpAvgVol);

      // this works - updates the first value
      setBar (Bar.Value, - i, 0, curExpAvgVol);

      // this does NOT works - it should update the second value
      setBar (Bar.Value, - i, 1, curExpAvgDWVol);

      Comment


      • #4
        Hello bullman,

        Hopefully this code example will help. One thing to point out first is that the offset parameter may seem a bit counter intuitive. setBar() already assumes that you're changing info for previous bars so it sees an offset of 0 as the bar with an index of -1. The other thing you may be having trouble with is not having the proper size array on the previous bar's returned data series to change the values of. In the code example below, you'll notice that I'm just returning null values for the return series. This essentially primes the array on that bar for the returned data series. If you comment out that return line below, this code example doesn't work. Before you can change the values of a previous bar with setBar(), something had to be returned to that bar to initialize its array. Let me know if this helps.

        PHP Code:
        function preMain() {
            
        setStudyTitle(" setBar ");
            
        setCursorLabelName("data0"0);
            
        setCursorLabelName("data1"1);
            
        setCursorLabelName("data2"2);
            
        setStudyMax(100);
            
        setStudyMin(0);
        }

        var 
        aData = new Array(3);
        aData[0] = 40;
        aData[1] = 35;
        aData[2] = 30;

        function 
        main() {
            if (
        getCurrentBarIndex() > -&& getBarState() == BARSTATE_NEWBAR) {
                
        setBar(Bar.Value0aData);        
                
                
        // or you can do this
                //for (i=0; i<3; ++i) {
                //    setBar(Bar.Value, 0, i, aData[i]);
                //}
            
        }
            return new Array(
        nullnullnull);

        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

        Working...
        X