GithubHelp home page GithubHelp logo

nettrader.indicator's Introduction

NetTrader.Indicator NuGet stable

Technical analysis library for .NET

Sample for Relative Strength Index (RSI) usage:

  RSI rsi = new RSI(14);
  List<Ohlc> ohlcList = new List<Ohlc>();
  // fill ohlcList
  rsi.Load(ohlcList);
  RSISerie serie = rsi.Calculate();

Library includes the following implementations:

  • Accumulation/Distribution (ADL)
  • Average Directional Index (ADX)
  • Aroon
  • Average True Range (ATR)
  • BollingerBand
  • Commodity Channel Index (CCI)
  • Chaikin Money Flow (CMF)
  • Chande Momentum Oscillator (CMO)
  • Double Exponential Moving Average (DEMA)
  • Detrended Price Oscillator (DPO)
  • Exponential Moving Average (EMA)
  • Moving Average Envelopes (Envelope)
  • Ichimoku Clouds (Ichimoku)
  • Moving Average Convergence Divergence (MACD)
  • Momentum
  • On Balance Volume (OBV)
  • Price Volume Trend (PVT)
  • Rate of Change (ROC)
  • Relative Strength Index (RSI)
  • Stop and Reverse (SAR)
  • Simple Moving Average (SMA)
  • TRIX
  • Volume
  • Volume Rate of Change (VROC)
  • Weighted Moving Average (WMA)
  • Williams %R (WPR)
  • Zero Lag EMA (ZLEMA)

nettrader.indicator's People

Contributors

anilca avatar wingcd avatar

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

nettrader.indicator's Issues

RSI is Off

You should be using formula described here..

https://stackoverflow.com/questions/38481354/rsi-vs-wilders-rsi-calculation-problems

Answer by RooiWillie in this thread matches ditto! Copying here..

=====================================================================

In order to calculate the RSI, you need a period to calculate it with. As noted on Wikipedia, 14 is used quite often.

So the calculation steps would be as follows:

Period 1 - 13, RSI = 0

Period 14:

AverageGain = TotalGain / PeriodCount;
AverageLoss = TotalLoss / PeriodCount;
RS = AverageGain / AverageLoss;
RSI = 100 - 100 / (1 + RS);
Period 15 - to period (N):

if (Period(N)Change > 0
AverageGain(N) = ((AverageGain(N - 1) * (PeriodCount - 1)) + Period(N)Change) / PeriodCount;
else
AverageGain(N) = (AverageGain(N - 1) * (PeriodCount - 1)) / PeriodCount;

if (this.Change < 0)
AverageLoss(N) = ((AverageLoss(N - 1) * (PeriodCount - 1)) + Math.Abs(Period(N)Change)) / PeriodCount;
else
AverageLoss(N) = (AverageLoss(N - 1) * (PeriodCount - 1)) / PeriodCount;

RS = AverageGain / AverageLoss;
RSI = 100 - (100 / (1 + RS));

What is AdjClose for in Ohlc class?

Hi, firstly thanks for this project, I think it will be very useful.

I have been trying to understand what AdjClose is for in the Ohlc class, in the context of MACD. I have been looking at the sample data file table.csv, which has
Date | Open | High | Low | Close | Volume | Adj Close

All the candle data available on exchanges seems to have all fields except AdjClose, yet your source data includes it.

a) Are we supposed to supply something in the AdjClose column or just Close, or both? What is the difference?
b) AdjClose and Close are within about 20% of each other in the csv file, before Calculate(). But after macd.Calculate(), the macd.OhlcList has had all the Close values replaced:
Before: 152.2
After: -1.827068
Is there a reason for this we need to know about?

Thanks for any clarification.

EMA Not matching Trading View

The EMA calculation is not matching trading view for say at least the first 100 candles. It seems to eventually match but takes a long time.

Bollinger Bands source set as HLC3

I have been battling why the calculated Bollinger Band values do not match those from the exchanges I use with the default settings.

Line 49 assumes source is HLC3:

OhlcList[i].Close = (OhlcList[i].High + OhlcList[i].Low + OhlcList[i].Close) / 3;

TradingView, for example, uses Close by default.

Perhaps the BollingerBand override could also support Close as a parameter.

For now, I plan to proceed with line 49 commented out.

Thanks

RSI value is NaN

There seems to be some issue with the RSI calculations if all the Close values are the same:

[Fact]
        public void RSIWithHardCodedValues()
        {
            RSI rsi = new RSI(14);
            List<Ohlc> ohlcList = new List<Ohlc>
            {
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 },
                new Ohlc { Close = 44.34 }
            };
            rsi.Load(ohlcList);
            RSISerie serie = rsi.Calculate();

            Assert.False(serie.RSI.Last() is Double.NaN);
        }

Example CSV records must be reversed

As I read source of EMA.cs, It seems your Test project CSV file records must be reversed.
I mean First record must be the oldest record.

Am I wrong?

Getting Signal

Hi, How can I use the result of the Calculate method of the Indicators to get a signal (Buy, Sell, or stay) !? what are those numbers in the result and what they mean? thanks

Örnek proje

Merhaba,

İndicator kullanımı ile ilgili elinizde paylaşabileceğiniz örnek bir proje var mıdır?
Konuyu yeni öğrendiğim için nasıl uygulanacağı hakkında bilgi toplamaya çalışıyorum.

Teşekkür ederim.

MACD goofing up OHLC original close value

While calculating MACD close value is being changed in source list! line 68 and 73 of MACD.cs is bug. Also looks like something wrong with calculation as it does not match with the stock MACD and signal values.

Since the Close value is changed in the source list, if we call other functions passing OHLC list, they too goof up.

