Skip to content

Bracket + Trailing

Market entry with a bracket, where the trailing stop only switches on once the trade is far enough in profit.

  • Source: mt4/strategies/bracket_trailing.go
  • Entry: RunBracketTrailing(ctx, sugar, sp, rp, activateAtPips) (int32, error)
  • Demo: examples app โ†’ menu 41 (strategydemo.Demo)

What it does

  1. Sizes the lot and opens a market BUY (like Market One-Shot).
  2. Attaches the pip SL/TP bracket.
  3. Manages for ~10s: auto-breakeven applies early; trailing only arms once the trade is activateAtPips in profit โ€” letting the position breathe before the stop starts following it.
  4. Closes and returns the ticket.

Use it when you want a trade to run before the stop begins trailing, rather than trailing from the first pip.


Signature

func RunBracketTrailing(ctx context.Context, sugar *mt4.MT4Sugar, sp StrategyPreset, rp RiskPreset, activateAtPips float64) (int32, error)
Parameter Type Description
ctx context.Context Cancellation / timeout.
sugar *mt4.MT4Sugar Connected high-level client.
sp StrategyPreset What to trade.
rp RiskPreset Risk & protection; TrailingPips must be set for trailing to do anything.
activateAtPips float64 Profit (in pips) at which trailing switches on.

Returns: the order ticket (int32) and an error.


Example

// trailing arms once the trade is +12 pips in profit
ticket, err := strategies.RunBracketTrailing(ctx, sugar,
    strategies.MarketEURUSD(), strategies.Balanced(), 12)
if err != nil { return err }
fmt.Println("bracket+trailing ticket:", ticket)

Balanced() sets TrailingPips = 15 and BETriggerPips = 10, so breakeven locks at +10 while the trail follows 15 pips behind once +12 is reached.


๐Ÿ“š See also