Announcement

Collapse
No announcement yet.

Drawing Lines in Advanced Charts Help Required

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

  • Drawing Lines in Advanced Charts Help Required

    I have been working on drawing lines in my advanced charts but have experienced a number of difficulties as many of the functions are not seemingly properly documented which I would like to get some comments/assistance/advice.

    I have used both drawLineRelative and drawLineAbsolute with varying degrees of success as follows:-

    ///////////////////////////////////////////////
    Use of drawLineXXX()
    ///////////////////////////////////////////////

    1. drawLineAbsolute(x1, y1, x2, y2, Line Type, Thickness, Color, TagID);

    I have tried to use a combination of:-

    getCurrentBarIndex() ; This should give bar index numbers starting at 0 for the current index with the amount incrementing negatively to the prior bar index and shouild update incremently as each bar is drawn. in my system this is never done.

    getOldestBarIndex(); This should give the total number of bar indicies startimng from start to current. This should update incremently as each bar is drawn. In my system this is never done.

    To fix the x1 and x2 coorinates with poor success, as these functions to do not update properly on my system and you have to reset the chart by reloading the efs file so that it shows the current situation. I believe there is flaw in the coding of the functions

    2. drawLineRelative(x1, y1, x2, y2, Line Type, Thickness, Color, TagID);

    This has worked out much better drawing the line in majority of cases where I want it. I still have some small problems but they are too esotrerci to go through here at this satge. Please see the code fragments below which has worked out for. What was critical was building the x2 parameter. x1 was easy as that is 0. However the problem is how to build x2. The only way because neither getCurrentBarIndex() or getOldestBarIndex() workews on my system is to build an index of my own.

    I have also used a number of differing methods to fix the TagID with the best success using rawtime as in the examples below.


    ///////////////////////////////////////////////////////////
    Building an Index based on Time and Chart Interval
    ///////////////////////////////////////////////////////////
    function preMain()......

    var vInterval = null;
    var vIndex = 0;

    function main()......

    var bState = getBarState();
    var vRawTime;

    if (bState == BARSTATE_ALLBARS){
    vInterval = getInterval();
    }

    vRawTime = getValue("rawtime")

    if(vInterval == null)
    return;
    if(vInterval == "D"){
    vIndex = (vRawTime/(60*60*24))
    }else if(vInterval == "W"){
    vIndex = (vRawTime/((60*60*24*7)))
    }else if(vInterval == "M"){
    vIndex = (vRawTime/((60*60*24*365.25)/12));
    }else{
    vIndex = (vRawTime/(vInterval*60))
    }

    ///////////////////////////////////////////////////////////
    Assigning x coordinates based on Time/Chart Interval Index
    ///////////////////////////////////////////////////////////

    function preMain()......

    var RP = null;
    var RPPoint = null;
    var RP1 = null;
    var RPPoint1 = null;
    var aRP = null;
    var aRPPoint = null;

    function main()......

    var bState = getBarState();
    var 0, o2;

    if (bState == BARSTATE_ALLBARS){
    aRP = new Array(2);
    o = 0;
    aRPPoint = new Array(2);
    o2 = 0;
    }


    Some parameter equal to a value

    RPPoint = vIndex;
    RP = (current close etc...);
    RPPoint1 = (aRPPoint[0]-RPPoint);
    RP1 = aRP[0];
    drawLineRelative(0,RP,RPPoint1,RP1, PS_SOLID, Thickness, Color, vIndex);


    // Fixing RP into Array
    if(o < 2) { // prime the array
    aRP[o] = RP;
    o++;
    return;
    }

    if(bState == BARSTATE_NEWBAR) {
    aRP.shift();
    aRP.push(RP);
    } else if(bState == BARSTATE_CURRENTBAR) {
    aRP[1] = RP;
    }


    // Fixing RPPoint into Array
    if(o2 < 2) { // prime the array
    aRPPoint[o2] = RPPoint;
    o2++;
    return;
    }

    if(bState == BARSTATE_NEWBAR) {
    aRPPoint.shift();
    aRPPoint.push(RPPoint);
    } else if(bState == BARSTATE_CURRENTBAR) {
    aRPPoint[1] = RPPoint;
    }


    /////////////////////////////////////////////////
    QUSETIONS
    /////////////////////////////////////////////////

    My questions are as follows:-

    A. How do you clear a previous drawn line considering the the line TagID is XXX

    B. Why do getCurrentBarIndex() or getOldestBarIndex() do not work properly.

    C. Can the code I put forward be made more efficient

  • #2
    Hi,

    getCurrentBarIndex() ; This should give bar index numbers starting at 0 for the current index with the amount incrementing negatively to the prior bar index and shouild update incremently as each bar is drawn. in my system this is never done.
    You might be saying this, but this isn't how I read the above so I just want to make sure we are all clear. The most current bar (rightmost on the chart) is zero, each new bar that arrives will be zero. The next most recent bar will be -1 and so on. So the leftmost bar on a chart will be the lowest numbered bar (have the highest negative value). If you aren't seeing this, something is wrong...almost all my formula's use this (if for nothing else other than debug), and all 100+ of them this works fine.

    Maybe what is thowing you is what happens with EFS with historical data. Before loading any EFS all bars are loaded first, so that the indexing is already done, the leftmost bar of data therefore was never really "0" from my EFS's perspective. In other words if I loaded an EFS on a chart with 60 bars, and if no new bars were drawn during the load, then the leftmost bar would be -59 to my EFS, and never be 0. Is this what you are seeing?
    Garth

    Comment


    • #3
      Concerning your first paragraph is correct in how the information is presented on my system.

      The problem rests with updating in real time where lets say, you have a chart running and you load a formula which say just displays getCurrentBarIndex() . The right most bar i.e. the current index will be displayed as 0 and all older bars will increment negatively ie. -1, -2 etc...

      When a new bar is drawn, the Current bar will be 0 however the previous bar will also be 0 and each bar thereafter will be -1, -2, -3 etc...

      And so it will go in this way (from right to left):-

      initial: 0, -1, -2 -3 etc....
      new bar1: 0, 0, -1, -2, -3 etc...
      new bar2: 0, 0, 0, -1, -2, -3 etc...

      When you reload the formula say when you at newbar2, the following is displayed:-

      0, -1, -2, -3, -4, -5 etc....

      I beleive that when each bar is drawn this kind of update should be done automatically. If it was done by the system then using
      drawlLineAbsolute() would work correctly.

      Comment


      • #4
        There is something wrong. I have never seen that. If you turn on "show bar index" in the cursor window (right click cursor window -> properties), does it show the same thing?

        either you have found a bug, your code is broken, or something else is wrong. If the above show the right index counts, then I would guess your code is broken somehow. If the above shows the same results you have found a bug. I would then verify I'm running the latest release, and if so, call it in.
        Garth

        Comment


        • #5
          I wrote a very simple efs file attached extracting just the routine to display the function output for:-

          getCurrentBarIndex();
          getOldestBarIndex();

          I did what you recommended and once new bars are drawn the output of the formula is out of sync with the Bar Count and Bar Index in the Cursor Window in the way I described before.

          For example (reading from right to left)

          First drawn

          Cursor Window Bar Count: 2500, 2500, 2500, etc...
          Cursor Window Bar Index: 0, -1, -2, etc....
          Formula getOldestBarIndex(): -2499, -2499, -2499, etc....
          Formula getCurrentBarIndex(): 0, -1, -2, etc....

          New Bar 1

          Cursor Window Bar Count: 2501, 2501, 2501, etc...
          Cursor Window Bar Index: 0, -1, -2, etc....
          Formula getOldestBarIndex(): -2500, -2499, -2499, etc....
          Formula getCurrentBarIndex(): 0, 0, -1, -2, etc....

          New Bar 2

          Cursor Window Bar Count: 2502, 2502, 2502, etc...
          Cursor Window Bar Index: 0, -1, -2, etc....
          Formula getOldestBarIndex(): -2501, -2500, -2499, etc....
          Formula getCurrentBarIndex(): 0, 0, 0, -1, -2 etc....

          And so on. I am running Version 7.1 Build 500. Before you ask that I should use 7.2, it totally bombs on my computer when running on certain formulas which run perfectly well on 7.1 and I don't have the time to bug test and rewrite my formulas.
          Attached Files

          Comment


          • #6
            Well, I would put a call into support. There is something wrong with your setup somehow. That is not the normal way it functions.
            Garth

            Comment


            • #7
              Hello rcameron,

              I've downloaded your efs and will take a look at it later this morning. We'll get this figured out.
              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


              • #8
                Jason, rcameron,

                Thanks for catching that Jason, I had totally misread the information he was presenting (I'm no good without my coffee - should have learned that by now). It looks more like a formula (or EFS) issue than an engine issue.

                Given that his formula listed below doesn't use getCurrentBarIndex or getOldestBarIndex, I'm not sure how looking at it will determine what is going on.


                Can you also put up your test .efs file?
                Garth

                Comment


                • #9
                  Garth

                  You will find the test efs file I have posted uses

                  getCurrentBarIndex();
                  getOldestBarIndex();


                  hoiweverr right now I am using the formula first put forward with generating my own index until we get this matter sorted out as drawLineAbsolute() was very precise in drawing lines compared to drawLine Relative() but of mcourse I had to keep reloading the formula to get the the lines to be updated correctly because of the problem with getCurrentBarIndex().

                  Robert

                  Comment


                  • #10
                    Well...

                    Ok I downloaded and ran the test formula. I added some debug statements, as plotting the values will only show the historical values and not update as new records come in (Hence you see 0, 0, -1, etc).

                    If you do use debugPrintln(() to print the values, you will see they update correctly (or at least they do here).

                    There is one odd thing going on, and that is that getOldestBarIndex() is reporting the right numbers in the debug prints, but is not accurately reflected in the latest values on the plot. I'm not sure why that is, but clearly EFS logic based on getOldestBarIndex() will work, as the variable does have the right info.

                    G
                    Garth

                    Comment


                    • #11
                      Garth,

                      Can you tell me how to integrate debugPrintln() ? statements to test it for myself.

                      From what you have seen is exactly what i am seeing. However when you want to use the values from getCurrentBarIndex() into DrawLineAbsolute() it will only be correct for a moment. when new bars are drawn the lines are advanced bara by bar instead of being fixed to the x coordinates when first drawn. to get the lines back to their original positions you have to reload the formula which is not what should be done.

                      IMO getCurrentBarIndex() should update in the smae way as the index count in the cursor Window without resetting the formula.

                      Robert

                      Comment


                      • #12
                        Hi,

                        debugPrintln() is like debugPrint() except it does an auto CR/LF (or newline (/n) if you are more familiar with that term).

                        So:

                        nIndex = getCurrentBarIndex();
                        nBarCount = getOldestBarIndex();

                        debugPrintln("This is the current index: " + nIndex + " and this is the oldest bar index: " + nBarCount);

                        Would print the current index and oldest bar count, with some ascii text before it to let you know which is which.

                        DrawLineAbsolute() does just that. It draws lines at an absolute location, and those lines don't move as new bars are created. DrawLineRelative() will move as new bars are created. One is chart centric (DrawLineAbsolute) and the other is time centric (DrawLineRelative).

                        This thread talks about it:

                        http://forum.esignalcentral.com/showthread.php?s=&threadid=439

                        getCurrentBarIndex() does update as the cursor window, but your plot of it will not update as the historical plot information will not be updated, only the current bar. This is why I used debugPrintln() to see what is really going on.
                        Garth

                        Comment


                        • #13
                          Hello rcameron, Garth,

                          No need to contact Tech Support. I’ll do my best to explain what is happening here.

                          There is nothing wrong with the code. It is doing what it is supposed to. The problem here is that the value of the lines that are drawn in the indicator pane aren’t updated to reflect each bar’s new index number every time a new bar comes in.

                          For example, let’s say we are using a 1-minute interval and our chart is in dynamic mode. When you first apply the formula to the chart it only loads a certain number of bars. The oldest index number might be something like –650. So we have one flat line at –650 for the entire chart. The other line plots each bar’s index value so we get a line that is sloped from –650 to 0. At the instance a new bar starts, the historical values of the lines don’t change but the index numbers for all of the bars do. The line that plots the current bar index now becomes a flat line at 0 going forward because the most current bar’s index is always 0. Likewise, the bar that is 2 bars old always has a bar index of –2. Add the following line of code right before the return statement. Make sure the formula output window is open and then reapply the formula.

                          debugPrintln("Current Bar Index: " + getCurrentBarIndex() + " Close at Bar Index -1 = " + close(-1));

                          The bar indexes are always based off the most current bar. Therefore close(-1) will always give you the close of the bar that is one bar (interval) old.

                          The oldest bar index increments by 1 every time a new bar starts because we are adding bars to our chart. That’s why its line begins sloping down as new bars come in.

                          If you want to keep track of a specific bar as time goes by and new bars are added to the chart, you need to increment a global variable that keeps track of what that bar’s index value changes to.

                          var myBar = 0;
                          function main() {
                          if (getBarState() == BARSTATE_NEWBAR) {
                          myBar -= 1;
                          }
                          }

                          Did this help?
                          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


                          • #14
                            drawing a horizontal line

                            is there any EFS to draw a horizontal line with the value is current price (lenght, style, color and width are adjustable woud be great)

                            Comment


                            • #15
                              Hello nkhoi,

                              The attached formula should give you a good example of how to create what you need.
                              Attached Files
                              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