When something looks wrong
Errors show the line number and what went wrong. If there is no error and the picture is not what you expected, check this list.
| What you see | Why, and what to do |
|---|---|
| A line starts part-way along the chart | A lookback such as ta.sma(close, 200) has no value until 200 bars exist. The early bars are na. |
| Two equal prices are not equal | Prices are decimals computed from integer points. Compare with a tolerance: math.abs(a - b) < syminfo.mintick / 2. |
| Hundreds of labels or lines, then old ones vanish | line.new inside a plain statement makes a new one every bar, and the oldest is deleted at the limit. Declare it with var, or delete the old one first. |
| An array element read gives the wrong thing | a[i] is the history operator, not element access. Use a.get(i). |
| “index out of range” or an empty array error | The index is outside the array, or you called pop, shift, first or last on an empty one. Check size() first. |
| “Cannot read 'x': the value is na” | The object was never created (var p = na). Create it with Name.new(...) before you read a field. |
| “There is no method ... for that value” | The method is defined for another type, or the value is not what you think. Check the first parameter's type. |
| “There is no library called ...” | The library is not saved, or its library("Name") title differs from the name in the import. Save the library and check the spelling. |
| “In library 'X', line N: ...” | The error is inside the library, not in the script that imports it. Open the library, fix that line, and save. |
| Add to chart says the script is a library | Libraries are imported, not added. Save it and write import in an indicator. |
| A higher-timeframe line is stepped | That is correct. It changes only when a higher-timeframe bar closes. See Other timeframes. |
A request.security error about a variable | The expression uses a variable changed with := or declared with var, which cannot be recomputed on the higher timeframe. Put the calculation inside the expression. |
A ta.* inside if reads too little history | Its argument changes from bar to bar, so skipped bars cannot be replayed. Call it outside the if and use the result inside. |
| A drawing is not visible | Labels, lines and boxes do not affect the price scale. One far outside the visible prices is off screen. |
| Stopped after 500,000 iterations | A loop on one bar never ended or is too large. Check its exit condition. |
| A value differs from TradingView | See Where it differs from TradingView: ta.ema seeding, pivots reported late, and ta.kc using an EMA of the true range. |