Announcement

Collapse
No announcement yet.

How to retrieve the bar index of the bar resulting from a lowerDonchian calculation?

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

  • How to retrieve the bar index of the bar resulting from a lowerDonchian calculation?

    Given the definition

    var LowestLow = lowerDonchian(11, low(), -9);

    How does one with EFS code retrieve the bar index of the bar lowerDonchian calculates to be the bar possessing the lowest low?

  • #2
    Foober
    You would do that using a for loop that starts its count at the offset that you set for the Donchian Channel (ie -9) and ends at the length of the Donchian Channel plus the offset (ie 11+9).
    The first step is to declare two variables one that will hold the starting Low value (that will be used in the for loop) and the other that will hold the bar index (these are both local variables)
    PHP Code:
    var vValue low(-9);
    var 
    Bar(Index 0
    Then set up the the for loop
    PHP Code:
    for (var 9i11+9i++){ 
    At this point you determine the lowest value in the loop
    PHP Code:
    vValue Math.min(vValuelow(-i)); 
    Then (while still in the loop) you find the condition where a Low matches the lowest Low in that loop and you assign to the variable barIndex the index of that bar
    PHP Code:
    if(vValue==low(-i))
        
    barIndex getCurrentBarIndex()-i;
    }
    //end of loop 
    The variable barIndex will now hold the index of the bar that matched the Lower Donchian Channel.
    You can find a complete example of this logic in this thread
    If you encounter any problems with your code post what you have done and someone will be available to assist you in fixing it
    Alex

    Comment

    Working...
    X