Risk & position-sizing checksIntermediate#position-sizing#checklist#python#long-only

Check an add to an open position against your written add rules first

Before you add to an existing long, a script recomputes the combined position's risk at the current stop and checks your own add rules, such as adding only when the first part shows open profit. It reports; you decide.

How it works

  1. Write your add rules as numbered, checkable statements, for example: an add is allowed only if the current stop is at or above the first entry, the combined open risk at the stop is no more than the initial risk of the first part, and there are at most two adds per position.
  2. Keep each open position's fills (quantity and price per part) and its current stop in your own positions file.
  3. When you're considering an add, give the script the planned add quantity and the price you expect, plus the new stop if you'd raise it.
  4. The script computes the average cost, the combined quantity, the combined risk at the stop in account currency and in R of the original position, and the number of adds so far, then checks each numbered rule as met or not met.
  5. It prints the figures and the rule table. You decide, and the check line goes into your journal with your decision.

Copy-paste prompt

Write a Python script that checks a planned add to an open long position against my rules. It gives no trading advice and never says whether to add.
Inputs: {{positions_csv}} (position_label, part, quantity, fill_price), {{stops_csv}} (position_label, current_stop), {{initial_risk_csv}} (position_label, initial_risk_amount), and arguments position_label, add_quantity, expected_price, optional new_stop.
Compute: combined_quantity, average_cost, combined_risk = Σ part quantity × (part fill price − stop) using the new stop if given, combined_risk_in_R = combined_risk ÷ initial_risk_amount, adds_so_far.
Check each rule in {{add_rules}} and print met or not met with the numbers used. A negative risk figure means the stop is above that part's cost; show it, don't hide it.
Print one journal line and append it only after I confirm. No broker connection, no orders. Include two test cases I can check by hand.

Guardrails

  • The rules are yours and written in advance; the script never proposes an add or a size.
  • All figures are computed in code from your files, never typed by a model.
  • The script reads files and appends one journal line after you confirm; it has no broker access.

What can go wrong

The first version measured risk only on the new part, so an add looked small while the whole position's risk at the stop had nearly doubled. Measuring the combined position against the original R fixed it. Rules like 'the first part shows open profit' also need a number (open profit of at least 1R, say), or the check can't be run.

Why it helps

Adding to a working position is one of the few in-trade decisions that raises risk, and it tends to be made when you feel most confident. Seeing the combined position's risk at the stop, in R of the original trade, next to your own add rules, keeps the decision inside the limits you set when you were calm.

How it fits with other entries

The pre-trade sizing check (aft-0008) covers new positions and portfolio heat; this is the same discipline for adds to an existing one. The management ledger (aft-0059) records the add after it happens, and the overnight gap check (aft-0050) shows what the larger position would cost if it opened beyond the stop.

Where this comes from

Investopedia's explainer on pyramiding (adding to a position) and the SEC investor bulletin on stop orders, as background. The add rules, R measure and check are ours.

Source and references

Original write-up by Agents for Traders. Background reading is linked below.

Spotted an error, or want your post removed? Email hello@agentsfortraders.com.

Educational content only. Not investment advice or a personal recommendation. No tickers, signals or trade alerts. Trading involves risk of loss.

Conteúdo exclusivamente educativo. Não constitui aconselhamento nem recomendação de investimento. Sem tickers, sinais ou alertas de negociação. Negociar envolve risco de perda.

Related use cases