# Kibana dashbord trading candle

**URL:** <https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600>\
**Category:** Kibana\
**Created:** [November 16, 2020, 10:52pm UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600 "2020-11-16T22:52:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adriann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adriann/32/77780_2.png) [@Adriann](https://discuss.elastic.co/u/Adriann)\
**Post date:** [November 16, 2020, 10:52pm UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/1 "2020-11-16T22:52:47Z")

</div>

Hello,

giving this example data,  
Is It possible to make trading candle in kibana? Maybe using timelion?

```
{'crypto.candle.close': '16746.10000000',
  'crypto.candle.closeTime': '2020-11-16T22:59:59Z',
  'crypto.candle.high': '16768.79000000',
  'crypto.candle.intervalName': '1MINUTE',
  'crypto.candle.low': '16650.00000000',
  'crypto.candle.name': 'BTCUSDT',
  'crypto.candle.numberOfTrades': 52927,
  'crypto.candle.open': '16695.41000000',
  'crypto.candle.openTime': '2020-11-16T22:00:00Z',
  'crypto.candle.quoteAssetVolume': '33524105.17010261',
  'crypto.candle.takerBuyBaseAssetVolume': '1006.47549000',
  'crypto.candle.takerBuyQuoteAssetVolume': '16822669.52254529',
  'crypto.candle.volume': '2005.95127300'}]

```

Candle example

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/5/c5d07410dffe1ebc7602bc5bfe29d9ade6132be9.jpeg)

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [November 16, 2020, 10:55pm UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/2 "2020-11-16T22:55:49Z")

</div>

You can in Vega. But it will be 100% custom and nothing really out of the box.

---

<div class="post-metadata">

**Author:** ![Adriann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adriann/32/77780_2.png) [@Adriann](https://discuss.elastic.co/u/Adriann)\
**Post date:** [November 17, 2020, 12:05am UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/3 "2020-11-17T00:05:52Z")

</div>

@aaron-nimocks  
Hi thanks for your hint with VEGA.

Can you help me one more time with a hint what am I doing wrong?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/4/b45291113af199d6f2c917c8111c10445eb82e48.png)