BinaryFormatter is deprecated

BinaryFormatter has been deprecated, and will no longer be available in .NET after November 2023.

I've heard comments on stackoverflow saying that: "Using BinaryFormatter as a hack to create a deep clone for an object. That's still a hack and can easily end up producing bad copies".

Should you update Utils.cs?

Ohlc Date: Opening or Closing?

Hi there. First of all, thanks for creating this awesome package and saving me from a lot of icky math!

I have a question (that might be somewhat stupid): Should the Date property of the Ohlc class correspond to the Open Time of the candle, or the close time?

I think it should be the Closing Time of the candle period, but I just wanted to be sure. Thanks for your reply!

Farklı indikatör?

farklı indikatör var baya faydalı 2 tane hatta onları koyabilir misin projeye?

RSI Calculation not correct

Hi,

I was trying the real data for BTC for 15 minutes as below

RSI: 38.7
Tradingview showing : 32.3

data
List ohlcList = new List
{
new Ohlc { Close = 35912.88 },
new Ohlc { Close = 36015.69 },
new Ohlc { Close = 35939.43 },
new Ohlc { Close = 35886.66 },
new Ohlc { Close = 35987.14 },
new Ohlc { Close = 35868.13 },
new Ohlc { Close = 36098.19 },
new Ohlc { Close = 36090.88 },
new Ohlc { Close = 35913.99},
new Ohlc { Close = 35869.81},
new Ohlc { Close = 35905.80 },
new Ohlc { Close = 35781.40 },
new Ohlc { Close = 35769.19 },
new Ohlc { Close = 35639.03 },
new Ohlc { Close = 46.28 },
new Ohlc { Close = 46.00 },
new Ohlc { Close = 46.03 },
new Ohlc { Close = 46.41 },
new Ohlc { Close = 46.22 },
new Ohlc { Close = 45.64 }
};

RSI not working correctly.

Hi, I'm quite sure the RSI indicator isn't calculating properly. You're not using the Period correctly. You're using a "change" List that you keep adding to for the full history. I think you're calculating the average gain and average loss for the full period, instead of the period variable. When I ran the 14 day RSI for the full SPY historical data, your RSI was always calculating to be around 50. It's supposed to be an oscillator from 1-100. Anyway, thanks for the API.

I'm not totally sure my revisions are correct, but here's what I did to work around the problem.

` public override RSISerie Calculate()
{
RSISerie rsiSerie = new RSISerie();

        // Add null values for first item, iteration will start from second item of OhlcList
        rsiSerie.RS.Add(null);
        rsiSerie.RSI.Add(null);
      //  change.Add(null);

        for (int i = 1; i < OhlcList.Count; i++)
        {
            if (i > this.Period)
            {
                int start = i - Period;
                double gainSum = 0;
                for(int j= start; j <= i; j++)
                {
                    double thisChange = OhlcList[j].Close - OhlcList[j - 1].Close;
                    if (thisChange > 0)
                    {
                        gainSum = gainSum + thisChange;
                    }
                }
                var averageGain = gainSum / Period;
                double lossSum = 0;
                for (int j = start; j <= i; j++)
                {
                    double thisChange = OhlcList[j].Close - OhlcList[j - 1].Close;
                    if (thisChange < 0)
                    {
                        lossSum = lossSum + thisChange;
                    }
                }
                var averageLoss = -1 * lossSum / Period;
                //   var averageGain = change.Where(x => x > 0).Sum() / change.Count;
               // var averageLoss = change.Where(x => x < 0).Sum() * (-1) / change.Count;
                var rs = averageGain / averageLoss;
                rsiSerie.RS.Add(rs);
                var rsi = 100 - (100 / (1 + rs));
                Console.WriteLine("i=" + i + " averageGai=" + averageGain + " averageLoss=" + averageLoss + " rs=" + rs+ " rsi="+ rsi);
                rsiSerie.RSI.Add(rsi);
                // assign change for item
             //   change.Add(OhlcList[i].Close - OhlcList[i - 1].Close);
            }
            else
            {   
                rsiSerie.RS.Add(null);
                rsiSerie.RSI.Add(null);
                // assign change for item
              //  change.Add(OhlcList[i].Close - OhlcList[i - 1].Close);
            }
        }
        return rsiSerie;
    }
}`

Modify SMA to work on fields other than Close

Firstly, really great library and thanks for sharing.

Small comment. The SMA is currently hard coded to use the Close field. It would be good for it to be able to work on other fields, Volume perhaps being most common.

    public override SingleDoubleSerie Calculate()
    {
        SingleDoubleSerie smaSerie = new SingleDoubleSerie();
            
        for (int i = 0; i < OhlcList.Count; i++)
        {   
            if (i >= Period - 1)
            {
                double sum = 0;
                for (int j = i; j >= i - (Period - 1); j--)
                {
                    sum += OhlcList[j].Close;
                }
                double avg = sum / Period;
                smaSerie.Values.Add(avg);
            }
            else
            {
                smaSerie.Values.Add(null);
            }
        }

        return smaSerie;
    }

I might have a go at implementing more flexability regarding the field it uses if I get a chance...

Match OHLC object to BinanceKline object

Hi,

I'm trying to fill the candles I've taken from Binance.net API List <Ohlc>.

There is a section I hang out at this point.
I didn't match the object BinanceKline (the object that the Binance API is returned to me) with the OhLC object.

E.g:

  1. What is the "Volume" feature in the OHLC object equivalent to the Binancekline object?

  2. What is the "adjClose" feature in the OHLC object equivalent to the Binancekline object?

  3. What is the "Date" feature in the OHLC object equivalent to the Binancekline object?

Binancekline object:

image

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.