TickValueWithSize¶
Tick value, tick size and contract size for one or more symbols โ the money-math inputs for risk sizing.
API Information:
- Low-level API:
MT4Account.TickValueWithSize(ctx, symbolNames)(defined inmt4/MT4Account.go) - gRPC service:
mt4_term_api.AccountHelper - RPC:
TickValueWithSize(TickValueWithSizeRequest) โ TickValueWithSizeReply - Payload:
TickValueWithSizeDataโGetInfos()โSymbolTickValueWithSizeInfo
๐ฌ Just the essentials¶
- What it is. The per-symbol tick value / tick size / contract size โ a focused subset of
SymbolParams. - Why you need it. Convert a pip distance into money for position sizing.
- When to use. Risk calculators, exposure/value math.
๐ฏ Purpose¶
- Read tick value (money per tick per lot)
- Read tick size (price per tick)
- Read contract size
- Compute pip value โ size a lot by cash risk
Method Signature¶
func (a *MT4Account) TickValueWithSize(ctx context.Context, symbolNames []string) (*pb.TickValueWithSizeData, error)
Request message:
message TickValueWithSizeRequest { repeated string symbol_names = 1; }
Payload message:
message TickValueWithSizeData { repeated SymbolTickValueWithSizeInfo infos = 1; }
message SymbolTickValueWithSizeInfo {
int32 index = ...;
string symbol_name = ...;
double trade_tick_value = ...;
double trade_tick_size = ...;
double trade_contract_size = ...;
}
๐ฝ Input¶
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context |
yes | Cancellation / timeout. |
symbolNames |
[]string |
yes | Symbols to describe, e.g. []string{"EURUSD"}. |
โฌ๏ธ Output โ *pb.TickValueWithSizeData¶
GetInfos() returns []*pb.SymbolTickValueWithSizeInfo:
| Field | Proto Type | Go getter | Description |
|---|---|---|---|
symbol_name |
string | GetSymbolName() string |
Symbol |
trade_tick_value |
double | GetTradeTickValue() float64 |
Money value of one tick per lot |
trade_tick_size |
double | GetTradeTickSize() float64 |
Price size of one tick |
trade_contract_size |
double | GetTradeContractSize() float64 |
Contract size |
index |
int32 | GetIndex() int32 |
Server index |
On failure the call returns a non-nil
error(text"API error (code=โฆ): โฆ") โ see the Return Codes Reference.
๐งฉ Notes & Tips¶
- Pip value per lot โ
GetTradeTickValue() ร (pipSize / GetTradeTickSize()). - Lighter than
SymbolParamsif money math is all you need โ butSymbolParamsalready includes these. - Match by
GetSymbolName(), not slice index.
๐ Usage Examples¶
1) Print the money-math inputs¶
func tickInfo(ctx context.Context, acc *mt4.MT4Account, symbols []string) error {
d, err := acc.TickValueWithSize(ctx, symbols)
if err != nil { return err }
for _, i := range d.GetInfos() {
fmt.Printf("%-8s tickVal=%.5f tickSize=%.5f contract=%.0f\n",
i.GetSymbolName(), i.GetTradeTickValue(), i.GetTradeTickSize(), i.GetTradeContractSize())
}
return nil
}
2) Pip value per lot¶
func pipValue(ctx context.Context, acc *mt4.MT4Account, symbol string, pipSize float64) (float64, error) {
d, err := acc.TickValueWithSize(ctx, []string{symbol})
if err != nil { return 0, err }
for _, i := range d.GetInfos() {
if i.GetSymbolName() == symbol && i.GetTradeTickSize() > 0 {
return i.GetTradeTickValue() * (pipSize / i.GetTradeTickSize()), nil
}
}
return 0, fmt.Errorf("no tick info for %s", symbol)
}
3) Lot for a cash risk over a stop¶
func lotForRisk(ctx context.Context, acc *mt4.MT4Account, symbol string, pipSize, riskCash, slPips float64) (float64, error) {
pv, err := pipValue(ctx, acc, symbol, pipSize)
if err != nil || pv <= 0 || slPips <= 0 { return 0, err }
return riskCash / (slPips * pv), nil
}
โ ๏ธ Pitfalls¶
- Divide-by-zero. Guard
GetTradeTickSize() > 0before dividing. - Missing symbols. Unknown names may be omitted โ match by name.
- Still normalize the resulting lot with
SymbolParams's volume step.
๐งช Testing Suggestions¶
- Happy path (demo). For a liquid FX symbol,
GetTradeTickValue() > 0andGetTradeTickSize() > 0. - Pip value.
pipValueis positive and matches the figure derived fromSymbolParams. - Risk lot.
lotForRiskscales inversely withslPips.