The script change that helped my scalping the most was not a signal. It was making sure no entry ever goes out without its stop and target attached. If my broker's API supports bracket or OCO-style orders, I use them. If it doesn't, my script builds the same behavior itself and refuses to send a naked entry.
## Rails
- The entry function takes three prices: entry limit, stop, target. If any one is missing, it raises an error and sends nothing.
- The stop distance is checked against a per-symbol max in cents from a config file. Too wide and the order is rejected locally, before the broker ever sees it.
- The size is calculated from dollar risk divided by stop distance, rounded down to whole shares.
- After the entry fills, the script confirms both child orders show as working. If either is missing after 2 seconds, it flattens the position and logs the event.
## Worked example (illustrative)
Config: max risk $40 per trade, max stop 15 cents for a $52 ETF. At 10:12 ET I want to buy a pullback at 52.30 with a stop at 52.18 and a target at 52.54.
Stop distance is 12 cents, inside the 15-cent cap. Size is $40 / 0.12 = 333.3, rounded down to 333 shares. The script sends the bracket. The entry fills at 52.30 at 10:13 ET. At 10:13:01 it queries open orders and sees the 52.18 stop and 52.54 limit both working. Logged as OK.
Another day: same setup, but the target child is missing after the fill because of a rejected price increment. At 2 seconds the script sends a market sell for the full size and logs "CHILD_MISSING". I lose a few cents of spread. The important part is that I'm never sitting in a position with no stop while I work out what went wrong.
## Failure modes
- Assuming the broker accepted the children because the parent filled.
- Hard-coding share size instead of deriving it from risk, so a wider stop quietly doubles the dollar risk.
- Letting the script modify the stop outward. Mine can only tighten it.
## When to skip
- The API connection has dropped at any point that session and I haven't re-checked open orders by hand.
- The instrument has a price increment the script doesn't handle.
- Any news window where I'd rather be flat than trust automation.
Diagram: three boxes (entry, stop, target) wired into one "bracket" box, then a check step that confirms children are working, with a red "missing child = flatten" branch.
Bracket orders through my broker API: entry, stop and target sent as one unit
Bracket orders through my broker API: entry, stop and target sent as one unit
- Attachments
-
- 03-diagram.png (19.6 KiB) Viewed 33 times