Optimized Way to Find Last Connected Overlapping Wick (Without Full Loopback Tra

Forums ProRealTime English forum ProRealTime platform support Optimized Way to Find Last Connected Overlapping Wick (Without Full Loopback Tra

Viewing 4 posts - 1 through 4 (of 4 total)
  • #244365

    I’m working on an indicator that needs to find the highest overlapping wick of any candle and dynamically update a variable (highestConnectedWick). The problem is that my current approach requires looping back through all previous candles to check for wick connections, which makes my indicator slow or even freeze when applied to many bars.

    Currently, I’m using a standard for/while loop to traverse back and check if:

    • The high of a previous candle overlaps with the highest wick found so far.
    • The body of any previous candle overlaps with this highest wick (which stops the search).

    However, this method is inefficient as it runs O(n) loops for every bullish/bearish engulfing pattern, leading to performance issues.

    What I Need:

    I am looking for an optimized approach that does not rely on a full backward traversal using a for/while loop every time a new candle is processed. Instead, I would prefer:

    • Memoization or caching: Store the highest connected wick values to avoid redundant calculations.
    • Binary search or another fast lookup method: To quickly find the relevant wick instead of checking all previous candles.
    • Any other ProRealTime-specific function that can efficiently track the last connected overlapping wick.

    I must be able to look back as far as needed if no body overlap is found, but I don’t want to traverse linearly through all past candles every time.

    Any suggestions or alternative solutions in ProRealTime code? Thanks in advance! 🚀

    #244367
    JS

    You could try this approach:

    2 users thanked author for this post.
    #244371

    If I understood correctly, you want to detect groups of connected wicks dynamically without scanning all previous candles each time.

    The following code is a simplified version that only calculates the highest wick within each group of connected wicks, without drawing any visual elements.

    1 user thanked author for this post.
    #244392

    I’m realy sorry  JS wrote: Iván wrote:  for not being able to explain my question here i have attached screenshot of given you two example assume that marked number are their  respective barindex

    1.  Highest connected wick candle’s barindex for candle ‘0’ is ‘0’ because candle ‘0’ upper wick is overalpping with body of candle ‘1’ so barindex ‘0’ is my answer.
    2. Highest connected wick candle’s barindex for candle ‘1’ is ‘9’ because candle ‘1’ upper wick is overlapping with upperwick of ‘2’ and ‘2’ upper wick overlapping with ‘3’ and so on we wiil keep looking ‘up’ and ‘left’ as long as  candles uppper wicks are loverlapping and stop when there is body overlap with wick(which happens at ’10’) and return barindex  ‘9’ as my answer.

    You can see that for candle ‘1’, ‘2’,’3’…. till  ‘9’ all of them has answer  ‘9’. You might notice that there are unmarked candle in between ‘3’ to ‘4’ and ‘8’ to ‘9’ because we need to look straight left from high of the candle.

    P.S- My general for/while loop  run through all the previous candles checking is making my whole indicator slow.So i need efficient way which is <= O(n) because i’m doing this query so many time in my indicator.

    Thank you!

Viewing 4 posts - 1 through 4 (of 4 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login