How to draw trendlines in lightweight-charts with left or right extension? - lightweight-charts

How to draw lines between any two highs or lows of the candlestick bars to make a slanted trend line that can extend to left or right or both directions?
Extending left or right by creating a custom series manually using y = mx + b formula seems plausible, but a direct straight-forward method would be more appropriate.

It's impossible right now. lightweight-charts doesn't support drawings at all (except workaround for drawing trend line with series with the only 2 points).
We aren't going to add drawing itself to the library, but we thought about extending the API to allow you draw on canvas directly. If you'd like to use drawings, I can suggest you take a look at charting_library.

Related

Drawing a bar chart in the background of candlestick chart in apexchart

I am playing with candlestick graphs (example from here: https://apexcharts.com/javascript-chart-demos/candlestick-charts/basic/) everything work as expected.
However, I am struggling with adding my signal data for a visual representation of the graph.
I am unable to find a solution that works I was thinking I can somehow fine-tune a timeline - I tried chart.js/apexcharts and for now, I believe the closest will be with the second framework.
What I need is a bar chart that can be used in numeric ranges for the X and Y-axis as presented below. (the goal is to be able to add the green bar as presented)
Is there an easy win or an idea of how to approach this?
Is there something I am missing?
That is my current solution (line graphs with stopWin/stopLose and entry price).
Still suboptimal - but works and is easy to achieve.
After weeks of playing around with it - the solution stayed:
I got two instances of apexcharts one with candlestick and one with line graphs
they are in a single div with CSS playground and position absolute.
I am passing standardised min/max values and has to have the same amount of elements in them (line graphs are allowing You to add null values which allow using this solution.
The final version work is repeatable and looks good.
if you need some help in similar case - feel free to reach out ;)

Draw curves to make arrows in the Codename One GlassPane

In a CodenameOne App, I need to draw curved arrows in the GlassPane. The use of the GlassPane is not mandatory, however I've already used some layers in the ContentPane and some layers in the LayeredPane, so I suppose that the GlassPane is the best option to be sure that the arrows are "over" the app.
The arrows should be like the following ones:
I suppose that I can create an algorithm that decides the absolute X and Y coordinates of the "Start" and "End" points, more other few points (P0, P1, P2, etc.), that describes the curves. For example:
My problem is that I don't know how to do it. Usually I don't need low-level drawing in a Codename One app like in this case. Could you please show me a correct and complete code to do this drawing (assuming to know the coordinates of Start, End, P0, P1, etc.)? Thank you.
This is a bit hard to do by hand. I would suggest using SVG to draw an arrow like this by using a tool such as Sketch or a similar vector graphics tool. Then using flamingo to convert it to an image: https://www.codenameone.com/blog/flamingo-svg-transcoder.html
Alternatively you can handcode it with a GeneralPath e.g.:
GeneralPath gp = new GeneralPath();
// move to start of path
gp.move(x, y);
// draw the curve of the arrow, we use a control point around which
// the curve is drawn and curve to the destination of the line
gp.curveTo(contolX, controlY, destX, destY);
// Stroke defines how the shape is drawn it accepts the line width
// cap style, join style and miter limit
Stroke st = new Stroke(2, Stroke.CAP_SQUARE, Stroke.JOIN_MITER, 1);
// red
graphics.setColor(0xff00000);
// now we can draw the shape
graphics.drawShape(gp, st);

How to replace DrawClosedCurve / FillClosedCurve when moving from WinForms (GDI+) to WPF?

I've got an array of points (X,Y) which constitute a convex hull (a simple, irregularly shaped contour). Rather than rendering a polygon with straight edges, I want to render them with an approximate "smoothly curved" contour that passes through all of these points.
In WinForms/GDI+, this could be accomplished with the Graphics.DrawClosedCurve or Graphics.FillClosedCurve methods. There does not appear to be an equivalent in WPF.
I've looked into drawing using things like Path and BezierSegment, but I'm not sure if (and how) these can be used to generate a continuous closed curve, given a set of points. It appears that to do this, I'd perhaps have to generate a set of control points based on my contour as an intermediate step?
I have tried using the GDI+ methods to render onto a System.Drawing.Bitmap and then displaying that in the WPF application. This works, but the performance (particularly the conversion from System.Drawing.Bitmap to BitmapSource) is poor and not sufficient for the application. This is why I'm looking for a pure WPF solution.
Has anyone been able to draw a closed curve based off a set of points in WPF?
Unfortunately, there is no single-method equivalent to DrawClosedCurve in WPF, even though it's been requested. So you are left with at least two options:
Host a native window within your WPF window and perform all your drawing on it.
Implement your own cardinal spline drawing. You are on the right track with Bezier segments. However, there are existing implementations of it you can look at out there.

Blob detection in C (not with OPENCV)

I am trying to do my own blob detection who will receive a real time video, and try to detect a white paper sheet.
Even if is something written inside the paper. I need to detect the paper and is corner, because what i really want is to draw a opengl polygon over the paper in each corner of the paper will be a corner of the polygon. Then i need the coordinates of the paper to do other stuffs.
So i need to:
- detect a square white blob.
- get the coordinates of the cornes
- draw a polygon over the white sheet.
Any ideias how can i do that?
Much depends on context. For example, suppose that you:
know that the paper is always roughly centered (i.e. W/2, Y/2 is always inside the blob), and no more rotated than 45 degrees (30 would be better)
have a suitable border around the sheet so that the corners never touch the edges of the FOV
are able (through analysis of local variance, or if you're lucky, check of background color or luminance) to say whether a point is inside or outside the blob
the inside/outside function never fails (except possibly in the close vicinity of a border)
then you could walk a line from a point on the border (surely outside) and the center (surely inside), even through bisection, and find a point - an areal - on the edge.
Two edge points give a rect (two areals give a beam), two rects give an intersection (two beams give a larger areal) - and there's your corner. You should carry along the detection uncertainty (areal radius) in order to validate corners (another less elegant approach is to roughly calculate where the corner is, and pinpoint it with a spiral search or drunkard's walk).
This algorithm is amenable to parallelization and, as long as the hypotheses hold, should be really fast.
All that said, it remains a hack -- I agree with unwind, why reinvent the wheel? If you have memory or CPU constraints (embedded systems, etc.), I believe there ought to be OpenCV and e-Vision "lite" ports also for ARM and embedded platforms.
(Sorry for my terminology - I'm monkey-translating from Italian. "Areal" is likely to correspond to your "blob", a beam is the family of lines joining all couples of points in two different blobs, line intensity being the product of distance from a point from its areal's center)
I am trying to do my own blob detection who will receive a real time video, and try to detect a white paper sheet.
Your first shot could be a simple flood-fill. That is, select a good threshold to binarize the image and apply the algorithm. The threshold can be fixed if you know the paper is always brighter than X and the background is always darker than this. Or this can be an adaptive threshold, for example Otsu's method. OpenCV offers this for free.
If you'd need to speed it up you could use a union-find data structure.
Finally you'd need to come up with some heuristic how to identify the corners (e.g. the four extreme values in x/y direction).
Then i need [...] the coordinates of the cornes [...]
Then you don't need blob detection, but corner detection or contour detection in the first place. OpenCV has some nice functionality for exactly this.
If you can't use it, I would suggest to binarize the image as above and use a harris-detector to find the corners of the object.
OpenCV's TBB support could also come quite handy if you'd use it and you have problems to meet your real-time requirements.

Silverlight Image Positioning/Transformation

What I would like to do is the following:
Change the points of the four corners of an image.
What is possible now, is to change the top left corner. But that will only move the image.
I want to transform the image by changing the corner coordinates.
The effect will be a 3d-kind transformation.
A skew transformation will not do, I want to be able to position the corners freely.
Is this possible?
I don't think you can just place corners of an image arbitarily and have it distort accordingly. It might be better if you specified the effect you are trying to acheive.
There are couple of options which may or may not suit.
Would a Matrix3DProjection serve your purpose (as well as do a lot a math for you)?
Would using the image to Fill a path or using a path to clip the image get the effect you want.

Resources