Skip to content

Strategy function evaluates the next bar #31

Description

@takumi-miyajima

Describe the bug

The bar evaluated in the strategy function is using the value of the next bar in the future.

To Reproduce

Create a simple strategy:

"""
@pyne
"""

from pynecore.lib import bar_index, open, script, strategy


@script.strategy()
def main():
    if bar_index < 10:
        print("----------------------------------------")
        print("bar_index=", bar_index, " open=", open)

    if bar_index == 3:
        strategy.entry(id="unique-trade-id", direction=strategy.long)

    return {}

Add a debug print statement in pynecore/lib/strategy/__init__.py:534:

        print('pynecore/lib/strategy/__init__.py:534')
        print('price=',price, ' h=', h, ' l=', l)

Execute the script:
uv run pyne run simple ccxt_kraken_USD_JPY_15

Expected behavior

The strategy should use the value of the current bar.

Screenshots

Execution log:

Image

Environment:

  • OS: macOS
  • Version: 15.5 (24F74)
  • Python version: 3.13
  • How you ran the script: cli pyne run

Additional context

version:

name = "pynesys-pynecore"
version = "6.3.1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions