LonesomeTheBlue

Machine Learning / Longs [Experimental]

Hello Traders/Programmers,

For long time I thought that if it's possible to make a script that has own memory and criterias in Pine. it would learn and find patterns as images according to given criterias. after we have arrays of strings, lines, labels I tried and made this experimental script. The script works only for Long positions.

Now lets look at how it works:

On each candle it creates an image of last 8 candles. before the image is created it finds highest/lowest levels of 8 candles, and creates a string with the lengths 64 (8 * 8). and for each square, it checks if it contains wick, green or red body, green or red body with wicks. see the following picture:

Each square gets the value:
0: nothing in it
1: only wick in it
2: only red body in it
3. only green body in it
4: red body and wick in it
5: green body and wick in it



And then it checks if price went up equal or higher than user-defined profit. if yes then it adds the image to the memory/array. and I call this part as Learning Part.

what I mean by image is:


if there is 1 or more element in the memory, it creates image for current 8 candles and checks the memory if there is a similar images. If the image has similarity higher than user-defined similarty level then if show the label "Matched" and similarity rate and the image in the memory. if it find any with the similarity rate is equal/greater than user-defined level then it stop searching more.

As an example matched image:

and then price increased and you got the profit :)

Options:
Period: if there is possible profit higher than user-defined minimum profit in that period, it checks the images from 2. to X. bars.
Min Profit: you need to set the minimum expected profit accordingly. for example in 1m chart don't enter %10 as min profit :)
Similarity Rate: as told above, you can set minimum similarity rate, higher similarity rate means better results but if you set higher rates, number of images will decrease. set it wisely :)
Max Memory Size: you can set number of images (that gives the profit equal/higher than you set) to be saved that in memory
Change Bar Color: optionally it can change bar colors if current image is found in the memory

Current version of the script doesn't check if the price reach the minimum profit target, so no statistics.

This is completely experimental work and I made it for fun. No one or no script can predict the future. and you should not try to predict the future.

P.S. it starts searching on last bar, it doesn't check historical bars. if you want you should check it in replay mode :)

if you get calculation time out error then hide/unhide the script. ;)


Enjoy!


เอกสารเผยแพร่: Changed some parts for readability
เอกสารเผยแพร่: Put some more explanation into the script. and a filter to choose better images.

this is the filters (explained in following screenshot) that is used in the script:

As this is an experimental/Example work and of course it's not possible fully completed, because it may not ne possible to run ML in Pine, I do NOT recommend you to use it in your trades!.
เอกสารเผยแพร่: Because of last changes in "str.split" command it wasn't working as expected, I added a new function to solve it.
เอกสารเผยแพร่: "str.split" command fixed, so now using it in the script again.
สคริปต์โอเพนซอร์ซ

จากใจ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ยินดีด้วย! คุณสามารถใช้มันได้ฟรี แต่การใช้โค๊ดนี้ซ้ำเพื่อการเผยเเพร่ อยู่ภายใต้ กฎของเรา คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้กับชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?

ความคิดเห็น

wow
100 เหรียญ
+8 ตอบกลับ
@admin, Thank you!
ตอบกลับ
Great work
100 เหรียญ
+1 ตอบกลับ
To be honest, I did not fully understand it yet - but a very interesting thing to explore further. Thanks a lot!
+12 ตอบกลับ
First Comment!
Amazing work as always!
+9 ตอบกลับ
Really amazing stuff!!!!!

and all of this in only about 100 lines of code! WOW!

Gr, JD.
+7 ตอบกลับ
@Duyck, thanks a lot mate :)
ตอบกลับ
Duyck LonesomeTheBlue
@LonesomeTheBlue, PS. you can add the original string split again! ;-)
+1 ตอบกลับ
@Duyck, yes good idea, will implement it soon. thank you mate :)
ตอบกลับ
It doesn´t work forme it ´s having some errors on line 50
+4 ตอบกลับ