TradingView
capissimo
2020년 12월 30일 오전 8시 35분

Machine Learning: kNN-based Strategy 

Euro Fx/U.S. DollarFXCM

설명

kNN-based Strategy (FX and Crypto)

Description:
This strategy uses a classic machine learning algorithm - k Nearest Neighbours (kNN) - to let you find a prediction for the next (tomorrow's, next month's, etc.) market move. Being an unsupervised machine learning algorithm, kNN is one of the most simple learning algorithms.

To do a prediction of the next market move, the kNN algorithm uses the historic data, collected in 3 arrays - feature1, feature2 and directions, - and finds the k-nearest
neighbours of the current indicator(s) values.

The two dimensional kNN algorithm just has a look on what has happened in the past when the two indicators had a similar level. It then looks at the k nearest neighbours,
sees their state and thus classifies the current point.

The kNN algorithm offers a framework to test all kinds of indicators easily to see if they have got any *predictive value*. One can easily add cog, wpr and others.
Note: TradingViews's playback feature helps to see this strategy in action.
Warning: Signals ARE repainting.

Style tags: Trend Following, Trend Analysis
Asset class: Equities, Futures, ETFs, Currencies and Commodities
Dataset: FX Minutes/Hours+++/Days

릴리즈 노트

Added alerts.

릴리즈 노트

An upgrade to Pinescript v.5.

릴리즈 노트

Major Fix. Changedthe signal filter application point and corrected the class label calculation.

릴리즈 노트

Major fix. Added bars count for clear condition variable. Replaced endLongTrade and endShortTrade variables with clear_condition

릴리즈 노트

Minor fix.
코멘트
PineCoders
cabierman
Well done.. I love it, thank you!
mthtsenol
How will i read this?
What is the meaning of symbols? blue, red arrow, plus
dakvin
jekojordi88
Nice work!! just a quick question, is there any reason why you used as a k floor(sqrt(252))? wouldn't be better using a high number?
capissimo
@jekojordi88, the k value was chosen arbitrarily. On the one hand, small k leads to unstable results. On the other, I wanted to minimize computing cost and tie it up to trading (ex. 252 trading days; might as well use fibo numbers.). Generally, k value is based on the training accuracy.
jekojordi88
@capissimo, Thanks for the reply. I tried to implement your code in a basic strategy but the outcome is negative. Have you tried as well?
capissimo
@jekojordi88, yes I have. My results were relatively better in higher TFs. It looks this indicator should be used together with other indicators. Besides, I did not explore the fast/slow parameter values. Ple regard it as a proof of concept.)
Four17
How should the yellow cross be interpreted? Is there a video explanation on the indicator?
SwellFella
@Four17, looking for the same info
더보기