Market One-Shot¶
Open a market order with an automatic pip-based SL/TP bracket โ the simplest orchestrator.
- Source:
mt4/strategies/market_one_shot.go - Entry:
RunMarketOneShot(ctx, sugar, sp, rp) (int32, error) - Demo: examples app โ menu
41(strategydemo.Demo)
What it does¶
- Sizes the lot โ fixed
sp.Lots, or risk-based fromrp.RiskPercentoverrp.SLPipsviaCalcLotByRisk. - Opens a market BUY via
MT4Sugar.BuyMarket. - Attaches a bracket โ SL/TP as pip distances with
ModifySLTPByPips. - Manages for ~5s (auto-breakeven, then gated trailing โ both from the preset).
- Closes the position and returns the ticket.
Use it when you simply want a protected market entry in one call.
Signature¶
func RunMarketOneShot(ctx context.Context, sugar *mt4.MT4Sugar, sp StrategyPreset, rp RiskPreset) (int32, error)
| Parameter | Type | Description |
|---|---|---|
ctx |
context.Context |
Cancellation / timeout. |
sugar |
*mt4.MT4Sugar |
A connected high-level client (drives entry, bracket, manage, close). |
sp |
StrategyPreset |
Symbol, Lots (optional), Magic, Comment. |
rp |
RiskPreset |
RiskPercent, SLPips, TPPips, optional trailing/breakeven. |
Returns: the order ticket (int32) and an error.
Example¶
sugar := mt4.NewMT4Sugar(mt4.NewMT4Service(acc)).SetDefaults(777, 20, "demo")
ticket, err := strategies.RunMarketOneShot(ctx, sugar,
strategies.MarketEURUSD(), // WHAT: market EURUSD, magic 777
strategies.Balanced()) // HOW: 1% risk, SL 20 / TP 40, trail 15, BE 10/+2
if err != nil { return err }
fmt.Println("one-shot ticket:", ticket)
If
sp.Lotsis nil, sizing comes fromrp.RiskPercent+rp.SLPipsviaCalcLotByRisk.