Using the _N Function to Limit Trading Value Precision
Summary
The document explains how to use the _N function to limit a numeric value to a chosen number of decimal places in a trading program. It presents examples for formatting a sell price and a buy price in both JavaScript and Python, with six decimal places used in the illustrations. The stated motivation is to avoid overly precise calculated prices or account values that could contribute to failed or incorrect trades.
It notes that _N does not round to the nearest value, so the result is truncated or otherwise reduced in precision rather than conventionally rounded. The Python example converts a string price to a floating-point value first, and the accompanying note says the function expects a float as its first argument. The document shows example outputs by reference but does not explain behavior across edge cases, numeric types, exchange tick-size rules, or whether decimal precision alone is sufficient to ensure valid order prices.
Key ideas
- The _N function limits a value to a specified number of decimal places.
- The document says the function does not perform conventional rounding.
- Its examples apply six-place precision to buy and sell prices.
- The Python example converts a string input to a floating-point number before processing.
- Decimal precision settings do not by themselves establish compliance with instrument tick sizes.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.