```
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": 800,
    "autosize": {
    "type": "fit",
    "contains": "padding"
  },
  "description": "A candlestick chart inspired by an example in Protovis (http://mbostock.github.io/protovis/ex/candlestick.html)",
  "data": {url: {
  // Specify the time filter.
  %timefield%: crypto.candle.openTime
  // Apply dashboard context filters when set
  %context%: true

  // Which indexes to search
  index: "crypto-*"
  // The body element may contain "aggs" and "query" keys
  body: {
    aggs: {
      time_buckets: {
        date_histogram: {
          // Use date histogram aggregation on @timestamp field
          field: "crypto.candle.openTime"
          // interval value will depend on the time filter
          // Use an integer to set approximate bucket count
          // interval: { %autointerval%: true }
          "interval": "1h"
          // Make sure we get an entire range, even if it has no data
          // extended_bounds: {
          // min: { %timefilter%: "min" }
          // max: { %timefilter%: "max" }
          // }
          // Use this for linear (e.g. line, area) graphs
          // Without it, empty buckets will not show up
          min_doc_count: 1
        }
      }
    }
    // Speed up the response by only including aggregation results
    size: 0
  }
}},
  "encoding": {
    "x": {
      "field": "key",
      "type": "temporal",
      "title": "Date",
      "axis": {
        "format": "%Y-%m-%dT%H:%M:%SZ",
        "labelAngle": -45,
        "title": "Date"
      }
    },
    "y": {
      "type": "quantitative",
      field: "doc_count",
      "scale": {"zero": false},
      "axis": {"title": "Price"}
    },
    "color": {
      "condition": {
        "test": "datum.open < datum.close",
        "value": "#06982d"
      },
      "value": "#ae1325"
    }
  },
  "layer": [
    {
      "mark": "rule",
      "encoding": {
        "y": {"field": "crypto.candle.low"},
        "y2": {"field": "crypto.candle.high"}
      }
    },
    {
      "mark": "bar",
      "encoding": {
        "y": {"field": "crypto.candle.open.max"},
        "y2": {"field": "crypto.candle.close.max"}
      }
    }
  ]
}

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/e/8e27c35cbb4bbf470f610607816044035db31d88.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/d/7de672f6f924cd709fb6db5d94810d7a2d4b21e2.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/6/66ba69a5c9ab81faf90a34b4a60216198dc147ac.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/e/9eb7f1f3b0c4768754dcb7d37b1ce49838b2ebe9.png)

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [November 17, 2020, 12:45am UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/4 "2020-11-17T00:45:06Z")

</div>

Not sure I understand your data and query but if you want to start with the visualization first you can use the Vega Editor and hardcode the data.

I [started it and did a basic design](https://vega.github.io/editor/#/url/vega/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykSArJQBWENgDsQAGhAB3GgBN6aAEwCADDPg0yWVRplIGmNhBoAvOGhDiJVmQqSYUqANqhxSBFfTOmAG3sQYiR-BjgINFAoACcATxwTSigkcQVA5P9THxAARgA2AHYAFnzKXPVKqvVpEFiEpJS0jKgsiDgAFRpvaxV1PoBaXNyh-I6VFVQBAE4p6YAtWvrEtmTU9LhKGB0YawLC-IAOSkLp6sql+JW15s2acUw4GJD-ADkvHNyAWQBJV4BVDoAUUuDVWTQ2lCysj2+XyGko5yqoOuEIynh66AAQh0AML-ADKABEOijGut0QwEEwngB5ABmHRiSAUETQAhU0xUhRky3Jt0obBwcEk6AK+WmQmKFXOZPBFM2QpFXUxID6g2Go3Gk0qqEqi15V35kIAjgw2I8AIIQdqYABqbDCqoAzM6OdL1EJcoV1BUVPlcnKbpDnABrJ5YhhxLFIdrW20Op2fSplYqFATFM4XQ1g4MZMMRqMARXNVptcHtjqpnyOEzh00oHLUxQ50yDaM2xCrqr6nsokty3OdFwAviOALoyZAxUORNygTAJHKPAAemFq9JibAQURAjmc1j8gRAI5kIqgbFZu5Fjxiu-pNH8-l3L3C1gAxMjTyBV+vUKBXxyAAJHYTxkFcX1CN9UAqb84kgsIfFgwx-B0UUAKgnJAnpdcxzHKQFyXQ84DXDctx3f89ycFwfyQAIrG-c9Lx8UAbyee9H2fSjAI-L8ZF-BDoJAXE2gY8DBKQ9Q4Ik9kpJQtCZPQbDcLwgifyI3wSPXGRN23Xd9xoo8xJAJir0oti70oh8n0UkBP1HfitNs2lhUkb8IO4zC0GQkB4M8xDvI0b9QgU-yhOUk9VMI4ViNInTyP06jDzo49GPEC8zNYh52KszjbPsmpvwEsKcgAGTYGF3MUny-IwgKYLOYLULIdDgi8pS4BwyL8OinIYgYY94r0yiDOS+iwJM9LmOvbLLNACBMC3cN8vhFQoDOCaPLq6CgpkWq2vqnyVxUardt8k6Su8qSovUmL0H6waQF0ijQFG3wUuM0yWMm29dwWpbvp49B31W9bCvEy6pjk3zFLO47TuhuILu2nwgpuxc7pAB6gmexKD3e8a0oy76LL+xa2GWyG7NBjaqshs79qB3I4eRg7oOZxHWaZtGetuvqBpxhKRqSgnUrPKbMp+nL5vJymUY-GnwZALa2dRxHqsa8Cufajm4O1w7GvRjSsYFsjhtekXaMJ8XiZm37KP+inAfakAyBiOARU26r02kyGjv19mfb2gOkMN3mMb6uAoG0ybbfM2aOJsqm3Y9tyIflmD8hUX2M+KaH5CUXZIbUb9tF0P8M5lPCJxHIA) of what I think you are looking for. The hard part is doing the transformations/math to get the boxes in the right spot. Then you can conditionally color the boxes to be green or red.

Does this help at all?

---

<div class="post-metadata">

**Author:** ![Adriann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adriann/32/77780_2.png) [@Adriann](https://discuss.elastic.co/u/Adriann)\
**Post date:** [November 17, 2020, 12:53am UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/5 "2020-11-17T00:53:59Z")

</div>

It surely will. I will try that. Basically what I think my problem is how to reference correctly the fields in a document.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [November 17, 2020, 1:02am UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/6 "2020-11-17T01:02:23Z")

</div>

```auto
  "data": {
    "url": {
      "%context%": true,
      "%timefield%": "@timestamp",
      "index": "_all",
      "body": {
        "aggs": {
          "time_buckets": {
            "date_histogram": {
              "field": "@timestamp",
              "interval": {"%autointerval%": true},
              "extended_bounds": {
                "min": {"%timefilter%": "min"},
                "max": {"%timefilter%": "max"}
              },
              "min_doc_count": 0
            }
          }
        },
        "size": 0
      }
    },
    "format": {"property": "aggregations.time_buckets.buckets"}
  },

