Sample programs
Complete programs to copy into the editor, from a plain average to sessions and tables, each one tested on real bars and explained in a few lines.
These are complete programs, written for this guide: indicators, and on the last page strategies. Each one is compiled and run on real bars of the chart every time the guide is built, so a program that stops working is found and fixed. Copy one into a new script, press Save and Add to chart, then change it: changing a working program is the quickest way to learn.
| Program | What it teaches | Page |
|---|---|---|
| Simple moving average | the header, an input, a plot | Moving averages and trend |
| Two averages with cross marks | crossings and marks | Moving averages and trend |
| Trend background | a colour per bar, the background | Moving averages and trend |
| Trend candles | recolouring the candles | Moving averages and trend |
| Distance from the average | arithmetic, a histogram | Moving averages and trend |
| An average from a higher timeframe | data.series | Moving averages and trend |
| RSI written out | earlier bars, running means, levels | Oscillators |
| RSI with zones and marks | a shaded zone, marks on a level | Oscillators |
| MACD | three values from one function | Oscillators |
| Stochastic oscillator | highest and lowest over a window | Oscillators |
| Bars since a high | state, a value kept between bars | Oscillators |
| Bollinger bands | standard deviation, a shaded band | Channels and levels |
| ATR channel | the average true range | Channels and levels |
| Donchian channel | the extremes of a window | Channels and levels |
| Daily pivot levels | yesterday's high, low and close | Channels and levels |
| Key levels | yesterday's range and the week's open | Channels and levels |
| Recent range drawing | boxes, lines and labels | Channels and levels |
| Session range boxes | a named session and its members | Sessions, patterns and volume |
| Opening range | a range built during a session | Sessions, patterns and volume |
| Inside bars | a candle pattern | Sessions, patterns and volume |
| Swing pivots | swings and labels | Sessions, patterns and volume |
| On-balance volume | a running total of volume | Sessions, patterns and volume |
| Volume spikes | volume against its average | Sessions, patterns and volume |
| Status table | a table in the corner | Sessions, patterns and volume |
| Moving average crossover | setup:, enter and close by key | Strategies |
| RSI reversion | entry and exit on two conditions | Strategies |
| Donchian breakout | a pending stop entry, expires, an exit stop | Strategies |
| ATR stop and target | a stop and a limit placed with the entry | Strategies |
| Risk guards | risk.max_daily_orders, risk.max_losing_days | Strategies |
| Opening range breakout | two sessions, state, long and short, closing at the session end | Strategies |
| Inside bar breakout | expires, profit_ticks and loss_ticks | Strategies |
| Trend pullback | costs, a protective stop, a time exit | Strategies |
| Band reversion, both sides | side.short, two keys | Strategies |
| Engulfing bars | the body of a bar, comparing with the bar before | Candle patterns |
| Doji | a share as an input, a guard against an empty range | Candle patterns |
| Hammer and shooting star | shadows, one input for two patterns | Candle patterns |
| Bars in a row | tech.bars_since | Candle patterns |
| Gaps | boxes drawn inside an if | Candle patterns |
| Outside bars | colouring only some candles | Candle patterns |
| Close position in the bar | a guarded division, columns | Candle patterns |
| Z-score | standard deviation, a signed histogram | Statistics and tools |
| Percent rank | tech.percent_rank, the true range | Statistics and tools |
| Change and volume correlation | tech.correlation, a named argument | Statistics and tools |
| Day range used | current(day) and prior(day, n) | Statistics and tools |
| ATR position size | arithmetic with inputs, a table | Statistics and tools |
| Round numbers | rounding to a step, steps | Statistics and tools |
| Last week's range | prior(week) | Statistics and tools |
| Session average price | state sums inside a session | Statistics and tools |
| Regression line | tech.linreg and its slope | Statistics and tools |
| Market dashboard | several readings in one table | Statistics and tools |
If you are new to scripts, start with the tutorial: it explains every part these programs use.