Comments (6)
In principle it should be fine to add a different checker for each data type. It would probably only add a tiny bit to the bundle size and be easy to implement. So if you create a PR and the increase to the bundle size is tiny then we would consider merging it.
Whether it is required is still debatable because the types for LineData
wouldn't actually let you have open
or other extra properties. If you tried this in Typescript then you would get a compiler error. I know not everyone uses TS, so this issue wouldn't be known until runtime for vanilla JS developers.
The suggested approach would be to modify your addSMAValue
function such that it returns only data containing time
and value
(optional) instead of adding value
to existing bar data. You wouldn't want to be mutating the existing candles data anyway so if you are creating a new array for the sma values then it should also be easy to only include the expected properties.
Additionally, we actually already have a code sample for an SMA indicator on candles data here: https://jsfiddle.net/TradingView/537kjtfg/
It was written a few years ago, and you can ignore most of the code (which is displaying a legend, and generating random but realistic candle data), but you can pay attention to the calculateSMA
function
from lightweight-charts.
It depends on the type of series that the data is intended for. The library expects one of the following:
- 'Line type' data, which has
value
- or 'Bar type' data, which has
open
,high
,low
,close
As you can see there is no overlap of keys thus it is safe to check if the data is fulfilled by checking if either open
or value
are supplied. You shouldn't be supplying partially complete bars, or extra information in the data. If you do need to use extra info then make use of the customValues
key.
from lightweight-charts.
I see that and I may not be using the API as intended, but it does seem like an unintended side effect. As I start with my candles and I compute my signal and add that as a the value. Then I pass the new data array as the argument for my line.
Psuedocode:
candles = getCandles('TSLA')
sma = addSMAValue(candles)
candleStickSeries.setData(candles)
lineSeries.setData(sma)
However, for the first values in the line series with undefined values (like sma_30) will error out saying "... series item data value of open must be a number ... " from here, since the validator will be true as (open OR value) is present.
Specifically, I had to change my code as follows:
// FROM: errors because `open` is present
const data = candles.map((bar, i) => {
const value = smaValues[i - diff]
return value ? { ...bar, value } : bar
})
// TO: when value is invalid, only include time
const data = candles.map((v, i) => {
const value = smaValues[i - diff]
return value ? { ...v, value } : { time: v.time }
})
I ask, because it seems it's a bug for line series to tell me open
is causing an issue even though it never uses that value for anything and causes an exception to be thrown.
Edit: The assert is from the checkLineItem
function here, which uses the same validation as checkBarItem
.
from lightweight-charts.
I guess I'm just asking if there could instead be a isFulfilledBarData
and isFulfilledLineData
instead of only a isFulfilledData
? I can make a PR if you think this is something to be considered.
from lightweight-charts.
I guess I've already written the code to avoid the issue so it's solved for me in a way, but when doing something quick I keep running into it. I use TS but I didn't see a compiler error, I'll look into that too. I should have time soon to try out a PR and see how the build size changes, it'll give me a better understanding of that portion of the code too. Thanks.
from lightweight-charts.
Related Issues (20)
- Seconds Hours Minutes HOT 4
- `hoveredObjectId` (`subscribeCrosshairMove`) is not set for a marker crossed by price line HOT 1
- Pop time series data HOT 2
- `setCrosshairPosition` does not emit events to `subscribeCrosshairMove` handlers. HOT 5
- Adding points or bars while scrolling leads to timescale jumps HOT 1
- How to stop zoom feature ? HOT 1
- `hoveredObjectId` (`subscribeCrosshairMove`) is not updated when chart is scrolled horizontally
- How to get the price of the horizontal line of crosshair HOT 2
- Lightweight view turns black and cannot be restored
- Change area fill color ? HOT 1
- Feature: Get priceLines from `ISeriesAPI`
- Setting addCandlestickSeries and addHistogramSeries at the same time not working HOT 1
- The "dataByIndex" always retrieves the oldest value
- 想請問charting_library 儲存庫
- Bug: invalid @babel/generator version on install (v4.2.0) HOT 2
- Lines with different y-axis values HOT 1
- How to make right side graph faded in color, while scroling the from right to left : Tradingview light Android HOT 3
- Rectangle plugin HOT 1
- Trend Line plugin doesn't respect showLabels option
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightweight-charts.