```

That's the default example when you create a new visualization. The bottom `format` field is what I think you are looking for. Except yours would be like `{"property": "aggs.time_buckets.buckets"}`. Then you can reference the data like `_source.crypto.candle.high`

---

<div class="post-metadata">

**Author:** ![Adriann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adriann/32/77780_2.png) [@Adriann](https://discuss.elastic.co/u/Adriann)\
**Post date:** [November 17, 2020, 1:59am UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/7 "2020-11-17T01:59:06Z")

</div>

> [@aaron-nimocks](#):
>
> ```auto
> "body": {
> "aggs": {
> "time_buckets": {
> "date_histogram": {
> "field": "@timestamp",
> "interval": {"%autointerval%": true},
> "extended_bounds": {
> "min": {"%timefilter%": "min"},
> "max": {"%timefilter%": "max"}
> },
> "min_doc_count": 0
> }
> }
> }
> 
> ```

I have tried a few iterations with your example but I still was shown the error of

```
Infinite extent for field "_source.crypto.candle.openTime": [Infinity, -Infinity]

Infinite extent for field "_source.crypto.candle.openTime": [Infinity, -Infinity]

Infinite extent for field "_source.crypto.candle.low": [Infinity, -Infinity]

Infinite extent for field "_source.crypto.candle.high": [Infinity, -Infinity]

Infinite extent for field "_source.crypto.candle.open": [Infinity, -Infinity]

Infinite extent for field "_source.crypto.candle.close": [Infinity, -Infinity]

```

Then I tried also this one with the same result 😕

```
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": 800,
    "autosize": {
    "type": "fit",
    "contains": "padding"
  },
  "description": "A candlestick chart inspired by an example in Protovis (http://mbostock.github.io/protovis/ex/candlestick.html)",
   "data": {
    "url": {
      "%context%": true,
      "%timefield%": "crypto.candle.openTime",
      "index": "_all",
      "body": {
      "aggs": {
    "time_buckets": {
      "date_histogram": {
        "field": "crypto.candle.openTime",
        "calendar_interval": "1h",
        "time_zone": "Europe/Warsaw",
        "min_doc_count": 1
      },
      "aggs": {
        "1": {
          "max": {
            "field": "crypto.candle.high"
          }
        },
        "3": {
          "top_hits": {
            "docvalue_fields": [
              {
                "field": "crypto.candle.close"
              }
            ],
            "_source": "crypto.candle.close",
            "size": 1,
            "sort": [
              {
                "crypto.candle.openTime": {
                  "order": "desc"
                }
              }
            ]
          }
        },
        "4": {
          "min": {
            "field": "crypto.candle.open"
          }
        },
        "5": {
          "top_hits": {
            "docvalue_fields": [
              {
                "field": "crypto.candle.open"
              }
            ],
            "_source": "crypto.candle.open",
            "size": 1,
            "sort": [
              {
                "crypto.candle.openTime": {
                  "order": "asc"
                }
              }
            ]
          }
        }
      }
    }
  
        },
        "size": 0
      }
    },
    "format": {"property": "aggregations.time_buckets.buckets"}
  },

  "encoding": {
    "x": {
      "field": "_source.crypto.candle.openTime",
      "type": "temporal",
      "title": "Date",
      "axis": {
        "format": "%Y-%m-%dT%H:%M:%SZ",
        "labelAngle": -45,
        "title": "Date"
      }
    },
    "y": {
      "type": "quantitative",
      "scale": {"zero": false},
      "axis": {"title": "Price"}
    }
    // ,
    // "color": {
    // "condition": {
    // "test": "datum.open < datum.close",
    // "value": "#06982d"
    // },
    // "value": "#ae1325"
    // }
  },
  "layer": [
    {
      "mark": "rule",
      "encoding": {
        "y": {"field": "_source.crypto.candle.low"},
        "y2": {"field": "_source.crypto.candle.high"}
      }
    },
    {
      "mark": "bar",
      "encoding": {
        "y": {"field": "_source.crypto.candle.open"},
        "y2": {"field": "_source.crypto.candle.close"}
      }
    }
  ]
}

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/8/48ff4e2c44e63b9bf7de2a264f08f02f476bec48.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/a/3ac776f5a39b46ff71c2652d223645bea7e951b0.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/6/e6806c58ce9b76ae9e13b56e038f442a16a03967.png)

