Handling Premature Loop Exit and Final Candle Evaluation in Tick Charts

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #241410 quote
    shiv55
    Participant
    New

    I’m working with tick-based charts (e.g., 100-tick and 300-tick) in the ProRealTime code editor and encountering an issue with my logic. Here’s a simplified version of my code:

    prorealcode
    IF (  Low[BarIndex - j] < firstLow AND Close[BarIndex - j] > firstLow AND Open[BarIndex - j] < Close[BarIndex - j] ) THEN
    BREAK
    ENDIF

    The issue arises when:

    1. Within a tick candle (e.g., the 100-tick candle), my condition is met at some intermediate tick (e.g., the 24th tick), causing the loop to BREAK.
    2. However, by the time the 100-tick candle fully forms, the overall condition of the candle (e.g., whether it’s red or green) changes. Since the loop has already exited, I miss this updated result.

    This problem doesn’t occur with time-based charts, as conditions are evaluated only at the close of a candle.

    Question:
    How can I modify my logic to ensure that:

    1. The condition is evaluated only after the full 100-tick or 300-tick candle is formed?
    2. The loop doesn’t exit prematurely, but I can still track intermediate conditions if needed?

    Any help or suggestions for handling this issue would be greatly appreciated. Thank you!

    #241488 quote
    JS
    Participant
    Senior

    Hi, You can create two indicators for this: the first one as it is now with the “break,” showing an “interim” result, and for the other indicator, you could “count” the ticks and display the result after, for example, 100 ticks… With this indicator, you can count the number of ticks…

    defparam drawonlastbaronly=true
     
    if opentimestamp<>$lastopen[0] then
    $lastopen[0]=opentimestamp
    $count[0]=0
    endif
    if close<>$close[0] then
    $close[0]=close
    $count[0]=$count[0]+1
    drawtext($count[0],-20,-20) anchor(topright)
    drawhline(close)
    endif
     
    return
    Iván González, robertogozzi and shiv55 thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Handling Premature Loop Exit and Final Candle Evaluation in Tick Charts


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
shiv55 @shiv55 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JS
1 year, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/14/2024
Status: Active
Attachments: No files
Logo Logo
Loading...