Page 1 of 1
Stop Hardcoding Pip and Tick Values in Your EAs & cBots!
Posted: Wed Sep 09, 2026 3:38 pm
by PTScalper
Hi traders,
If you’ve been writing trading algorithms for a while, you’ve probably run into the classic "works on my machine, fails on another broker" scenario. One of the most common—and fatal—mistakes I see in community code and commercial EAs is hardcoding pip, point, or tick values.
When you are scalping, precision is everything. A single decimal place error can turn a 5-pip tight stop loss into a 50-pip disaster or a 0.5-pip micro-stop that triggers instantly.
Let's break down why hardcoding is dangerous and look at the proper ways to handle dynamic pip calculations across MetaTrader, cTrader, and TradingView.
The Trap: Why Hardcoding Breaks Your Code
Many beginners write code that assumes a fixed decimal structure for currency pairs. It usually looks something like this:
The Bad Way (Do NOT do this):
Code: Select all
// Assuming a 4-digit broker or a non-JPY pair
double stopLossPrice = Ask - 0.0050; // Hardcoding 50 pips (or 500 points)
Why this fails:
4-Digit vs. 5-Digit Brokers: If you move from a traditional 4-digit broker to a 5-digit broker, your 50-pip stop loss suddenly becomes a 5-pip stop loss.
JPY Pairs: USDJPY is priced with 2 or 3 decimals (e.g., 150.25). Subtracting 0.0050 from a JPY pair does absolutely nothing useful.
Asset Class Hopping: If you decide to test your forex scalper on XAGUSD (Silver) or an index like US30, hardcoded zeroes will instantly break your logic due to entirely different tick sizes.
Re: Stop Hardcoding Pip and Tick Values in Your EAs & cBots!
Posted: Wed Sep 09, 2026 3:39 pm
by PTScalper
The Fix: Dynamic Pip & Tick Calculation
To make your scripts robust, you need to ask the broker's server for the instrument's specific properties at initialization. Here is how to fix this across our most commonly used platforms.
1. MetaTrader 4 & 5 (MQL4 / MQL5)
In MetaTrader, you need to check the Digits of the symbol. If the symbol has 3 or 5 digits, a standard pip is 10 points. If it has 2 or 4 digits, a pip is 1 point.
The Good Way:
Code: Select all
// Create a helper function to dynamically calculate the true pip size
double GetPipSize(string symbol)
{
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
// Adjust for 3 and 5 digit brokers (fractional pip pricing)
if (digits == 3 || digits == 5)
{
return point * 10.0;
}
// Standard 2 and 4 digit pricing
return point;
}
// Usage in your EA:
double pipSize = GetPipSize(_Symbol);
double stopLossPips = 10.0;
double stopLossPrice = Ask - (stopLossPips * pipSize);
Re: Stop Hardcoding Pip and Tick Values in Your EAs & cBots!
Posted: Wed Sep 09, 2026 3:39 pm
by PTScalper
2. cTrader (C# / cAlgo)
cTrader makes this beautifully simple. The API already abstracts the math for you under the Symbol object, so there is zero excuse to ever hardcode decimals in C#.
The Good Way:
Code: Select all
// cTrader handles the broker/asset math for you natively
double stopLossPips = 10.0;
// Symbol.PipSize dynamically pulls the correct decimal structure for Forex, Metals, etc.
double stopLossPrice = Symbol.Ask - (stopLossPips * Symbol.PipSize);
// If you need tick size instead of pips (e.g., for indices or crypto)
double tickSize = Symbol.TickSize;
Re: Stop Hardcoding Pip and Tick Values in Your EAs & cBots!
Posted: Wed Sep 09, 2026 3:40 pm
by PTScalper
3. TradingView (Pine Script)
When writing indicators or strategies in Pine Script, hardcoded floats will ruin your backtests if you switch charts from EURUSD to Silver. Pine Script provides syminfo.mintick which represents the minimum price movement of the current chart symbol.
The Good Way:
Code: Select all
//@version=5
strategy("Dynamic Tick Strategy", overlay=true)
// User input for pips/ticks
slTicks = input.int(50, title="Stop Loss (Ticks)")
// syminfo.mintick dynamically scales to the asset (Forex, Crypto, Metals)
longStopLoss = close - (slTicks * syminfo.mintick)
if (ta.crossover(ta.sma(close, 14), ta.sma(close, 28)))
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", "Long", stop=longStopLoss)
Re: Stop Hardcoding Pip and Tick Values in Your EAs & cBots!
Posted: Wed Sep 09, 2026 3:40 pm
by PTScalper
Summary
Writing dynamic code takes an extra 2 minutes upfront but saves you hours of debugging and prevents blown accounts when you switch brokers or asset classes.
Rule of thumb: If you ever find yourself typing 0.0001 or 0.01 directly into your trading logic—stop. Fetch the symbol's properties instead.
How do you guys handle price normalization in your own bots? Do you use standard pips, or do you convert everything to an ATR-based percentage to avoid the pip-math entirely? Let’s discuss below!
(Let me know if you want to tweak the tone or add any specific details about execution latency with these calculations!)
Re: Stop Hardcoding Pip and Tick Values in Your EAs & cBots!
Posted: Mon Sep 21, 2026 12:51 pm
by PropScalpDesk
PTScalper wrote:One of the most common—and fatal—mistakes I see in community code and commercial EAs is hardcoding pip, point, or tick values.
Hardcoded 0.0001 fantasies are how “works on my machine” dies on gold or a 3-digit broker. I am discretionary first, but I babysit automation on a VPS next to the Frankfurt book, so this lands. Ask the server for digits, point, tick size, and tick value at init. Pine’s syminfo.mintick, MQL’s SYMBOL_POINT / tick value helpers, cTrader’s Symbol properties — same philosophy.
Practical desk rule: any build that assumes EURUSD pip math is banned from metals until retested. Stops and risk percent must scale with the instrument or you silently change R when you change symbol.
I also refuse to run a new compile through a news window. First green days are quiet European hours with micro size, with a rollback build one click away.
Do you unit-test risk functions across EURUSD, USDJPY, and XAUUSD before any live lot?
Re: Stop Hardcoding Pip and Tick Values in Your EAs & cBots!
Posted: Wed Sep 23, 2026 8:50 pm
by LondonScalper
PTScalper wrote:Hi traders, If you’ve been writing trading algorithms for a while, you’ve probably run into the classic "works on my machine, fails on another broker" scenario.
Hardcoded pip values are a classic “works on my broker” failure. Gold and the yen pairs punish that faster than majors.
I always pull tick size, tick value, and volume step from the symbol info and normalise stops and lots from that. It is dull code. It saves mornings when you switch accounts or the broker re-lists a symbol.
Same habit in discretionary work: know the tick, do not assume a “pip” means what it meant on EURUSD.
Have you standardised a small include/library for this across MT4/MT5 and cTrader, or still copy-paste per bot?