Handling Missing Dates in a Trailing Stop Data Lookup
Summary
This forum post documents a failure in a stock strategy’s trailing-stop routine. The routine reads each position’s last sale date, subtracts it from the current date to estimate holding days, and uses that value as the bar count when requesting historical highs. When the position date is missing, the subtraction produces an invalid value; the history call then fails because its bar-count argument must be an integer.
The example also shows a 7% trailing stop based on the highest high since entry, with a sale when the current price falls below the stop. The discussion identifies a missing Wind data-service dependency as a separate possible setup issue, but the reported runtime error is tied to the invalid date-derived bar count. The post does not provide a complete code fix or validate the stop strategy’s performance. It is useful as a debugging case about checking position dates and ensuring history lookback arguments are valid before querying price data.
Key ideas
- The example sets a trailing stop 7% below the highest high since the position was opened.
- It estimates the historical lookback from the difference between the current date and the position’s last sale date.
- A missing date can yield an invalid holding-period value and cause a history lookup to reject its bar count.
- The discussion also mentions checking whether the Wind integration is installed and configured.
- The post provides no complete repair or performance analysis of the stop method.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.