Skip to content

MT4Sugar — 3. Symbol Math

Point/pip conversions and volume/price normalization — the arithmetic you need before sending an order.

All read the symbol's contract parameters (SymbolParams) under the hood. A pip is point × 10 on 3/5-digit symbols, else point.


Point(ctx, symbol)

func (s *MT4Sugar) Point(ctx context.Context, symbol string) (float64, error)

The point size (SYMBOL_POINT), e.g. 0.00001 on 5-digit EURUSD.

Example:

pt, _ := sugar.Point(ctx, "EURUSD")
fmt.Println("point:", pt)

Digits(ctx, symbol)

func (s *MT4Sugar) Digits(ctx context.Context, symbol string) (int32, error)

Price decimal places (e.g. 5 for EURUSD, 3 for USDJPY).

Example — format a price to the symbol's precision:

d, _ := sugar.Digits(ctx, "EURUSD")
fmt.Printf("%.*f\n", d, 1.234567)

PipSize(ctx, symbol)

func (s *MT4Sugar) PipSize(ctx context.Context, symbol string) (float64, error)

point × 10 on 3/5-digit symbols, else point — the price distance of one pip.

Example:

pip, _ := sugar.PipSize(ctx, "EURUSD") // 0.0001

PipsToPrice(ctx, symbol, pips) · PriceToPips(ctx, symbol, priceDelta)

func (s *MT4Sugar) PipsToPrice(ctx context.Context, symbol string, pips float64) (float64, error)
func (s *MT4Sugar) PriceToPips(ctx context.Context, symbol string, priceDelta float64) (float64, error)

Convert between a pip distance and a price distance (inverse of each other).

Example — pips → price:

dist, _ := sugar.PipsToPrice(ctx, "EURUSD", 20) // 0.0020

Example — price → pips:

pips, _ := sugar.PriceToPips(ctx, "EURUSD", 0.0035) // 35

NormalizeLot(ctx, symbol, lot)

func (s *MT4Sugar) NormalizeLot(ctx context.Context, symbol string, lot float64) (float64, error)

Rounds a lot to the symbol's volume step and clamps it to [volumeMin, volumeMax]. Always run a computed volume through this before sending, or the broker may reject it as an invalid volume (error 131).

Example — snap a computed lot to the step:

lots, _ := sugar.NormalizeLot(ctx, "EURUSD", 0.137) // -> 0.14 on a 0.01 step

Example — clamp a too-small lot up to the minimum:

lots, _ := sugar.NormalizeLot(ctx, "EURUSD", 0.0) // -> volumeMin

NormalizePrice(ctx, symbol, price)

func (s *MT4Sugar) NormalizePrice(ctx context.Context, symbol string, price float64) (float64, error)

Rounds a price to the symbol's digits.

Example:

p, _ := sugar.NormalizePrice(ctx, "EURUSD", 1.234567) // -> 1.23457

TickValue(ctx, symbol)

func (s *MT4Sugar) TickValue(ctx context.Context, symbol string) (float64, error)

Money value of one tick per lot (TRADE_TICK_VALUE) — the basis for risk sizing.

Example:

tv, _ := sugar.TickValue(ctx, "EURUSD")
fmt.Println("tick value:", tv)

See also: 2. Prices & Quotes · 4. Risk Sizing