- ago
I have been struggling with using images/icons with DrawImage. I downloaded bunch of them from Internet and also tried to crop/resize them - but either they are too big or too hazy or just look ugly - not able to get good results. Do you have any image/icon set which we can use with DrawImage() ?

Specifically looking for:
1. Arrows - up, down, left, right - in different colors
2. Shapes(star, triangle) in different colors
3. Alphabets in different colors (transparent background, circle background, square background).
Don't need all of them, but few of them in the above categories should get going.

New APIs like these will be even better:
https://www.tradingview.com/pine-script-docs/en/v4/annotations/Plotting_shapes_chars_and_arrows.html
1
1,798
Solved
14 Replies

Reply

Bookmark

Sort
- ago
#1
You could plot arrows and shapes without DrawImage (or having to embed images) simply as text using extended Unicode character set. They're vector so no hazy look. Let me whip up a quick example using Wingdings font. Alas, custom font face like in WL6 is not supported.
0
- ago
#2
Here you go:
CODE:
string upArrow = "\u25b2", dnArrow = "\u25bc"; var up = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(upArrow))); var dn = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(dnArrow)));           DrawBarAnnotation(up, bars.Count - 10, false, Color.Blue, 36); DrawBarAnnotation(dn, bars.Count - 20, false, Color.Red, 36);


A list of geometric shapes with Unicode numbers built in the font you're using:

https://en.wikipedia.org/wiki/Geometric_Shapes
0
- ago
#3
And now a star:

CODE:
string star = "\u2605"; var s = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(star))); DrawBarAnnotation(s, bars.Count - 15, false, Color.Green, 36);




For your reference:

1. Unicode star symbols
https://unicode-table.com/en/sets/star-symbols/

2. You can find more symbols in the Windows built-in Character Map utility.
0
Best Answer
Cone8
 ( 6.32% )
- ago
#4
Nice, but don't forget to add using System.Text;

We can probably make this is easier by creating some Enums to pass to methods like DrawBarAnnotation. I'll add it to the wish list.
1
Glitch8
 ( 12.10% )
- ago
#5
A couple of points. When using DrawImage, it's up to you to make sure the image you're using appears how you desire. One thing that can help is to use transparent PNGs, or use a tool like this to make an existing PNG image transparent:

https://onlinepngtools.com/create-transparent-png

The big arrow in the example picture below was plotted using DrawImage.

Second, you can use symbolic ASCII characters, right as text, in DrawBarAnnotation. I went to this page and copied an arrow symbol:

https://unicode-table.com/en/sets/arrow-symbols/

Then used DrawBarAnnotation to produce the red arrow in the chart below. Here's the code:

CODE:
//Initialize public override void Initialize(BarHistory bars) {          Image img = Image.FromFile(@"C:\Scratch\Arrow.png");          DrawImage(img, bars.Count - 58, bars.Low[bars.Count - 58] - 32);          DrawBarAnnotation("▲", bars.Count - 10, false, Color.Red, 20, true); }


0
- ago
#6
Thank you Eugene, Cone and Glitch!
Very nice tips! And these one does make it easier to draw different kind of symbol annotations on the chart.

One thing which was there in WL6 and is still not there in WL7 Build 5 is that DrawBarAnnotation is still overwriting previous annotations on the same bar. Following code shows this behavior:
CODE:
using System; using System.Drawing; using System.Text; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; public class MyStrategy : UserStrategyBase {    public override void Initialize(BarHistory bars)    {       DrawBarAnnotation("▲", bars.Count - 9, false, Color.Red, 20, true);       DrawBarAnnotation("▲", bars.Count - 10, false, Color.Red, 20, true);       DrawBarAnnotation("▲", bars.Count - 11, false, Color.Red, 20, true);       string star = "\u2605";       var s = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(star)));       DrawBarAnnotation(s, bars.Count - 10, false, Color.Green, 20);    }    public override void Execute(BarHistory bars, int idx) { } }

If you can prioritize this for the next build, then that will be great!

The annotations are done from different sections of the program and they are independent and are of different colors. I have tried to accumulate all the annotations for each bar in a Dictionary/Map and then draw them with "\n" separator at the end. That works, but then all the annotations need to be of the same color which limits what you can do with the annotations.
0
Glitch8
 ( 12.10% )
- ago
#7
We should be able to get that taken care of for the next build.

Oh and if you want to simplify annotating with the star, just copy this character:

0
- ago
#8
Awesome!
thx!
0
Cone8
 ( 6.32% )
- ago
#9
Let's talk about it (and the issue I created) in the next team meeting. Finding an image and putting it in quotes is probably the most non-intuitive thing I've imagined doing all year. Never even seen it done before.

Let's record the next meeting - maybe it will go viral★⭲ :)
0
Glitch8
 ( 12.10% )
- ago
#10
Ok, if Eugene’s solution is elegant and mine is non intuitive I think someone needs to look up the definition of elegant! 😂

And, It’s not an image. It’s an ascii character. There are many web sites that list all of the ascii characters that can be easily and intuitively accessed and the characters copied.
0
- ago
#11
In a perfect world, what would be nice is if DrawBarAnnotation() accepted a UTF slash encoding like "\u25b2" directly.
CODE:
DrawBarAnnotation("\u25b2",...);
I kind of thought .NET string functions already did that (but I guess I may be wrong). However, you could build the ASCII-to-UTF8 conversion into the DrawBarAnnotation() call. Whatever you do, make it intuitive such that it doesn't raise questions.
0
- ago
#12
This is not an image, it is a character.

Finding a character and putting it in double quotes - that's pretty intuitive to me.

I have been doing this for ASCII characters like '^', '|' '<', etc. all along. Didn't know WL supported Unicode characters as well.

It is good to know that now almost all editors support unicode characters out of the box and .NET graphics libraries are able to handle unicode characters. That opens up lot of possibilities.
0
mjj38
- ago
#13
Do we have a community library yet? I like the flexibility of this but it might be nice to create a generic helper class built in that does the more common images.
0
- ago
#14
We have a community library, it's built in. Once you have that generic helper class it could be reviewed and added.
0

Reply

Bookmark

Sort