Optimizing Daily Entry, Exit, and Stop Levels from Intraday Stock Data
Summary
The document describes a proposed daily long-only stock strategy with three percentage-based thresholds: an entry below the opening price, a stop loss below the entry, and a profit exit above the entry. Each threshold triggers when the observed price crosses it. The strategy permits one completed trade per day and liquidates any open position at that day's close.
The author wants to choose the threshold values that maximize cumulative returns over historical days, using intraday open, high, low, and close candles at five-minute intervals. They report that a general-purpose numerical optimizer was too slow and ask whether a more efficient method exists. The document does not provide a solution, compare optimization algorithms, or show backtest results. Any threshold search based on this setup would also depend on how candle data resolves the order of intrabar threshold touches, and the described objective alone does not account for trading costs or out-of-sample performance.
Key ideas
- The proposed strategy enters long after a specified decline from the daily open.
- A stop loss and profit target are defined as percentage moves from the entry price.
- Any position still open at market close is sold at the closing price.
- The author seeks parameter values that maximize historical cumulative returns using five-minute candles.
- The document poses an optimization question and provides no algorithm or performance evidence.
Tags
Full text
# Optimal Entry, Exit, And Stop Loss From Historical Stock Data # Optimal Entry, Exit, And Stop Loss From Historical Stock Data I'm trying to build a system that recommends stock trades. My goal is calculate optimal values for the following: > Entry Parameter: expressed as a percentage change downwards from the opening price. Our entry price = (opening price) * (1 - this parameter). The first time the stock price reaches this price or below, we will buy. Stop Loss Parameter: expressed as a percentage change downwards from the entry price. Our stop loss = (entry price) * (1 - this parameter). The first time the stock price reaches this price or below while we are long, we will sell for a loss. Exit Parameter: expressed as a percentage change upwards from the entry price. Our exit price = (entry price) * (1 + this parameter). The first time the stock price reaches this price or above while we are long, we will sell for a profit. We are limited to one full trade per day. If we have bought, but not sold, by market close, we will sell at the closing price that day. I would like to calculate these using historical data. That is, based on some number of trading days, I want to efficiently calculate values for these parameters that would have maximized my total return over those trading days. I have already tried using scipy.optimize, but this takes too long to be useful. Is there another system I could utilize that would determine these values more efficiently? Is there an existing algorithm to determine this? Addendum: My historical data is stored as a list of Pandas DataFrames. Each DF is made up of 5 minute candles. Each row contains a timestamp (the end of that candle), as well as the Open, High, Low, and Close price for that candle. I am not married to this; other formats would be acceptable, if easier to work with.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.