Skip to content

Open a limit order at a certain time #502

Closed
@sword134

Description

@sword134

Hello,
I am trying to open a long limit order when the time is between 2:55pm and 3pm and only in that timeframe.

In raw python it would look like this, where x is my index column in my dataframe.

def time_in_range(x):
    start = time(14, 55)
    end = time(15 0)
    x = datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
    """Return true if x is in the range [start, end]"""
    if start <= end:
        return start <= x <= end
    else:
        return start <= x or x <= end

I am however unsure how I would make it in the backtesting library? How do I open a long limit order when the time is between 2:55pm and 3pm and then close it say 10 minutes later if it hasn't been filled?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions