Skip to content
All library documents

A Spot Trading Bot That Adds to Positions and Uses Profit Targets

Article FMZ forum · Author: 发明者量化-小小梦

Summary

This code commentary explains a directional spot trading bot that can open either a long or short position, add to the position as price moves against it, and close when a profit target or stop-loss condition is reached. It exposes settings for order size, execution style, price slippage, maximum order size, spacing between adds, target average entry price, polling interval, and restoration of a prior position. The code also tracks realized and floating profit, position size, and counts of successful cycles, recoveries, and stop losses.

The bot retries exchange calls, cancels stale orders, and can rebuild its accounting state after restart. The article is a partial code excerpt, so key portions of the position-management loop are omitted and its full behavior cannot be verified from the text. It provides no backtest or live trading evidence. Its own notes limit use to spot trading and flag exposure to adverse price movement; adding to losing positions can increase inventory and losses, while stop-loss settings do not by themselves demonstrate controlled risk.

Key ideas

  • The strategy trades in one direction at a time and can add to a position after adverse price movement.
  • It uses configurable profit and stop-loss thresholds alongside order-size and spacing controls.
  • Order handling includes retries, stale-order cancellation, and optional position restoration.
  • The excerpt is incomplete and contains no performance evidence, so the strategy's results cannot be assessed from it.

Tags

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