Linear versus Logarithmic Scaling
Two analysts open the same chart of the same instrument over the same twenty years. One says the trend accelerated dramatically in the last three years. The other says the rate of advance has been almost constant since the beginning. Neither is misreading. They have different settings on the vertical axis, and the axis is doing the arguing.
By the end of this lesson you will be able to say which of those two readings a given chart supports, switch between them in AmiBroker, and — the part most people skip — recognise which conclusions survive the switch and which were artefacts of it.
Two ways to space a price axis
Section titled “Two ways to space a price axis”A linear (arithmetic) axis puts equal differences at equal distances. The gap between 10 and 20 is drawn the same height as the gap between 100 and 110, because both are ten points.
A logarithmic axis puts equal ratios at equal distances. The gap between 10 and 20 is drawn the same height as the gap between 100 and 200, because both are a doubling.
That single change decides what “the same size move” means on your screen, and therefore what “steeper” and “flatter” mean when you describe the picture.
Four prices, each double the last
| Bar | t1 | t2 | t3 | t4 |
|---|---|---|---|---|
Price | 10 | 20 | 40 | 80 |
Change in points | — | +10 | +20 | +40 |
Change in per cent | — | +100% | +100% | +100% |
log(Price) | 2.303 | 2.996 | 3.689 | 4.382 |
Change in log(Price) | — | +0.693 | +0.693 | +0.693 |
Here is that claim as two pictures. Same four numbers, same order, same chart component - only the spacing of the axis is different:
Linear axis: equal differences, equal distances
- Price
Show the numbers behind this chart
| Bar | Open | High | Low | Close |
|---|---|---|---|---|
| t1 | 10 | 10 | 10 | 10 |
| t2 | 20 | 20 | 20 | 20 |
| t3 | 40 | 40 | 40 | 40 |
| t4 | 80 | 80 | 80 | 80 |
Logarithmic axis: equal ratios, equal distances
- Price
Show the numbers behind this chart
| Bar | Open | High | Low | Close |
|---|---|---|---|---|
| t1 | 10 | 10 | 10 | 10 |
| t2 | 20 | 20 | 20 | 20 |
| t3 | 40 | 40 | 40 | 40 |
| t4 | 80 | 80 | 80 | 80 |
The bottom row is the whole idea. Taking logarithms converts multiplication into addition, so a series that multiplies by a constant factor becomes a series that adds a constant amount, and a straight line on a logarithmic axis means a constant percentage rate.
Why this bites hardest on long histories
Section titled “Why this bites hardest on long histories”The distortion is proportional to how far the price has travelled. Over three months, a linear and a logarithmic chart of the same instrument look nearly identical, because the price range is narrow enough that the ratio and the difference stay roughly in step. Over twenty years of a security that went from 5 to 500, they are barely recognisable as the same data.
On a linear axis over that history, the first fifteen years are compressed into a flat line hugging the bottom of the pane, and the last few years dominate the picture. A 50% decline early on — from 6 to 3 — is drawn as a three-point wobble you cannot see. The same 50% decline at the end, from 500 to 250, consumes half the pane. The chart is not lying; it is answering the question “how many points?”, and nobody asked it that.
Trendlines stop being objects and become opinions
Section titled “Trendlines stop being objects and become opinions”A straight line drawn on a linear axis represents a constant number of points per bar. The same straight line drawn on a logarithmic axis represents a constant percentage per bar, which on a linear axis would be a curve bending upwards.
The consequence is uncomfortable and worth stating plainly: a rising trendline can be intact on one axis and broken on the other, from identical data, at the same moment. Neither chart is faulty. The line was never a property of the market; it was a property of the drawing surface, and you changed the surface.
This is the first appearance of a problem that Part 5 spends an entire lesson on. For now, take one habit away: when you draw a trendline, record which axis you drew it on, in the same breath as recording which two points you anchored it to. A trendline without those three facts cannot be reproduced by anyone, including you next month.
Which to use for what
Section titled “Which to use for what”| Situation | Axis |
|---|---|
| A few weeks or months of data | Either; the difference is negligible |
| Many years, or a price that has multiplied several times over | Logarithmic |
| Comparing two instruments at very different price levels | Logarithmic |
| Reading the cash value of a fixed share count | Linear |
| An oscillator bounded between 0 and 100 | Linear; ratios are meaningless there |
| An equity curve you want to judge by compound rate | Logarithmic |
A short honest note on vocabulary. AmiBroker’s own term is Logarithmic, offered as the Type of the Y-axis scaling with Linear as the alternative. Because only the price axis is transformed and the time axis stays linear, the rest of the industry usually calls this a semi-log chart. The idea is the same; use AmiBroker’s word when you are describing where to click.
Switching scale in AmiBroker
Section titled “Switching scale in AmiBroker”The setting is not on the View menu, which is where most people look first and give up. It is in the Parameters window: right-click the chart pane, choose Parameters, and open the Axes & Grid tab. Under Axes you will find:
- Scaling —
Automatic, where AmiBroker picks the minimum and maximum, orCustom, where you set them. - Minimum and Maximum — the bounds. These are locked while Scaling is set to
Automatic. They are not broken; switch to
Customand they unlock. - Type —
LinearorLogarithmic. This is the one you came for.
Two things follow from where the setting lives. First, it is per pane. Switching the price pane to logarithmic does not touch the indicator pane below it, which is usually what you want, because a logarithmic axis on an oscillator that crosses zero is not defined. Second, because it is a chart property rather than a formula property, it travels with your layout rather than with your code.
A formula can also set the scaling. The documented flags for SetChartOptions()
include chartLogarithmic alongside chartShowDates, chartShowArrows,
chartWrapTitle and chartHideQuoteMarker. Its first argument decides whether the
flags are defaults for a new pane, an overwrite, a set or a clear. That is useful when
you are shipping a chart template to someone else and want the axis to arrive already
correct; it is overkill while you are exploring.
Seeing the arithmetic instead of trusting the axis
Section titled “Seeing the arithmetic instead of trusting the axis”Switching an axis and watching a picture change teaches you that something happened, but not what. This formula performs the transformation explicitly in its own pane, so you can compare the shape it produces with the shape the axis setting produces and satisfy yourself that they are the same operation. It also prints the single number that motivates the whole exercise: what one point of price is worth as a percentage, now and a long time ago.
Complete formula
Section titled “Complete formula”Complete runnable AFL
// log-price-pane.afl// Part 4 - Linear versus Logarithmic Scaling//// Does by arithmetic what the Parameters dialog does to the axis, so you can// see the mechanism rather than take it on trust. Apply it to its own pane,// underneath a normal price pane, then switch the price pane to Logarithmic in// Parameters -> Axes & Grid -> Type. The two shapes should match.//// It also prints what one point of price is worth in percentage terms now and// N bars ago, which is the entire argument for a logarithmic axis in two numbers.//// Assumptions:// - Prices are positive. A logarithm of zero or of a negative number is not// defined, and bad data does produce zeros, so they are excluded explicitly.// - Any instrument, any interval.
_SECTION_BEGIN("Log price pane");
Lookback = Param( "Compare with the close N bars ago", 250, 20, 2000, 10 );
// Nz() turns Null into 0, so the validity test below is a plain comparison// instead of an expression that quietly propagates Null.PriceNow = Nz( Close );PricePast = Nz( Ref( Close, -Lookback ) );
ValidNow = PriceNow > 0;ValidPast = PricePast > 0;
// IIf() is a function, and the official page is explicit that it ALWAYS// evaluates both the true part and the false part before selecting between them// bar by bar. So a condition cannot protect log() or a division: the guard has// to be inside the argument. Flooring the input at a tiny positive number keeps// log() and the divisions defined on every bar, and the IIf() then throws those// bars away.FlooredNow = Max( PriceNow, 0.000001 );FlooredPast = Max( PricePast, 0.000001 );
// log() is the natural logarithm. Any base gives the same shape; only the// numbers on the axis would change.LogPrice = IIf( ValidNow, log( FlooredNow ), Null );
Plot( LogPrice, "log(Close)", colorBlue, styleLine | styleThick );
// One point of price is a different percentage at every price level. That, and// nothing more mystical, is what a logarithmic axis corrects for.OnePointNow = IIf( ValidNow, 100 / FlooredNow, Null );OnePointPast = IIf( ValidPast, 100 / FlooredPast, Null );
_N( Title = Name() + " - " + Interval( 2 ) + " - one point of price, as a percentage\n" + StrFormat( "Close now %g, so one point is %.3f%% of price\n", PriceNow, OnePointNow ) + StrFormat( "Close %g bars ago %g, so one point was %.3f%% of price\n", Lookback, PricePast, OnePointPast ) + "On a linear axis those two moves are drawn the same height. On a " + "logarithmic axis they are not." );
_SECTION_END();How it works
Section titled “How it works”Nz() is applied first, so that missing data becomes zero rather than propagating
Null through the comparisons that follow. The validity tests are then ordinary
comparisons, and the logarithm is only taken where the price is genuinely positive —
log() of zero or of a negative number is not defined, and real databases do contain
zeros where a vendor had nothing to report.
The rest is two divisions. One hundred divided by the price is what a single point is worth as a percentage of that price. Computing it at today’s price and at the price N bars ago gives you the two numbers whose difference the logarithmic axis exists to correct.
Key functions
Section titled “Key functions”log( array )is the natural logarithm — the official page nameslnas its synonym. The base does not matter for chart shape: changing base multiplies every value by a constant, which stretches the axis labels and leaves the picture identical.Nz( array )replacesNullvalues with zero (or with a replacement you supply). It is the standard way to stop missing data from quietly poisoning a comparison.Param( "name", default, min, max, step )adds a numeric slider to the Parameters dialog. The default, minimum, maximum and step must be constant numbers — the official page warns that they are cached and not re-read on later evaluations.
Expected result
Section titled “Expected result”Test it
Section titled “Test it”Pick an instrument whose price has at least tripled over the loaded history. Read the two percentages in the title. Now find, by eye, two moves of the same number of points — one early, one late — and confirm that on the linear price pane they are drawn the same height, while on the log pane they are not. If the two percentages in the title are nearly equal, your history is too short to demonstrate anything; load more bars or choose a different instrument.
Common errors
Section titled “Common errors”- The log pane is empty or full of gaps. The instrument has zero or missing closes in the loaded range. That is a data-quality finding, not a formula failure — go back to the checks in Part 2.
- The two shapes never match. Check that you switched the price pane rather than
the log pane, and that you switched
Typerather thanScaling. - The lookback slider does nothing. On a chart with fewer bars than the lookback, the past price is empty for every visible bar. Zoom out or reduce the lookback.
Extension
Section titled “Extension”Plot the difference between log(Close) and its own value N bars ago. That is the
continuously compounded return over N bars, and it is the quantity most statistical
work on prices actually uses. You will meet it again in Part 29 when return metrics
stop being intuitive.
What changed
Section titled “What changed”You now know that “steep” and “flat” are statements about an axis as much as about a market, that the effect grows with the length of the history and the size of the price multiple, and that a trendline inherits the ambiguity completely. You also know where AmiBroker keeps the setting and why it is not on the View menu.
The next lesson stops changing the picture and starts trying to pin down something in it: the swing points that all structure vocabulary is built from.
Check your understanding
Sources for this lesson
5 verified · checked 2026-08-31
- 01AmiBroker User's Guide — Parameters window§ Axes & Gridamibroker.com/guide/w_param.html2026-08-31
- 02AmiBroker User's Guide — Beginners' charting guide§ Shrinking, expanding and moving Y-axis scaleamibroker.com/guide/h_charting.html2026-08-31
- 03AmiBroker User's Guide — View menuamibroker.com/guide/m_view.html2026-08-31
- 04AFL Function Reference — SetChartOptionsamibroker.com/guide/afl/setchartoptions.html2026-08-31
- 05AFL Function Reference — logamibroker.com/guide/afl/log.html2026-08-31
Every technical claim on this page was checked against the official AmiBroker documentation on the date shown. Where the course disagrees with folklore, the source is how you can tell which one to trust.