Announcement

Collapse
No announcement yet.

Previous Bar Index Question

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

  • Previous Bar Index Question

    Hi,

    I have a question about storing the CurrentBarIndex and use it in the future.
    Is this possible?

    Typical case is when a condition is detected now (say, a pivot) and I want to refer to this bar info/data later, but don't know when and I don't know which data/info I will use (close, ADX, MACD, or ???).

    I assume that the Index of that bar changes as new bars come in (I am talking about real time situation not after hours accademic testing, when indexes are fixed).
    Also, updating Bar Index on NEW_BAR is not a good solution as I can have a number of such bars.

    Anyone can help? Greatly appreciated.
    Thanks,
    Mihai
    Last edited by mbuta; 05-30-2004, 11:37 AM.
    Mihai Buta

  • #2
    Yes, I store this information in an array. You can determine the current barcount by tracking it using one of these two methods:

    if (getBarState() == BARSTATE_NEWBAR){
    barcount++;

    or

    barcount = Math.abs(getOldestBarIndex()); edit - this only works in RT for determination of barcount, when processing historical bars it returns the number of bars in the chart

    then if you have to plot from a previous pivot, you can reference the number of bars before the current by adding getOldestBarIndex() (which is negative).

    For example, 5 bars ago where barcount = 3300, the barcount is now 3305, what you do is subtract the current barcount from the previously recorded barcount to determine your back reference from the current bar, which is zero.

    for example

    x1_ur = lsf_hi[0]+getOldestBarIndex();
    y1_ur = lsf_hi[1];
    x2_ur = lsf_hi[2]+getOldestBarIndex();
    y2_ur = lsf_hi[3];
    addLineTool(LineTool.RAY, x1_ur , y1_ur , x2_ur , y2_ur , 2, Color.blue, "line");


    In this example, the x values were previously recorded values of the barcount.
    Last edited by Guest; 05-31-2004, 10:19 AM.

    Comment


    • #3
      Hi Steve and thank you for your reply.

      What you are saying (and I did not check that yet, can't do it off-hours) is that the BarCount (which I do track, by the way) does not stop at the number of bars in chart (as I thought, because i never use Dynamic templayes).

      In other words, if I have 200 bars in chart, during the day, the BarCount can get to 3300, to use your number.
      If this is true, of course it works, thank you.

      For now, I used a "fake method": I store the time the event occured, as BarIndex, then I calculate how many bars ago it happened, based on CurrentTime and Interval of the chart.

      Your way is, obvioulsy, the better one.
      Please confirm please that my interpretation is correct.

      Thnaks,
      Mihai
      Mihai Buta

      Comment


      • #4
        Mihai,

        You are welcome. For historical (not live) data, the command

        barcount = Math.abs(getOldestBarIndex());

        provides the same number regardless of the number of bars that have been processed to date. It is not suited for determination of barcount per-se for historical data. It does work in historical and real time for the purpose of referencing the relative location of a previous bar as in this example snippet

        x1_ur = lsf_hi[0]+getOldestBarIndex();
        y1_ur = lsf_hi[1];
        x2_ur = lsf_hi[2]+getOldestBarIndex();
        y2_ur = lsf_hi[3];
        addLineTool(LineTool.RAY, x1_ur , y1_ur , x2_ur , y2_ur , 2, Color.blue, "line");


        where the previous bar was determined using

        if (getBarState() == BARSTATE_NEWBAR){
        barcount++;}


        What I would suggest is that you save the historical barcount using a counter internal to your code, similar to what I showed directly above, then when it comes time to refer back to the historical point, add getOldestBarIndex() to the historical bar and verify the numbers match up with yours.

        I use this method exclusively, and it works well for me. Hopefully, it suits your methods as well
        Last edited by Guest; 05-31-2004, 10:21 AM.

        Comment

        Working...
        X