Pending Bracket¶
Place a BUY LIMIT, wait for the fill (cancel on timeout), then bracket and manage.
- Source:
mt4/strategies/pending_bracket.go - Entry:
RunPendingBracket(ctx, sugar, sp, rp, timeoutSeconds) (int32, error) - Demo: examples app โ menu
41(strategydemo.Demo)
What it does¶
- Picks the entry price โ
sp.EntryPriceif set, otherwise 5 pips below the current bid (demo default). - Sizes the lot and places a BUY LIMIT via
MT4Sugar.BuyLimit. - Waits up to
timeoutSecondsfor the fill withWaitFilled. If it doesn't fill, the pending is cancelled and the ticket is returned. - Once filled: attaches the pip bracket, manages ~5s (breakeven + gated trailing), then closes.
Use it for limit entries where you want a bounded wait and automatic cleanup if price never comes back.
Signature¶
func RunPendingBracket(ctx context.Context, sugar *mt4.MT4Sugar, sp StrategyPreset, rp RiskPreset, timeoutSeconds int) (int32, error)
| Parameter | Type | Description |
|---|---|---|
ctx |
context.Context |
Cancellation / timeout. |
sugar |
*mt4.MT4Sugar |
Connected high-level client. |
sp |
StrategyPreset |
Symbol, EntryPrice (optional โ else 5 pips below bid), Lots, Magic. |
rp |
RiskPreset |
Risk & protection. |
timeoutSeconds |
int |
How long to wait for the pending to fill before cancelling. |
Returns: the ticket (int32) โ filled-and-managed, or the cancelled pending โ and an error.
Example¶
// explicit limit price, 60s fill window
ticket, err := strategies.RunPendingBracket(ctx, sugar,
strategies.LimitEURUSD(1.0750), strategies.Conservative(), 60)
if err != nil { return err }
fmt.Println("pending-bracket ticket:", ticket)
With
strategies.MarketEURUSD()(noEntryPrice) the limit is placed 5 pips below the current bid โ handy for a quick demo fill.