cinar / indicator Goto Github PK
View Code? Open in Web Editor NEWIndicator is a Golang module providing various stock technical analysis indicators for trading.
License: GNU Affero General Public License v3.0
Indicator is a Golang module providing various stock technical analysis indicators for trading.
License: GNU Affero General Public License v3.0
The Ulcer Index (UI) is a technical indicator that measures downside risk in terms of both the depth and duration of price declines. The index increases in value as the price moves farther away from a recent high and falls as the price rises to new highs. The indicator is usually calculated over a 14-day period, with the Ulcer Index showing the percentage drawdown a trader can expect from the high over that period.
https://www.investopedia.com/terms/u/ulcerindex.asp
Already implemented in Indicator TS, can be ported from code change.
Check if codecov is better.
Hi,
I develop a trading bot and I really appreciate your indicators library. I have found one thing missing for my strategy - the possibility of setting the period for RSI. It is fixed to 14 days like in the standard RSI strategy. Larry Connor developed the 2-period RSI strategy which I use in my trading strategy as well.
The solution requires a change to allow passing the period which is then used in RMA (Rolling Moving Average).
warning: "substract" is a misspelling of "subtract" (misspell)
https://goreportcard.com/report/github.com/cinar/indicator#misspell
Is your feature request related to a problem? Please describe.
Currently the Min and Max functions are not optimal.
Describe the solution you'd like
Binary search tree is more efficient for this work.
Describe alternatives you've considered
Existing implementation.
Additional context
No
The Commodity Channel Indexβ (CCI) is a momentum-based oscillator used to help determine when an investment vehicle is reaching a condition of being overbought or oversold.
https://www.investopedia.com/terms/c/commoditychannelindex.asp
Already implemented in Indicator TS can be ported from code change.
Keltner Channels are volatility-based bands that are placed on either side of an asset's price and can aid in determining the direction of a trend.
https://www.investopedia.com/terms/k/keltnerchannel.asp
Already implemented in Indicator TS, can be ported from code change.
The Price Rate of Change (ROC) is a momentum-based technical indicator that measures the percentage change in price between the current price and the price a certain number of periods ago. The ROC indicator is plotted against zero, with the indicator moving upwards into positive territory if price changes are to the upside, and moving into negative territory if price changes are to the downside.
Replace Travis CI with GitHub Actions.
Maths for acceleration lower band appears to be incorrect
Expected behavior
Formula to calculate the lower band would correlate with the following pinescript:
Additional context
Just wanted to say I'm loving using the package, thanks for your great work Cinar! I would be absolutely willing to contribute but maths really isn't my strong suit π
Mass index is a form of technical analysis that examines the range between high and low stock prices over a period of time. Mass index, developed by Donald Dorsey in the early 1990s, suggests that a reversal of the current trend will likely take place when the range widens beyond a certain point and then contracts.
The Chaikin oscillator is named for its creator Marc Chaikin.1 The oscillator measures the accumulation-distribution line of moving average convergence-divergence (MACD). To calculate the Chaikin oscillator, subtract a 10-day exponential moving average (EMA) of the accumulation-distribution line from a 3-day EMA of the accumulation-distribution line. This measures momentum predicted by oscillations around the accumulation-distribution line.
A detrended price oscillator, used in technical analysis, strips out price trends in an effort to estimate the length of price cycles from peak to peak or trough to trough.
https://www.investopedia.com/terms/d/detrended-price-oscillator-dpo.asp
The Schaff Trend Cycle (STC) is a charting indicator that is commonly used to identify market trends and provide buy and sell signals to traders.
https://www.investopedia.com/articles/forex/10/schaff-trend-cycle-indicator.asp
Kaufman's Adaptive Moving Average (KAMA). Developed by Perry Kaufman, Kaufman's Adaptive Moving Average (KAMA) is a moving average designed to account for market noise or volatility. KAMA will closely follow prices when the price swings are relatively small and the noise is low.
https://school.stockcharts.com/doku.php?id=technical_indicators:kaufman_s_adaptive_moving_average
The triple exponential average (TRIX) indicator is an oscillator used to identify oversold and overbought markets, and it can also be used as a momentum indicator. Like many oscillators, TRIX oscillates around a zero line.
https://www.investopedia.com/articles/technical/02/092402.asp
Already implemented in Indicator TS, can be ported from code change.
Double Exponential Moving Average (DEMA).
The double exponential moving average (DEMA) is a technical indicator introduced by Patrick Mulloy. The purpose is to reduce the amount of noise present in price charts used by technical traders. The DEMA uses two exponential moving averages (EMAs) to eliminate lag. It helps confirm uptrends when the price is above the average, and helps confirm downtrends when the price is below the average. When the price crosses the average that may signal a trend change.
https://www.investopedia.com/terms/d/double-exponential-moving-average.asp
The Know Sure Thing (KST) is a momentum oscillator developed by Martin Pring to make rate-of-change readings easier for traders to interpret.
https://www.investopedia.com/terms/k/know-sure-thing-kst.asp
In a constant declaration such as the following:
There are 2 occurrences of this issue in the repository.
See all occurrences on DeepSource β deepsource.io/gh/cinar/indicator/issue/SCC-SA9004/occurrences/
Hi! First of all, I would like to thank you for this great package.
Recently I tested the RSI indicator, and I found some divergence in the RSI values produced by this package and values calculated by myself and other tools. Just wanted to find out why is it so.
Here's an example of closing values:
closing := []float64{
0.003544, 0.003498, 0.003548, 0.003565, 0.003827, 0.003934, 0.003904, 0.003835, 0.004432, 0.004366, 0.004281, 0.00434, 0.004538, 0.004611, 0.004383, 0.004389, 0.004182, 0.004259, 0.004291, 0.004403, 0.004257, 0.004203, 0.004067, 0.004084, 0.004299, 0.00467, 0.004506, 0.004519, 0.005683, 0.005335, 0.005534, 0.005251, 0.004963, 0.005871, 0.005063, 0.004922, 0.005215, 0.00513, 0.005625, 0.00564, 0.005338, 0.005369, 0.005433, 0.005303, 0.005185, 0.005165, 0.005105, 0.005152, 0.005187, 0.005135, 0.00516, 0.00518, 0.005296, 0.005156, 0.005131, 0.005102, 0.004958, 0.004969, 0.004987, 0.00498, 0.004966, 0.0051, 0.005107, 0.004948, 0.00479, 0.004798, 0.004792, 0.004587, 0.004442, 0.004388, 0.004272, 0.004326, 0.004479, 0.004509, 0.004427, 0.004453, 0.004476, 0.004542, 0.004526, 0.00448, 0.0045, 0.004374, 0.00433, 0.004297, 0.00437, 0.004355, 0.004301, 0.004282, 0.004349, 0.004417, 0.004317, 0.004325, 0.004315, 0.004538, 0.00477, 0.004659, 0.00468, 0.004105, 0.003875, 0.003882,
}
_, rsi := indicator.Rsi(closing)
// Printing out the last ten values
for i := len(rsi) - 10; i < len(rsi); i++ {
println(fmt.Sprintf("%f", rsi[i]))
}
The code below prints these values:
// last ten RSI values from this package
39.357430
34.252540
34.553441
53.372093
62.593284
63.481552
66.924565
43.908629
35.718407
36.289855
I've calculated the RSI values manually (using google sheets) and got these values:
// last ten RSI values from manual calculations
40.00359988
40.55514538
40.05940381
53.66234853
63.05581295
57.09246379
57.90359501
37.1789257
32.21242822
32.50793062
The document with my calculations is available here.
My calculations match the values from the Binance exchange.
Looking into the implementation of the package, I've found that the moving average values and the RSI values are available starting from the 3rd closing value, which is strange because the average value of the 14 closing values should be available starting from the 15th closing value. These MA issues are the point where my calculations start to diverge with the work of this package.
So I wanted to ask and ensure whether there are no mistakes in the RSI implementation. If not, could you please elaborate on what I've done wrong in my calculations and why they match the Binance exchange values? Thank you in advance.
The Triangular Moving Average is similar to the Simple Moving Average but instead places more weight on middle portion of the smoothing period and less weight on the newest and oldest bars in the period.
Implement Parabolic SAR from.
https://school.stockcharts.com/doku.php?id=technical_indicators:parabolic_sar
Check the workflows/codeql-analysis.yml.
Describe the bug
Using the Money Flow Index and I am consistently seeing values well in excess of 100.
To Reproduce
With these assets I get a MFI of around 283.
High | Low | Close | Vol |
---|---|---|---|
2390.9 | 2373.15 | 2373.39 | 1621 |
2386.3 | 2370 | 2382.47 | 1387 |
2395.33 | 2380.77 | 2394.4 | 1444 |
2399 | 2384.28 | 2387.51 | 1298 |
2402.46 | 2387.46 | 2395.64 | 1629 |
2401.15 | 2385.02 | 2389.47 | 1598 |
2421.98 | 2383.18 | 2410.24 | 2311 |
2430.31 | 2408.39 | 2425.37 | 2934 |
2426.33 | 2410.59 | 2422.33 | 2128 |
2434.93 | 2420.89 | 2430.29 | 1823 |
2470.83 | 2428.92 | 2465.76 | 5078 |
2483.36 | 2456.77 | 2466.27 | 6693 |
2467.19 | 2437.65 | 2440.07 | 3960 |
2450.72 | 2440.87 | 2445.85 | 1927 |
In looking through through the code it appears when you keep the negative values, you are keeping them as negatives thus their sum is negative when entering the formula for Money Ratio. It's my understanding Money Ratio takes a positive for both Positive Money Flow and for Negative Money Flow thus never yielding a negative ratio. I calculate the MFI should be around 58 for those assets. I'm new to these strategies so apologies if I've got something wrong here.
Thank you for the great project, it is super insightful for my project.
The average directional index (ADX) is a technical analysis indicator used by some traders to determine the strength of a trend.
Donchian Channels are three lines generated by moving average calculations that comprise an indicator formed by upper and lower bands around a midrange or median band. The upper band marks the highest price of a security over N periods while the lower band marks the lowest price of a security over N periods. The area between the upper and lower bands represents the Donchian Channel.
https://www.investopedia.com/terms/d/donchianchannels.asp
Already implemented in Indicator TS, can be ported from code change.
The triple exponential moving average (TEMA) was designed to smooth price fluctuations, thereby making it easier to identify trends without the lag associated with traditional moving averages (MA). It does this by taking multiple exponential moving averages (EMA) of the original EMA and subtracting out some of the lag.
Based on https://www.investopedia.com/terms/t/triple-exponential-moving-average.asp
Describe the solution you'd like
FOSC (aka CFO) indicator in the package, like this or the following pinescript:
//@version=2
////////////////////////////////////////////////////////////
// The Chande Forecast Oscillator developed by Tushar Chande The Forecast
// Oscillator plots the percentage difference between the closing price and
// the n-period linear regression forecasted price. The oscillator is above
// zero when the forecast price is greater than the closing price and less
// than zero if it is below.
////////////////////////////////////////////////////////////
strategy(title="Chande Forecast Oscillator", shorttitle="CFO")
Length = input(14, minval=1)
Offset = input(0)
hline(0, color=black, linestyle=line)
xLG = linreg(close, Length, Offset)
xCFO = ((close -xLG) * 100) / close
plot(xCFO, color=red, title="CFO")
Formula also here:
https://www.stockmaniacs.net/chande-forecast-oscillator/
And here:
https://www.fmlabs.com/reference/default.htm?url=ForecastOscillator.htm
The Stochastic RSI (StochRSI) is an indicator used in technical analysis that ranges between zero and one (or zero and 100 on some charting platforms) and is created by applying the Stochastic oscillator formula to a set of relative strength index (RSI) values rather than to standard price data. Using RSI values within the Stochastic formula gives traders an idea of whether the current RSI value is overbought or oversold.
Developed by Larry Connors, the 2-period RSI strategy is a fairly simple mean-reversion trading strategy designed to buy or sell securities after a corrective period. Traders should look for buying opportunities when 2-period RSI moves below 10, which is considered deeply oversold. Conversely, traders can look for short-selling opportunities when 2-period RSI moves above 90.
https://school.stockcharts.com/doku.php?id=trading_strategies:rsi2
The Ultimate Oscillator is a technical indicator that was developed by Larry Williams in 1976 to measure the price momentum of an asset across multiple timeframes. By using the weighted average of three different timeframes the indicator has less volatility and fewer trade signals compared to other oscillators that rely on a single timeframe. Buy and sell signals are generated following divergences. The Ultimately Oscillator generates fewer divergence signals than other oscillators due to its multi-timeframe construction.
Enable the Go Report Card Badge.
Warn: dependabot config file not detected in source location. We recommend setting this configuration in code so it can be easily verified by others.
The percentage price oscillator (PPO) is a technical momentum indicator that shows the relationship between two moving averages in percentage terms. The moving averages are a 26-period and 12-period exponential moving average (EMA).
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
It is not recommended to overshadow builtins.
There are 17 occurrences of this issue in the repository.
See all occurrences on DeepSource β deepsource.io/gh/cinar/indicator/issue/CRT-A0001/occurrences/
Enable Coveralls Test Coverage Badge.
Remove the Coveralls from the travis configuration. Reference #87.
The Bollinger Bands upper band and lower band seem to be too wide.
Below is a screenshot of the visualisation tool I'm working on:
In white are the bands computed by your BollingerBands sma(20) and standard deviation functions.
Your sma(20) seems to match up on top of my sma(20) calculation correctly.
In red and green are the upper and lower bands calculated by me based on code I derived from go-talib.
The standard deviation (2.0) output does not match go-talib and therefore also not my implementation.
A quick inspection seems to suggest it also does not match Trading View's Bollinger Bands implementation.
Below is the code I use, feel free to use if you're so inclined. It's MIT licensed.
// BBands - Bollinger Bands
// BBands(upperband, middleband, lowerband, close, periods=20, nbdevup=2, nbdevdn=2, ma=Sma)
func BBands(upperband, middleband, lowerband, closing []float64, periods int, nbdevup, nbdevdn float64, ma MA) {
ma(middleband, closing, periods)
StdDev(upperband, closing, periods, 1.0)
for i, mb := range middleband {
sd := upperband[i]
upperband[i] = mb + nbdevup*sd
lowerband[i] = mb - nbdevdn*sd
}
}
// StdDev - Standard Deviation
func StdDev(dst, src []float64, periods int, nbdev float64) {
Var(dst, src, periods)
for i, v := range dst {
if v < 0.00000000000001 {
dst[i] = 0.0
} else {
dst[i] = nbdev * math.Sqrt(v)
}
}
}
// Var - Variance
func Var(dst, src []float64, periods int) int {
if periods > 0 {
sum, sum2 := 0.0, 0.0
for i, v := range src {
sum, sum2 = sum+v, sum2+v*v
if i < (periods - 1) {
dst[i] = 0.0
} else {
dst[i] = sum2/float64(periods) - (sum/float64(periods))*(sum/float64(periods))
w := src[i-(periods-1)]
sum, sum2 = sum-w, sum2-w*w
}
}
return len(src)
}
return 0
}
When a param big in size (more than 80 bytes) is passed to another function, it is better to pass a pointer to the value around, rather than the value itself.
There are 5 occurrences of this issue in the repository.
See all occurrences on DeepSource β deepsource.io/gh/cinar/indicator/issue/CRT-P0003/occurrences/
Hi !
I think there is a mistake in the Stochastic Oscillator calculation.
From this site, it seems that the multiplyBy
is not in the right place.
This :
k := divide(substract(closing, lowestLow14), multiplyBy(substract(highestHigh14, lowestLow14), float64(100)))
Should be :
k := multiplyBy(divide(substract(closing, lowestLow14), substract(highestHigh14, lowestLow14)), float64(100))
I might be wrong but results from this change looks nice to me !
And thank you for this package, I love it :D
The true strength index (TSI) is a technical momentum oscillator used to identify trends and reversals. The indicator may be useful for determining overbought and oversold conditions, indicating potential trend direction changes via centerline or signal line crossovers, and warning of trend weakness through divergence.
Weighted moving averages assign a heavier weighting to more current data points since they are more relevant than data points in the distant past. The sum of the weighting should add up to 1 (or 100%).
Packages exposing functions that can stop program execution by exiting are hard to reuse. Program exits in functions other than main() or init() are not encouraged. Non-preferred way:
There is 1 occurrence of this issue in the repository.
See all occurrences on DeepSource β deepsource.io/gh/cinar/indicator/issue/RVV-A0003/occurrences/
Currently all indicators are in a single file, and all strategies are in a single file. It will be better to split them to multiple files aligned with their group.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.