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!
Experimental
Candle-Box RatioVolatility compression/expansion indicator calculated from the ratio of the area of the candles to the area of a rectangle encompassing the candles over n bars.
Generally during a squeeze or compression the ratio between the candles and the rectangular area increases, ie the candles occupy a larger portion of the rectangle, and vice versa during a release/expansion. It is inherently low lag due to the lack of any averaging in the calculation since the start of an expansion/breakout will instantly change the dimensions of the encompassing rectangle and the corresponding ratio. A potential downside is that different lengths will produce significantly different results which will require tuning to optimize for specific instruments and timeframes.
Additional standard deviation bands to identify potential points of volatility change and the option to normalize the output using the stdev bands.
SAK-MPI: Stochastic & RSIDescription : This SwissArmyKnife - MultiPurposeIndicator allows user to modify the conventional indicator smoothing method Stochastic(SMA)/RSI(RMA) to one of filtering tools proposed by John F. Ehlers .
Details of each filtering type can be read in Ehlers Technical Papers: Swiss Army Knife Indicator,
I'm still very new with Digital Signal Processing (DSP) concept and this is my first attempt to help visualize one of Ehlers tools and its practicality (Read: Its experimental).
Any ideas to further improve this indicator are welcome :)
Disclaimer:
I always felt Pinescript is a very fast to type language with excellent visualization capabilities, so I've been using it as code-testing platform prior to actual coding in other platform.
Having said that, these study scripts was built only to test/visualize an idea to see its viability and if it can be used to optimize existing strategy.
While some of it are useful and most are useless, none of it should be use as main decision maker.
Sigma Spike Filtered Binned OPR ( Adam H. Grimes )As originally described by Adam H. Grimes.
For analyzing the location of Open within the day's range (OPR). The OPR histogram displays the binned distribution of OPR values for the chart history. Fat tails at the extremes indicates that Open occurred more often close to the day's high or low.
The OPR results are filtered according to volatility using Grime's Sigma Spike. So that OPR values are only recorded when volatility exceeds a threshold (relative high range days).
This may (strong emphasis on may) indicate the opportunity for trades early in the day on days that begin with a high amount of relative volatility and trading with the direction that price is moving away from the open.
Test: range mappingEXPERIMENTAL:
just a wild experiment..
mapping the average range break points to find natural hubs of support and resistance?!
Test: Pattern RecognitionEXPERIMENTAL:
a test on how to compare price at different frequency's with static patterns.
function: Array DownsamplingA low cost function to down sample a array.
specially useful for pattern recognition algorithms.
Equivolume Overlay - Moving AveragesMoving average overlay for Equivolume Bars
To use it you must move it to the same existing pane as the Equivolume Bars pane and set it to the same scale (usually A).
Please ensure if you have modified the equivolume bars script's settings that you modify them in this script accordingly or they will not line up correctly.
Equivolume Overlay - Bollinger BandsA bollinger band overlay for Equivolume Bars .
To use it you must move it to the same existing pane as the Equivolume Bars pane and set it to the same scale (usually A).
Please ensure if you have modified the equivolume bars script's settings that you modify them in this script accordingly or they will not line up correctly.
Test: Chain casting multiple functions performanceExperimental:
A simple test to check performance impact of chaining functions in pinescript.
Test calling frequency impact.
Test: Chain casting functions performanceExperimental:
A simple test to check performance impact of chaining functions in pinescript.
RSI PieMore a novelty than anything useful. Measures the % of overbought/sold RSI and renders as a pie chart. RSI % -> Radians -> (x,y) -> bar_time. 24hr market charts only.
Logistic RSI, STOCH, ROC, AO, ... by DGTExperimental attemt of applying Logistic Map Equation for some of widly used indicators.
With this study "Awesome Oscillator (AO)", "Rate of Change (ROC)", "Relative Strength Index (RSI)", "Stochastic (STOCH)" and a custom interpretation of Logistic Map Equation is presented
Calculations with Logistic Map Equation makes sense when the calculated results are iterated many times within the same equation.
Here is the Logistic Map Equation : Xn+1 = r * Xn * (1 - Xn)
Where, the value of r is the key for this equation which changes amazingly the behaviour of the Logistic Map.
The value we have asigned for r is less then 1 and greater than 0 ( 0 < r < 1) and in this case the iterations performed with the maximum number of output series allowed by Pine is quite enough for our purpose and thanks to arrays we can easiliy store them for further processing
What we have as output:
Each iteration result is then plotted (excluding plotting the first iteration), as circles or line based on user preference
Values above and below zero level (0) are coloured differently to emphasis bull and bear power
Finally Standard Deviation of Array's Elements is ploted as line. Users may choose to display this line only
So where it comes the indicators "Awesome Oscillator (AO)", "Rate of Change (ROC)", "Relative Strength Index (RSI)", "Stochastic (STOCH)".
Those are the indicators whose values are assigned to our key varaiable in the Logistic Map equation forulma which is r
Further details regarding Logistic Map can found under the description of “Logistic EMA w/ Signals by DGT” study
Disclaimer:
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script
[RS]Support Resistance and FractureEXPERIMENTAL:
Inverted slope of SR pivots to mark the fracture point of slope.
example: Event StatisticsEXPERIMENTAL:
A example on how to retrieve statistics from a recurring event.
Can be used to optimized strategy's, trade parameters, etc..
Ehler's Autocorrelation Periodogram - RSI/MFIWarning! Frequently hits the execution time limit for scripts.
Especially on initially adding to your chart. Often requires toggling show/hide indicator to get it to complete script execution within the time limit. YMMV!
From TASC Sept 2016 this is Ehler's Autocorrelation periodogram. A means of determining the dominant cycle ("ideal" indicator length / dynamic length).
As an example it's applied here to RSI or MFI. Lower indicator segment displays the autocorrelation spectrum and the computed dominant cycle. Upper segment is RSI/MFI.
Example: Monte Carlo SimulationExperimental:
Example execution of Monte Carlo Simulation applied to the markets(this is my interpretation of the algo so inconsistencys may appear).
note:
the algorithm is very demanding so performance is limited.
Function Polynomial RegressionDescription:
A function that returns a polynomial regression and deviation information for a data set.
Inputs:
_X: Array containing x data points.
_Y: Array containing y data points.
Outputs:
_predictions: Array with adjusted _Y values.
_max_dev: Max deviation from the mean.
_min_dev: Min deviation from the mean.
_stdev/_sizeX: Average deviation from the mean.
Resources:
en.wikipedia.org
rosettacode.org
Function - Linear RegressionDescription:
A Function that returns a linear regression channel using (X,Y) vector points.
Inputs:
_X: Array containing x data points.¹
_Y: Array containing y data points.¹
Note:
¹: _X and _Y size must match.
Outputs:
_predictions: Array with adjusted _Y values at _X.
_max_dev: Max deviation from the mean.
_min_dev: Min deviation from the mean.
_stdev/_sizeX: Average deviation from the mean.
Resources:
www.statisticshowto.com
en.wikipedia.org