π΄ Sell at Market Price (SellMarket)ΒΆ
Sugar method: Opens a SELL position instantly at current market BID price.
API Information:
- Method:
sugar.SellMarket(symbol, volume) - Timeout: 10 seconds
- Returns: Position ticket number
π Method SignatureΒΆ
π½ Input / β¬οΈ OutputΒΆ
| Input | Type | Description |
|---|---|---|
symbol |
string |
Trading symbol (e.g., "EURUSD", "GBPUSD") |
volume |
float64 |
Lot size (e.g., 0.01, 0.1, 1.0) |
| Output | Type | Description |
|---|---|---|
ticket |
uint64 |
Position ticket number (for tracking/closing) |
error |
error |
Error if order rejected or execution failed |
π¬ Just the EssentialsΒΆ
- What it is: Instantly opens a SELL position at current market BID price.
- Why you need it: Simplest way to go SHORT on a symbol.
- Sanity check: Order executes immediately - no waiting, no SL/TP set.
β οΈ IMPORTANTΒΆ
This method does NOT set Stop Loss or Take Profit!
- Use
SellMarketWithSLTP()for trades with risk management - Use
SellMarketWithPips()for trades with SL/TP in pips - Or manually add SL/TP after:
ModifyPositionSLTP(ticket, sl, tp)
π― When to UseΒΆ
β Quick entries - When you want instant market entry
β Manual management - You'll set SL/TP manually later
β Testing/learning - Simple way to test trading
β NOT for production - Always use SL/TP in real trading!
π Usage ExamplesΒΆ
1) Basic usageΒΆ
ticket, err := sugar.SellMarket("EURUSD", 0.1)
if err != nil {
fmt.Printf("Order failed: %v\n", err)
return
}
fmt.Printf("β
SELL position opened, ticket #%d\n", ticket)
2) With immediate SL/TPΒΆ
symbol := "EURUSD"
volume := 0.1
// Open SELL position
ticket, err := sugar.SellMarket(symbol, volume)
if err != nil {
fmt.Printf("Order failed: %v\n", err)
return
}
fmt.Printf("Position #%d opened\n", ticket)
// SELL: SL above entry, TP below entry
sl, tp, _ := sugar.CalculateSLTP(symbol, "SELL", 0, 50, 100)
// Set SL/TP
sugar.ModifyPositionSLTP(ticket, sl, tp)
fmt.Printf("β
SL/TP set: %.5f / %.5f\n", sl, tp)
3) Sell at resistance levelΒΆ
symbol := "EURUSD"
resistance := 1.09000
bid, _ := sugar.GetBid(symbol)
if bid < resistance {
fmt.Printf("β Price %.5f below resistance %.5f\n", bid, resistance)
return
}
fmt.Printf("β
At resistance: %.5f\n", bid)
// Sell at resistance
ticket, _ := sugar.SellMarket(symbol, 0.1)
fmt.Printf("SELL order #%d placed\n", ticket)
4) Risk-managed SELLΒΆ
symbol := "EURUSD"
riskPercent := 2.0
stopLossPips := 50.0
takeProfitPips := 100.0
// Calculate position size
lotSize, _ := sugar.CalculatePositionSize(symbol, riskPercent, stopLossPips)
// Validate
canOpen, reason, _ := sugar.CanOpenPosition(symbol, lotSize)
if !canOpen {
fmt.Printf("Cannot open: %s\n", reason)
return
}
// Open SELL
ticket, _ := sugar.SellMarket(symbol, lotSize)
// Set SL/TP
sl, tp, _ := sugar.CalculateSLTP(symbol, "SELL", 0, stopLossPips, takeProfitPips)
sugar.ModifyPositionSLTP(ticket, sl, tp)
fmt.Printf("β
SELL setup complete\n")
fmt.Printf(" Ticket: #%d, Size: %.2f lots\n", ticket, lotSize)
5) Hedge existing BUY positionΒΆ
symbol := "EURUSD"
// Get existing BUY positions
buyPositions, _ := sugar.GetPositionsBySymbol(symbol)
if len(buyPositions) == 0 {
fmt.Println("No BUY positions to hedge")
return
}
// Calculate total BUY volume
var totalBuyVolume float64
for _, pos := range buyPositions {
totalBuyVolume += pos.Volume
}
fmt.Printf("Total BUY volume: %.2f lots\n", totalBuyVolume)
// Open SELL to hedge
ticket, _ := sugar.SellMarket(symbol, totalBuyVolume)
fmt.Printf("β
Hedge SELL opened: Ticket #%d\n", ticket)
fmt.Printf(" Volume: %.2f lots (matches BUY positions)\n", totalBuyVolume)
6) Pair trading - BUY one, SELL anotherΒΆ
// Buy EURUSD, Sell GBPUSD (pair trade)
ticketBuy, _ := sugar.BuyMarket("EURUSD", 0.1)
ticketSell, _ := sugar.SellMarket("GBPUSD", 0.1)
fmt.Println("Pair trade opened:")
fmt.Printf(" BUY EURUSD: Ticket #%d\n", ticketBuy)
fmt.Printf(" SELL GBPUSD: Ticket #%d\n", ticketSell)
7) Sell on breakdownΒΆ
symbol := "EURUSD"
supportLevel := 1.08000
fmt.Printf("Monitoring %s for breakdown below %.5f...\n", symbol, supportLevel)
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for range ticker.C {
bid, _ := sugar.GetBid(symbol)
if bid < supportLevel {
fmt.Printf("π΄ BREAKDOWN! BID %.5f broke below %.5f\n", bid, supportLevel)
// Sell on breakdown
ticket, _ := sugar.SellMarket(symbol, 0.1)
fmt.Printf("β
SELL order #%d placed\n", ticket)
return
}
fmt.Printf("BID: %.5f (%.5f above support)\n", bid, bid-supportLevel)
}
8) Average into short positionΒΆ
symbol := "EURUSD"
entries := 3
lotPerEntry := 0.1
fmt.Printf("Averaging into SELL position with %d entries\n", entries)
tickets := []uint64{}
for i := 1; i <= entries; i++ {
bid, _ := sugar.GetBid(symbol)
ticket, err := sugar.SellMarket(symbol, lotPerEntry)
if err != nil {
fmt.Printf("Entry %d failed: %v\n", i, err)
continue
}
tickets = append(tickets, ticket)
fmt.Printf("Entry %d: Ticket #%d at %.5f\n", i, ticket, bid)
if i < entries {
time.Sleep(10 * time.Second) // Wait before next entry
}
}
fmt.Printf("\nTotal: %d SELL positions opened\n", len(tickets))
9) Quick scalp SELLΒΆ
symbol := "EURUSD"
volume := 0.1
// Check spread (scalping needs tight spread)
spread, _ := sugar.GetSpread(symbol)
if spread > 10 {
fmt.Printf("Spread too high for scalping: %.0f points\n", spread)
return
}
// Quick SELL entry
ticket, _ := sugar.SellMarket(symbol, volume)
fmt.Printf("Scalp SELL opened: #%d\n", ticket)
// Set tight TP (10 pips)
sl, tp, _ := sugar.CalculateSLTP(symbol, "SELL", 0, 15, 10)
sugar.ModifyPositionSLTP(ticket, sl, tp)
fmt.Println("Tight SL/TP set for quick scalp")
10) Complete SELL workflowΒΆ
func OpenSellPosition(sugar *mt5.MT5Sugar, symbol string) error {
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
fmt.Println("β SELL ORDER WORKFLOW β")
fmt.Println("βββββββββββββββββββββββββββββββββββββββββ")
// Step 1: Check connection
if !sugar.IsConnected() {
return fmt.Errorf("not connected")
}
fmt.Println("β
Connected")
// Step 2: Check spread
spread, _ := sugar.GetSpread(symbol)
fmt.Printf("β
Spread: %.0f points\n", spread)
if spread > 20 {
return fmt.Errorf("spread too high: %.0f", spread)
}
// Step 3: Get current price
bid, _ := sugar.GetBid(symbol)
fmt.Printf("β
Current BID: %.5f\n", bid)
// Step 4: Calculate position size (2% risk, 50 pip SL)
lotSize, _ := sugar.CalculatePositionSize(symbol, 2.0, 50)
fmt.Printf("β
Position size: %.2f lots\n", lotSize)
// Step 5: Validate
canOpen, reason, _ := sugar.CanOpenPosition(symbol, lotSize)
if !canOpen {
return fmt.Errorf("validation failed: %s", reason)
}
fmt.Println("β
Validation passed")
// Step 6: Open SELL
ticket, err := sugar.SellMarket(symbol, lotSize)
if err != nil {
return fmt.Errorf("order failed: %w", err)
}
fmt.Printf("β
SELL opened: Ticket #%d\n", ticket)
// Step 7: Set SL/TP
sl, tp, _ := sugar.CalculateSLTP(symbol, "SELL", 0, 50, 100)
sugar.ModifyPositionSLTP(ticket, sl, tp)
fmt.Printf("β
SL/TP: %.5f / %.5f\n", sl, tp)
fmt.Println("\nβ
SELL POSITION COMPLETE")
return nil
}
// Usage:
err := OpenSellPosition(sugar, "EURUSD")
π Related MethodsΒΆ
π¬ Better alternatives with SL/TP:
SellMarketWithSLTP()- SELL with SL/TP pricesSellMarketWithPips()- SELL with SL/TP in pips β RECOMMENDED
π¬ Other market orders:
BuyMarket()- BUY at market
π¬ Position management:
ModifyPositionSLTP()- Add SL/TP after openingClosePosition()- Close the position
β οΈ Common PitfallsΒΆ
1) Confusing SELL SL/TP directionΒΆ
// β WRONG - SL/TP in wrong direction for SELL
bid := 1.08500
sl := bid - 50_pips // WRONG! SL should be ABOVE for SELL
tp := bid + 100_pips // WRONG! TP should be BELOW for SELL
// β
CORRECT - use CalculateSLTP
sl, tp, _ := sugar.CalculateSLTP("EURUSD", "SELL", bid, 50, 100)
// SELL: SL is ABOVE entry, TP is BELOW entry
2) Trading without Stop LossΒΆ
// β DANGEROUS - No stop loss!
sugar.SellMarket("EURUSD", 0.1)
// β
CORRECT - Use version with SL/TP
sugar.SellMarketWithPips("EURUSD", 0.1, 50, 100)
π Pro TipsΒΆ
-
SELL = short = profit when price drops
-
SL above entry, TP below - Remember SELL direction
-
Use
SellMarketWithPips()- Much safer than bareSellMarket() -
Calculate lot size - Always use risk-based sizing
-
Validate before selling - Check margin and spread
π¨ Production RecommendationΒΆ
DON'T use SellMarket() in production!
Instead:
// β
RECOMMENDED
ticket, _ := sugar.SellMarketWithPips("EURUSD", 0.1, 50, 100)
// OR with full risk management
lotSize, _ := sugar.CalculatePositionSize("EURUSD", 2.0, 50)
ticket, _ := sugar.SellMarketWithPips("EURUSD", lotSize, 50, 100)
See also: SellMarketWithPips.md, SellMarketWithSLTP.md, BuyMarket.md