Giter Club home page Giter Club logo

indicator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

indicator's Issues

Volatility: Ulcer Index (UI)

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.

RSI custom period

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).

Implement binary search tree and replace min and max functions

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

Momentum: Price Rate Of Change Indicator (ROC)

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.

https://www.investopedia.com/terms/p/pricerateofchange.asp

Lower Acceleration Band Value is incorrect

Maths for acceleration lower band appears to be incorrect
image

Expected:
1m:
image

15m:
image

1h:
image

To Reproduce
image
+
image

Expected behavior
Formula to calculate the lower band would correlate with the following pinescript:
image

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 πŸ˜…

Trend: Mass Index (MI)

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.

https://www.investopedia.com/terms/m/mass-index.asp

Chaikin Oscillator

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.

https://www.investopedia.com/terms/c/chaikinoscillator.asp

Double Exponential Moving Average (DEMA)

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

Question about RSI implementation

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.

MoneyFlowIndex values well above 100

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.

Volatility: Donchian Channel (DC)

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.

FOSC / CFO Indicator

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

Momentum: Stochastic RSI (SRSI)

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.

https://www.investopedia.com/terms/s/stochrsi.asp

Implement the Larry Connors the 2-period RSI strategy #69

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

Momentum: Ultimate Oscillator (UO)

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.

https://www.investopedia.com/terms/u/ultimateoscillator.asp

Setup dependabot

Warn: dependabot config file not detected in source location. We recommend setting this configuration in code so it can be easily verified by others.

Are KDJ metrics available

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.

Bollinger Bands standard deviation calculation is different from other implementations

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:

Screenshot 2022-06-20 at 23 19 08

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
}

Stochastic Oscillator problem

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

Momentum: True Strength Index (TSI)

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.

https://www.investopedia.com/terms/t/tsi.asp

Split indicators and strategies.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.