---

<div class="post-metadata">

**Author:** ![Adriann](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adriann/32/77780_2.png) [@Adriann](https://discuss.elastic.co/u/Adriann)\
**Post date:** [November 17, 2020, 2:38am UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/8 "2020-11-17T02:38:45Z")

</div>

Ok, so I got something moving.

This is how It looks right now and how my query looks like. I will work more on this now I have a much bigger understanding of these tools. @aaron-nimocks thank you very much for your input!

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/3/5328baca3546223a39a0baf62be01d3636003565.png)

```
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "width": 800,
    "autosize": {
    "type": "fit",
    "contains": "padding"
  },
  "description": "A candlestick chart inspired by an example in Protovis (http://mbostock.github.io/protovis/ex/candlestick.html)",
   "data": {
    "url": {
      "%context%": true,
      "%timefield%": "crypto.candle.openTime",
      "index": "_all",
      "body": {
      "aggs": {
    "time_buckets": {
      "date_histogram": {
        "field": "crypto.candle.openTime",
        "calendar_interval": "1h",
        "time_zone": "Europe/Warsaw",
        "min_doc_count": 1
      },
      "aggs": {
        "high": {
          "max": {
            "field": "crypto.candle.high"
          }
        },
        "open": {
          "max": {
            "field": "crypto.candle.open"
          }
        },
        "close": {
          "min": {
            "field": "crypto.candle.close"
          }
        },
        "low": {
          "max": {
            "field": "crypto.candle.low"
          }
        },
      }
    }
  
        },
        "size": 0
      }
    },
    "format": {"property": "aggregations.time_buckets.buckets"}
  },

  "encoding": {
    "x": {
      "field": "key",
      "type": "temporal",
      "title": "Date",
      // "axis": {
      // "format": "%Y-%m-%dT%H:%M:%SZ",
      // "labelAngle": -45,
      // "title": "Date"
      // }
    },
    "y": {
      "type": "quantitative",
      "scale": {"zero": false},
      "axis": {"title": "Price"}
    }
    // ,
    // "color": {
    // "condition": {
    // "test": "datum.open < datum.close",
    // "value": "#06982d"
    // },
    // "value": "#ae1325"
    // }
  },
  "layer": [
    {
      "mark": "rule",
      "encoding": {
        "y": {"field": "high.value"},
        "y2": {"field": "low.value"}
      }
    },
    {
      "mark": "bar",
      "encoding": {
        "y": {"field": "close.value"},
        "y2": {"field": "open.value"}
      }
    }
  ]
}
```

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [November 17, 2020, 1:58pm UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/9 "2020-11-17T13:58:24Z")

</div>

Nice. Looks like you are catching on quickly. If you need anything else with this please open a new thread and feel free to tag me. Good luck!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 15, 2020, 1:58pm UTC](https://discuss.elastic.co/t/kibana-dashbord-trading-candle/255600/10 "2020-12-15T13:58:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
