Announcement

Collapse
No announcement yet.

getCurrentBarIndex() return wrong bar index !!!

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

  • #16
    Simple Solution...

    Use the following code to begin counting bars on the chart. This will give us a running count of the bars as we progress through the chart...

    PHP Code:

    var nLastRawtime 0;
    var 
    BarCount 0;

    function 
    main() {

      if (
    getValue("rawtime",0) != nLastRawtime) {
        
    BarCount += 1;
        
    nLastRawtime = (getValue("rawtime",0); 
      {


    This gives us an ability to use a simple deduction of the current barcount and the bar # of a signal...

    For example...

    PHP Code:

    var nLastRawtime 0;
    var 
    BarCount 0;
    var 
    LastPeak null;
    var 
    LastPeakPrice null;

    function 
    main() {

      if (
    getValue("rawtime",0) != nLastRawtime) {
        
    BarCount += 1;
        
    nLastRawtime = (getValue("rawtime",0); 
      {

    //  record the bar number of a peak
      
    if ((high() < high(-1)) && (high(-2) < high(-1))  ) {
        
    LastPeak BarCount;
        
    LastPeakPrice high(-1);
      }

    //  Now for the graphics part...
    //  We can determine the actual "negative" bar number for drawing graphics by using...

    //         LastPeak - BarCount = Graphic X Location.

      
    if ((LastPeak != null) && (LastPeakPrice != null)) {
        
    DrawLineRelative((LastPeak BarCount), LastPeakPrice0high(), PS_SOLID1Color.blue"PeakLine");
      }


    By using...

    BarNumber - BarCount

    to calculate the proper location of the item to draw, we can continually update and re-draw items as needed. All we need to do is record the barcount and price item.

    Hope this helps..

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #17
      Hi Brad

      Thanks for the tips.

      My guess is that your coding for BarCount would work for intervals >= 1 second but not for tick interval since "rawtime" in seconds. I'll try to see anyway.

      Cheers
      Dzung

      Comment

      Working...
      X