thinkScript is a study language many traders already use. On ZoroCharts you can paste a thinkScript study into the Script Editor and add it to the chart. Our own engine reads the study and draws it on the chart's bars. This page explains how, and lists what works today.
- Studies, not strategies. Plots, clouds, labels, bubbles, bar colours and alerts work. Orders and backtests (
AddOrder) do not. - It runs in your browser, in a sandbox. The study cannot reach the internet, your account or other pages. A study that runs too long is stopped.
- Inputs become settings. Every
inputshows in the indicator settings, so you can change it without editing the code.
Education only. Not financial advice.
Add a study
- Open ZoroCharts and click the script editor button in the toolbar.
- In the switch at the top of the editor, pick thinkScript.
- Paste your study, or open one of the five Examples.
- Give it a name and press Add to chart. Studies with
declare lower;get their own pane. - To change an input, open the study's settings on the chart (the gear next to its name).
Problems show under the code with a line and column, for example Line 3:10 Unknown function "Averag". Click a problem to jump to it. Save keeps the study in My scripts in this browser.
# A pasted study: two averages and a label
input length = 20;
input averageType = AverageType.EXPONENTIAL;
plot Avg = MovingAverage(averageType, close, length);
Avg.SetDefaultColor(Color.CYAN);
plot Cross = close crosses above Avg;
Cross.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
AddLabel(yes, "Average " + Round(Avg, 2), Color.CYAN);
Language
| Part | What works |
|---|---|
| Values | def, rec, plot, numbers, text in quotes, yes / no, Double.NaN and IsNaN() |
| Inputs | whole numbers, decimals, text, yes/no, a price (close, hl2 ...), a list {default a, b}, AverageType.X |
| Declares | declare lower, upper, once_per_bar, hide_on_intraday, hide_on_daily |
| Choices | if ... then ... else values, if { } else { } blocks, switch / case / default |
| History | close[1] (bars ago), close[-1] (bars ahead), GetValue, CompoundValue, a def that reads its own past |
| Loops | fold i = 0 to n with s do ..., with while |
| Your own functions | script Name { input ...; plot ...; }, called as Name(1, 2).PlotName |
| Operators | + - * / %, == != <> < > <= >=, and or not, crosses, crosses above, crosses below |
| Bar data | open high low close volume hl2 hlc3 ohlc4 barNumber, and another timeframe with close(period = AggregationPeriod.DAY) |
| Display | SetPaintingStrategy, SetDefaultColor, AssignValueColor, SetLineWeight, SetStyle, Hide, HideBubble, HideTitle, AddCloud, AddLabel, AddChartBubble, AddVerticalLine, AssignPriceColor, Alert |
Names are not case-sensitive: average, Average and AVERAGE are the same. Labels from AddLabel sit in a row at the top of the study's pane. An Alert that is true on the newest bar shows a notice on the chart and plays the alert sound.
Functions (100)
- AbsValue
- ACos
- ASin
- ATan
- Ceil
- Cos
- Exp
- Floor
- Lg
- Log
- Sign
- Sin
- Sqr
- Sqrt
- Tan
- IsNaN
- IsInfinite
- Max
- Min
- Power
- Round
- RoundDown
- RoundUp
- Random
- Between
- Average
- SimpleMovingAverage
- ExpAverage
- WMA
- WildersAverage
- HullAverage
- MovingAverage
- Highest
- Lowest
- Sum
- StDev
- LinDev
- Median
- Inertia
- LinearRegressionSlope
- Correlation
- Covariance
- IsAscending
- IsDescending
- GetMaxValueOffset
- GetMinValueOffset
- TrueRange
- GetValue
- CompoundValue
- Crosses
- HighestAll
- LowestAll
- TotalSum
- StDevAll
- InertiaAll
- BarsSince
- ValueWhen
- SarValue
- BarNumber
- GetTime
- GetDay
- GetYYYYMMDD
- GetYear
- GetMonth
- GetWeek
- GetLastDay
- GetLastYYYYMMDD
- GetLastMonth
- GetLastYear
- getlastweek
- CountTradingDays
- GetDayOfWeek
- GetDayOfMonth
- DaysFromDate
- DaysTillDate
- SecondsFromTime
- SecondsTillTime
- RegularTradingStart
- RegularTradingEnd
- GetAggregationPeriod
- GetSymbol
- GetSymbolPart
- TickSize
- TickValue
- IsRealtime
- Concat
- AsText
- AsPrice
- AsDollars
- AsPercent
- CreateColor
- GetColor
- GlobalColor
- AddLabel
- AddChartBubble
- AddVerticalLine
- AddCloud
- AssignPriceColor
- Alert
- DefineGlobalColor
Built-in studies (66)
Call them like functions and pick a plot by name, for example RSI(14), MACD().Diff or BollingerBands(length = 20).UpperBand.
- SimpleMovingAvg
- MovAvgExponential
- MovAvgWeighted
- WildersSmoothing
- HullMovingAvg
- RSI
- MACD
- BollingerBands
- BollingerBandwidth
- BollingerPercentB
- ATR
- AverageTrueRange
- StochasticFull
- StochasticSlow
- StochasticFast
- StochRSI
- WilliamsPercentR
- CCI
- DMI
- ADX
- VWAP
- Momentum
- RateOfChange
- Ichimoku
- ParabolicSAR
- OnBalanceVolume
- MoneyFlowIndex
- AccDist
- ChaikinMoneyFlow
- ChaikinOsc
- AwesomeOscillator
- KeltnerChannels
- PriceChannel
- DonchianChannel
- TRIX
- TrueStrengthIndex
- UltimateOscillator
- AroonIndicator
- AroonOscillator
- VolumeAvg
- DetrendedPriceOsc
- PPO
- LinearRegCurve
- StandardDeviation
- HistoricalVolatility
- ElderRayIndex
- PercentChg
- SuperTrend
- MovAvgTriangular
- DEMA
- TEMA
- VWMA
- MovAvgAdaptive
- ChandeMomentumOscillator
- ForceIndex
- EaseOfMovement
- PriceVolumeTrend
- MassIndex
- VortexIndicator
- ChoppinessIndex
- BalanceOfPower
- CoppockCurve
- RelativeVolatilityIndex
- ATRTrailingStop
- StandardErrorBands
- KlingerOscillator
Constants
| Group | Members |
|---|---|
Color | BLACK, WHITE, RED, GREEN, BLUE, YELLOW, ORANGE, CYAN, MAGENTA, GRAY, DARK_GRAY, LIGHT_GRAY, DARK_GREEN, LIGHT_GREEN, DARK_RED, LIGHT_RED, DARK_ORANGE, LIGHT_ORANGE, LIME, PINK, PLUM, VIOLET, UPTICK, DOWNTICK, CURRENT |
AverageType | SIMPLE, EXPONENTIAL, WEIGHTED, WILDERS, HULL |
AggregationPeriod | MIN, TWO_MIN, THREE_MIN, FOUR_MIN, FIVE_MIN, TEN_MIN, FIFTEEN_MIN, TWENTY_MIN, THIRTY_MIN, HOUR, TWO_HOURS, FOUR_HOURS, DAY, TWO_DAYS, THREE_DAYS, FOUR_DAYS, WEEK, MONTH, QUARTER, YEAR |
PaintingStrategy | LINE, HISTOGRAM, POINTS, ARROW_UP, ARROW_DOWN, BOOLEAN_ARROW_UP, BOOLEAN_ARROW_DOWN, BOOLEAN_POINTS, BOOLEAN_WEDGE_UP, BOOLEAN_WEDGE_DOWN, SQUARED_HISTOGRAM, HORIZONTAL, DASHES, TRIANGLES, SQUARES, LINE_VS_POINTS, LINE_VS_TRIANGLES, LINE_VS_SQUARES, VALUES_ABOVE, VALUES_BELOW |
Curve | FIRM, LONG_DASH, MEDIUM_DASH, SHORT_DASH, POINTS |
Alert | BAR, ONCE, TICK, TRIGGER |
Sound | Bell, Chimes, Ding, NoSound, Ring |
CrossingDirection | ABOVE, BELOW, ANY |
Double | NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY, Pi, E |
Location | TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT |
FontSize | SMALL, MEDIUM, LARGE |
NumberFormat | TWO_DECIMAL_PLACES, THREE_DECIMAL_PLACES, DOLLAR, WHOLE_NUMBER |
PriceType | LAST, BID, ASK, MARK |
Not supported
- Strategies and orders:
declare strategy,AddOrder,EntryPrice,GetQuantityand the other position values. - Scan-only and watchlist-only functions, fundamentals, options chain values and account values.
- Drawing tools that only exist on other platforms. Use plots, clouds, labels and bubbles.
Limits
- Up to 8 thinkScript studies per chart, 256 KB per study, 50,000 bars.
- A
foldcan run up to 20,000 times on one bar. There is no time limit: a long study keeps going until it finishes or you remove it. - Another timeframe or symbol is loaded through the chart. It must be the chart's timeframe or longer.
- Results can differ slightly from other platforms where the first bars of an average are seeded differently. Check a study against a chart you trust before you rely on it.
thinkScript is the name of the language. TradeZoro wrote its own engine for it. Education only. Not financial advice.