[Python] Issues with Persistent Variable Handling in for ORB Indicator

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to convert an Opening Range Breakout strategy from Pine to TakeProfit's Indie but I’m having issues with persistent variable handling. I’ve tried several approaches but I’m still getting errors.

    Original PineScript code

    //@version=5
    strategy("ORB FVG Pro", overlay=true)

    // Parameters
    startTime = input.int(930, "Start Time", minval=0, maxval=2359)
    endTime = input.int(945, "End Time", minval=0, maxval=2359)
    atrMultiplier = input.float(0.3, "ATR Multiplier", minval=0.1, step=0.1)
    entryBars = input.int(3, "Entry Window", minval=1)

    // Indicators
    atr = ta.atr(14)
    emaFilter = ta.ema(close, 9)
    vwap = ta.vwap(hlc3)
    volumeFilter = volume > ta.sma(volume, 20) * 1.3

    // Time logic
    timeInRange() =>
    t = hour * 60 + minute
    t >= (startTime/100)*60 + (startTime%100) and t <= (endTime/100)*60 + (endTime%100)

    // Opening Range
    var float orbHigh = na
    var float orbLow = na
    var bool orbValid = false

    if timeInRange()
    if not orbValid
    orbHigh := high
    orbLow := low
    orbValid := true
    else
    orbHigh := math.max(orbHigh, high)
    orbLow := math.min(orbLow, low)
    else if dayofmonth != dayofmonth[1]
    orbHigh := na
    orbLow := na
    orbValid := false

    // Breakout Logic and rest of the strategy...


    My attempt in Indie

    # indie:lang_version = 4
    from indie import indicator, param, plot, color, MutSeriesF
    from indie.algorithms import Atr, Ema, Sma

    @indicator("ORB FVG Pro Visualization", overlay_main_pane=True)
    @param.int('start_time', default=930, min=0, max=2359, title="Start Time")
    @param.int('end_time', default=945, min=0, max=2359, title="End Time")
    @param.float('atr_multiplier', default=0.3, min=0.1, title="ATR Multiplier")
    @param.int('entry_bars', default=3, min=1, title="Entry Window")
    @plot(color=color.YELLOW, title="ORB High")
    @plot(color=color.NAVY, title="ORB Low")
    @plot(color=color.LIME, title="Breakout High")
    @plot(color=color.MAROON, title="Breakout Low")
    @plot(color=color.GREEN, style=plot.style_circles, title="Long Signal")
    @plot(color=color.RED, style=plot.style_circles, title="Short Signal")
    def Main(self, start_time, end_time, atr_multiplier, entry_bars):
    # Indicators
    atr_value = Atr.new(14)[0]
    ema_value = Ema.new(self.close, 9)[0]

    # Persistent series - this is where I'm struggling
    orb_high = MutSeriesF.new(float('nan'))
    orb_low = MutSeriesF.new(float('nan'))
    orb_valid = MutSeriesF.new(0)
    prev_day = MutSeriesF.new(0)
    entry_count = MutSeriesF.new(0)

    # Time conversion
    current_minutes = self.hour[0] * 60 + self.minute[0]
    start_minutes = (start_time // 100) * 60 + (start_time % 100)
    end_minutes = (end_time // 100) * 60 + (end_time % 100)
    in_time_range = current_minutes >= start_minutes and current_minutes <= end_minutes

    # Remainder of the code...


    Cause

    Error: [internal]


    I’ve tried using MutSeriesF, checking bar_index and other patterns but I’m still getting error.
    Error: [internal]
    Any help or examples of proper persistent state handling in Indie would be appreciated.


    1. How to handle persistent variables in Indie that is equivalent to Pine’s var float orbHigh = na?


    2. Is there a special syntax for day-to-day persistence in Indie?


    3. How to track state across bars in Indie indicators?


    4. Is there documentation on how to convert PineScript’s code to Indie syntax?

    Continue reading...

Compartilhe esta Página