Spot Moving-Average Crossovers with a Long-Position Stop
Summary
This spot strategy generates signals from a fast and a slow moving average. It identifies a bullish crossover using completed bar values rather than the current bar, which is intended to avoid signals that flicker while a bar is forming. A bullish cross opens a long position when the recorded position is below the configured minimum size; a bearish cross closes an existing long. Trades are submitted at the current bar's opening price, and the code tracks equity and realized profit for logging.
A separate stop closes a long position if the bar's low reaches the recorded entry price multiplied by a configured stop factor. The implementation records entry price locally because the exchange interface described does not provide an average holding price. This means a restart resets that value, which can undermine stop handling for an existing position. Although a short-stop parameter is present, the shown logic does not open or manage short positions. The document provides no backtest results, and its behavior depends on data timing and exchange execution.
Key ideas
- A fast and slow moving average crossover supplies the entry and exit signals.
- Signals use prior completed bars to reduce flickering during an unfinished bar.
- Long entries and exits are submitted at the current bar's opening price.
- A price-based stop closes the long if the bar low reaches the configured threshold.
- The entry price is stored locally and resets if the strategy restarts.
- The shown logic does not use its short-stop parameter or implement short trades.
Tags
From a private course collection; the original is not published.