Using Trading-Day Lookbacks for a Trailing Stop
Summary
This Chinese-language knowledge post explains a mismatch in a sample trailing-stop calculation. The code obtains a holding duration by subtracting the position’s last sale date from the current date, which yields calendar days. It then passes that duration to a daily history request, where the lookback is interpreted as a count of trading bars. Because weekends and market holidays are included in calendar time but absent from daily trading data, the requested history may not cover the period since entry.
The example sets a stop line 10% below the highest high in the requested history and closes the position if the current price falls beneath it. The post asks how to obtain the correct number of trading days but provides no answer or replacement method. Its useful lesson is to align date-based holding periods with the bar-count semantics of the data API; the example does not establish that the stop rule itself is effective.
Key ideas
- Subtracting dates produces calendar days, which can differ from the number of daily trading bars.
- A daily history request may therefore return a window that does not span the full period since entry.
- The example places a stop 10% below the highest high in its requested lookback.
- The document identifies the lookback mismatch but does not give a corrected implementation.
- The effectiveness of the trailing-stop rule is not tested or demonstrated.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.