NeBox
Posts: 53
Joined: Sun Feb 05, 2023 4:12 am

The last two prices in lastPrice

Hi

I am using the lastprice module which dynamically changes the price and the last bar

I have a question to output two prices ASK and BID
How can I do it ? I have not found information to output two prices.

It can be very important to watch both prices
sdsdvcccc.png
sdsdvcccc.png (13.51 KiB) Viewed 1216 times
jedrzej.r
Posts: 742
Joined: Tue Jan 24, 2023 11:21 am

Re: The last two prices in lastPrice

Hi!

To achieve such result, you can utlize the formatter callback function that allows to customize output of the lastVisiblePrice label.

Demo: https://jsfiddle.net/BlackLabel/5sLgfw0t/

API: https://api.highcharts.com/highstock/pl ... .formatter

Let me know if that's what you were looking for.
Best regards!
Jędrzej Ruta
Highcharts Developer
NeBox
Posts: 53
Joined: Sun Feb 05, 2023 4:12 am

Re: The last two prices in lastPrice

Hi.

Thanks for the reply.

I am using the lastPrice module which dynamically updates the last bar from the bid price and I am trying to add separately a line with ASK price

They are not supposed to be together. Trading systems and web traders use two separate ASK\BID lines.
eeeeeeeee.png
eeeeeeeee.png (10.65 KiB) Viewed 1189 times

Or can you tell me how I can add a plotline with the same label as lastprice so I can dynamically change it.
Because it is an important thing with trading, to see two prices.
jedrzej.r
Posts: 742
Joined: Tue Jan 24, 2023 11:21 am

Re: The last two prices in lastPrice

Could you please provide a minimal reproducible demo showing the usage of lastPrice module, so that I can investigate it and come up with a solution?
Jędrzej Ruta
Highcharts Developer
NeBox
Posts: 53
Joined: Sun Feb 05, 2023 4:12 am

Re: The last two prices in lastPrice

Hi
You can see an example of how lastprice works in your demo https://www.highcharts.com/demo/stock/live-candlestick
Only I don't have a new bar added, it just updates the last bar

The module accepts bid price
ASK price should not be bound to a bar. It should just create a line and label with the price and it could be dynamically updated. So that a person can see both prices, not just one.
NeBox
Posts: 53
Joined: Sun Feb 05, 2023 4:12 am

Re: The last two prices in lastPrice

If creating a second line is difficult, maj. there is a second option.

Maybe I can make a copy of the price_indicator module ?
I looked it up, it's not big. Maybe you can tell me how to make a copy of the module so that it just adds a new line with a price without linking to a bar?
jedrzej.r
Posts: 742
Joined: Tue Jan 24, 2023 11:21 am

Re: The last two prices in lastPrice

To be honest, I think the easiest way of achieving such result would be by enabling lastPrice for the ASK price by e.g. setting it up as another series and making it invisible. This way, you can still show the lastPrice without doing some modifications to your solution.

Demo: https://jsfiddle.net/BlackLabel/dcpyemva/

Let me know if that was helpful for you.
Best regards!
Jędrzej Ruta
Highcharts Developer
NeBox
Posts: 53
Joined: Sun Feb 05, 2023 4:12 am

Re: The last two prices in lastPrice

Hi.

I apologize for the long reply.

I am missing label if I set visible: false,

The price is not updated even though I put the update in this series.

I can't give you a sample code as we are testing the integration.

I have made an update according to the example here https://jsfiddle.net/BlackLabel/uv7egbfo/

can't get two prices (ASK and BID) to be updated
pi-line.png
pi-line.png (7.3 KiB) Viewed 1055 times
NeBox
Posts: 53
Joined: Sun Feb 05, 2023 4:12 am

Re: The last two prices in lastPrice

I don't think it's the right solution to add another series for the sake of displaying the last price.

Is there any way to add a second line through the price-indicator module itself?
jedrzej.r
Posts: 742
Joined: Tue Jan 24, 2023 11:21 am

Re: The last two prices in lastPrice

Hi again!

Unfortunately, it's not possible to add a second line using the price indicator module, as there can be only one lastPrice indicator for each series. On the other hand, this solution makes use of drawing y-axis crosshairs with labels, so you can utilize it by drawing a fixed crosshair at the last point. Note that i had to call the crosshair draw method for mousemove and mouseleave events, so that it's always shown for the last point on the chart.

Demo: https://jsfiddle.net/BlackLabel/by5tgwpc/

Reference:
https://api.highcharts.com/class-refere ... wCrosshair

Let me know if that was helpful for you.
Best regards!
Jędrzej Ruta
Highcharts Developer
NeBox
Posts: 53
Joined: Sun Feb 05, 2023 4:12 am

Re: The last two prices in lastPrice

Hi.

I finally realized that the price-indicator module is useless.
In trading I need to see two prices Open and Close
Price-indicator shows one price and has no possibility to show the second one.
At the same time it has an error. (possibly fixed).
If we show the price-indicator module and dynamically update prices (which should be the case), the price-indicator module starts deleting bars in case of swiping or scrolling the chart.

I solved this problem by turning off the price-indicator module if the chart starts scrolling.

Now I have solved the problem of two prices using price-indicator and plotline

In the end I came to the opinion that price-indicator can be removed at all and just add two plotlines.

Code: Select all

plotLines: [
	{
		value: 0,
		color: '#d1d1d2',
		dashStyle: 'solid',
		width: 1,
		id: 'openPrice',
		zIndex: 5,
		label: {
			text: "0",
			align: 'right',
			style: {
				backgroundColor: '#d1d1d2',
				color: '#323232',
				padding: '2px',
				fontWeight: 'bold',
				borderRadius: '2px 2px 2px 0'
			},
			x: 48, 
			y:-6,
		}
	}
]
To dynamically update the price I added

Code: Select all

chart.yAxis[0].plotLinesAndBands[0].options.value = price_ask;
chart.yAxis[0].plotLinesAndBands[0].label.attr({
	text: price_ask
});
It's a question of resources

Which consumes less resources?
Draw price_indicator module
or add two plotlines ?

Ideally make it possible for the price_indicator module to add multiple lines

Thank you for your help!
jakub.s
Posts: 1266
Joined: Fri Dec 16, 2022 11:45 am

Re: The last two prices in lastPrice

Hi NeBox!

Absolutely, if you notice any problems like that, it would be great if you could:
1. create a minimal reproducible example
2. describe all the problems thoroughly
3. report an issue on the Highcharts repository here: https://github.com/highcharts/highcharts/issues where our developers will investigate it

When it comes to the second part of your question, adding two plotlines will be just as efficient and performant for this case so no worries about this. A very similar thing is being done in the last-price module so the performance difference will be negligible. If the behavior is better with your custom approach, feel free to use it.

Best regards!
Jakub
Highcharts Developer

Return to “Highcharts Stock”