How to Stop an Indicator from Running on Every Tick and Execute Only on New Can

Forums ProRealTime English forum ProRealTime platform support How to Stop an Indicator from Running on Every Tick and Execute Only on New Can

Viewing 3 posts - 1 through 3 (of 3 total)
  • #242209

    Description:
    I am working on a custom indicator in ProRealTime, and I want it to execute only once when a new candle is formed, rather than recalculating on every tick. Currently, the indicator logic is running for every tick movement, which is not what I intend.

    Here’s the logic I’ve implemented:

    // Declare a variable to store the last processed bar index
    if not defined lastBarIndex then
    lastBarIndex = 0
    endif

    // Check if a new candle has formed
    if barindex > lastBarIndex then
    // Indicator logic
    randomValue = random // Example: Generate a random number

    // Update the last processed bar index
    lastBarIndex = barindex
    endif

    // Return the result
    RETURN randomValue

    However, the issue is that the random value (or any calculation) is still being generated on every tick movement, instead of being updated only once per new candle.

    Questions:

    1. How can I ensure the indicator runs only once per new candle?
    2. Is there a specific way to define or handle persistent variables (lastBarIndex) to prevent them from being reinitialized on every tick?
    3. Is my approach of using barindex to track candle changes correct, or is there a better method?

    I’d appreciate any guidance or examples from the community. Thank you!

    #242216

    Description:

    I am working on a custom indicator in ProRealTime, and I want it to execute only once when a new candle is formed, rather than recalculating on every tick. Currently, the indicator logic is running for every tick movement(i’m using 200 tick based chart), which is not what I intend.

    Here’s the logic I’ve used to stop executing my whole code on every tick movement:

    if opentimestamp<>$lastopen[0] then
    $lastopen[0]=opentimestamp
    drawhline(high[2])
    endif

    However, the issue is that ‘horizontal line’ is automatically forms and being deleted within few milliseconds of new candle start.Even i have tried with ‘DRAWSEGMENT’,DRAWARROWUP’ etc same thing happening.Since my indicator to much resource heavy i want it run on new candle only and older drawing should remain as it is.

    I’d appreciate any guidance or examples from the community. Thank you!

     

    #242226

    IsLastBarUpdate might be what you need:

     

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

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