Skip to content
All library documents

Updating a Trading Bot After a Manual Position Closure

Article FMZ forum · Author: 转角

Summary

This short example shows how an automated trading script can detect that both long and short positions have become flat, then respond when its internal state still indicates an active trade. It compares the current account balance with the previously saved balance to classify the closed position as a win or loss, updates a counter, logs cumulative profit and a percentage return relative to the initial balance, saves the latest account snapshot, and resets the strategy state to idle.

The method addresses coordination between manual intervention and a bot’s state tracking. The example notes that entry handling could follow a similar approach, but does not provide that implementation. It also leaves important details unspecified, including how account balance changes caused by deposits, withdrawals, fees, or other activity are distinguished from trade outcomes. As presented, it is a compact state-management illustration rather than a complete execution or performance-accounting system.

Key ideas

  • The script detects a flat account when neither a long nor a short position remains open.
  • If the bot still considers itself active, it compares current and saved account balances to classify the outcome.
  • It records a win or loss, logs cumulative profit and return, saves the account snapshot, and returns to idle.
  • The example does not show how to detect manual entries or separate trade results from unrelated account balance changes.

Tags

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