Skip to content
All library documents

Diagnosing Stop-Loss and Repeated-Order Issues in a Pine Strategy

Article FMZ forum · Author: Fland

Summary

The document shows a Pine Script strategy that enters long when a short-period RSI crosses below a threshold, then closes when price rises above an exponential moving average or falls to a fixed percentage below the recorded entry price. The author’s question concerns a stop that appears not to execute in backtests but does execute live, followed by repeated opening and closing that no longer seems to follow the intended conditions.

The example highlights implementation details worth checking when debugging: the stop is evaluated using the bar’s closing price, the entry price is stored when the signal fires, and both exit conditions use market-close commands. Those choices may not behave like an intrabar protective stop, and the stored entry price may need careful synchronization with actual fills and later trades. The document gives no diagnosis, corrected code, or test results, so it frames a troubleshooting problem rather than establishing why the behavior occurs. Differences between historical simulation and live execution also depend on platform settings and order handling.

Key ideas

  • The example combines an RSI threshold crossing for long entries with an EMA-based exit condition.
  • Its stop condition checks the bar close against a price derived from the recorded entry price.
  • Backtest and live behavior can differ when stop evaluation and order execution use different timing assumptions.
  • The document raises a debugging question but does not provide a confirmed cause or repair.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.