Skip to content
All library documents

EMA Crossover Trading with Entry and Exit State Rules

Article FMZ forum · Author: shindou

Summary

This Python-style example outlines a state-based trading loop driven by fast and slow exponential moving average crossovers. While flat, it checks an entry crossover and opens a long position for an upward cross or a short position for a downward cross, provided the crossover observation threshold is met. Position size is set as a proportion of the account’s stock balance. While holding a position, it checks a separate pair of exit averages and closes when their crossover points against the current direction, subject to an exit threshold.

The example also logs account information and profit after closing, then pauses for a configurable interval before checking again. It illustrates basic signal handling, position sizing, and long/short state tracking, but provides no market, timeframe, parameter values beyond defaults mentioned in comments, or backtest results. It does not discuss transaction costs, slippage, risk limits, or whether the account interface handles short positions as intended, so the code alone does not establish profitability or suitability.

Key ideas

  • The strategy uses separate fast and slow EMA pairs for entry and exit signals.
  • An upward entry crossover opens a long position, while a downward crossover opens a short position.
  • A configurable threshold filters crossover observations before trades are opened or closed.
  • Position size is calculated as a fraction of the account’s stock balance.
  • The example logs account and profit information but provides no backtest or risk analysis.

Tags

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