├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Excel ├── cs-bbands.xls ├── cs-cci.xls ├── cs-rsi.xls └── cs-stochrsi.xls ├── IndicatorsBot.Core ├── Common │ ├── Consts.cs │ └── Utils.cs ├── Exchanges │ ├── Bitfinex │ │ ├── TickerCandlesReader.cs │ │ ├── TickerHistoryReader.cs │ │ └── TickerReader.cs │ └── Interfaces │ │ └── IExchangeTicker.cs ├── Indicators │ ├── BollingerBands.cs │ ├── CCI.cs │ └── RSI.cs ├── IndicatorsBot.Core.csproj ├── Model │ ├── BBandSignal.cs │ ├── CCISIgnal.cs │ ├── RSISignal.cs │ └── Ticker.cs └── TickerHandler.cs ├── IndicatorsBot.Test ├── BollingerBands.cs ├── CCI.cs ├── IndicatorsBot.Test.csproj └── RSI.cs ├── IndicatorsBot.sln ├── IndicatorsBot ├── IndicatorsBot.ConsoleApp.csproj └── Program.cs ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/IndicatorsBot/bin/Debug/netcoreapp2.0/IndicatorsBot.ConsoleApp.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/IndicatorsBot", 16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window 17 | "console": "integratedTerminal", 18 | "stopAtEntry": false, 19 | "internalConsoleOptions": "openOnSessionStart" 20 | }, 21 | { 22 | "name": ".NET Core Attach", 23 | "type": "coreclr", 24 | "request": "attach", 25 | "processId": "${command:pickProcess}" 26 | } 27 | ,] 28 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/IndicatorsBot/IndicatorsBot.ConsoleApp.csproj" 11 | ], 12 | "problemMatcher": "$msCompile" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /Excel/cs-bbands.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelcostabr/IndicatorsBot/e2828ea5bdb27d7f2ead0b48aa92cf9312b40efd/Excel/cs-bbands.xls -------------------------------------------------------------------------------- /Excel/cs-cci.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelcostabr/IndicatorsBot/e2828ea5bdb27d7f2ead0b48aa92cf9312b40efd/Excel/cs-cci.xls -------------------------------------------------------------------------------- /Excel/cs-rsi.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelcostabr/IndicatorsBot/e2828ea5bdb27d7f2ead0b48aa92cf9312b40efd/Excel/cs-rsi.xls -------------------------------------------------------------------------------- /Excel/cs-stochrsi.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelcostabr/IndicatorsBot/e2828ea5bdb27d7f2ead0b48aa92cf9312b40efd/Excel/cs-stochrsi.xls -------------------------------------------------------------------------------- /IndicatorsBot.Core/Common/Consts.cs: -------------------------------------------------------------------------------- 1 | namespace IndicatorsBot.Core.Exchanges.Bitfinex 2 | { 3 | public static class Consts 4 | { 5 | public const int PoolingInterval = 60000; 6 | public const string BitFinexAPIAddress = "https://api.bitfinex.com/"; 7 | 8 | public const string CandleInterval1Min = "1m"; 9 | public const string CandleInterval5Min = "5m"; 10 | public const string CandleInterval15Min = "15m"; 11 | public const string CandleInterval30Min = "30m"; 12 | public const string CandleInterval60Min = "1h"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Common/Utils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IndicatorsBot.Core.Common 4 | { 5 | public static class Utils 6 | { 7 | public static DateTime FromUnixTime(long unixTime) 8 | { 9 | return epoch.AddSeconds(unixTime); 10 | } 11 | private static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Exchanges/Bitfinex/TickerCandlesReader.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core.Model; 2 | using Newtonsoft.Json.Linq; 3 | using System.Collections.Generic; 4 | using System.Net.Http; 5 | 6 | namespace IndicatorsBot.Core.Exchanges.Bitfinex 7 | { 8 | public class TickerCandlesReader 9 | { 10 | readonly HttpClient client = new HttpClient(); 11 | private string Route; 12 | private readonly string Address; 13 | 14 | public TickerCandlesReader() => Address = Consts.BitFinexAPIAddress; 15 | 16 | public List GetHistory(string ticker, string period, int interval) 17 | { 18 | var result = new List(); 19 | 20 | Route = string.Format($"v2/candles/trade:{period}:t{ticker}/hist?limit={interval}"); 21 | 22 | HttpResponseMessage response = client.GetAsync(Address + Route).Result; 23 | response.EnsureSuccessStatusCode(); 24 | string responseBody = response.Content.ReadAsStringAsync().Result; 25 | 26 | dynamic stuff = JArray.Parse(responseBody); 27 | 28 | for (int i = interval-1; i >= 0; i--) 29 | { 30 | var t = new Ticker() 31 | { 32 | last_price = stuff[i][2], 33 | timestamp = stuff[i][0]/1000, 34 | high = stuff[i][3], 35 | low = stuff[i][4] 36 | }; 37 | 38 | t.UtcDateTime = Core.Common.Utils.FromUnixTime((long)t.timestamp).ToLocalTime(); 39 | 40 | result.Add(t); 41 | 42 | //Console.WriteLine($"{FromUnixTime((long)t.timestamp).ToLocalTime()} ({t.timestamp}): {t.last_price}"); 43 | } 44 | 45 | return result; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Exchanges/Bitfinex/TickerHistoryReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * I started writing this class, but ended up discovering that Bitfinex API v1/trades/ endpoint never returns the ticker closest to the unix epoch time passed. 3 | * The class is fully functional, but with this API is not trustable. 4 | * I'll keep the code, for future purposes but I'll abandon the usage and find another way to the the ticker history 5 | * */ 6 | using IndicatorsBot.Core.Model; 7 | using Newtonsoft.Json.Linq; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Net.Http; 11 | 12 | namespace IndicatorsBot.Core.Exchanges.Bitfinex 13 | { 14 | [Obsolete("Not working fine with bitfinex API. Use TickerCandles instead", false)] 15 | public class TickerHistoryReader 16 | { 17 | readonly HttpClient client = new HttpClient(); 18 | private readonly string Address; 19 | 20 | public TickerHistoryReader() => Address = Consts.BitFinexAPIAddress; 21 | 22 | public static DateTime FromUnixTime(long unixTime) 23 | { 24 | return epoch.AddSeconds(unixTime); 25 | } 26 | private static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); 27 | 28 | public List GetHistory(string ticker, int intervalInMinutes, int quantity) 29 | { 30 | var result = new List(); 31 | 32 | long currentUnixEpochTime = (long)Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds); 33 | 34 | long startMilliseconds = currentUnixEpochTime - (intervalInMinutes * 60 * quantity); 35 | 36 | for (int i = 1; i <= quantity; i++) 37 | { 38 | long currentUnixTime = startMilliseconds + (intervalInMinutes * 60 * i); 39 | bool success = false; 40 | while (!success) 41 | { 42 | result.Add(GetQuoteByDate(ticker, currentUnixTime, out success)); 43 | System.Threading.Thread.Sleep(10000); //wait 10 seconds to avoid HTTP 429 error (Too Many Requests) 44 | } 45 | } 46 | 47 | return result; 48 | } 49 | 50 | private Ticker GetQuoteByDate(string ticker, long unixEpochTime, out bool success) 51 | { 52 | var Route = string.Format("v1/trades/{0}?timestamp={1}&limit_trades=1", ticker, unixEpochTime); 53 | 54 | HttpResponseMessage response = client.GetAsync(Address + Route).Result; 55 | response.EnsureSuccessStatusCode(); 56 | string responseBody = response.Content.ReadAsStringAsync().Result; 57 | 58 | dynamic stuff = JArray.Parse(responseBody); 59 | 60 | var t = new Ticker() 61 | { 62 | last_price = stuff[0].price, 63 | timestamp = stuff[0].timestamp, 64 | UtcDateTime = FromUnixTime(unixEpochTime) 65 | }; 66 | 67 | Console.WriteLine($"meu {t.UtcDateTime} ({unixEpochTime}) - api {FromUnixTime((long)t.timestamp)} ({t.timestamp}): {t.last_price}"); 68 | success = true; 69 | return t; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Exchanges/Bitfinex/TickerReader.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core.Exchanges.Interfaces; 2 | using IndicatorsBot.Core.Model; 3 | using Newtonsoft.Json.Linq; 4 | using System; 5 | using System.Net.Http; 6 | using System.Threading.Tasks; 7 | 8 | namespace IndicatorsBot.Core.Exchanges.Bitfinex 9 | { 10 | public class TickerReader : IExchangeTickerReader 11 | { 12 | public event EventHandler TickerReady; 13 | public event EventHandler OnError; 14 | public bool Enabled { get; set; } 15 | static HttpClient client = new HttpClient(); 16 | public string Route { get; set; } 17 | public string Address { get; set; } 18 | public int PoolingInterval { get; set; } 19 | public TickerReader() 20 | { 21 | Address = Consts.BitFinexAPIAddress; 22 | PoolingInterval = Consts.PoolingInterval; 23 | } 24 | 25 | public async Task Start(string ticker) 26 | { 27 | Enabled = true; 28 | 29 | while (Enabled) 30 | { 31 | try 32 | { 33 | FetchTicker(ticker); 34 | } 35 | catch (Exception ex) 36 | { 37 | string e = null; 38 | if (ex.InnerException != null) 39 | { 40 | e = ex.InnerException.Message; 41 | } 42 | else 43 | { 44 | e = ex.Message; 45 | } 46 | OnError(this, e); 47 | await Task.Delay(PoolingInterval * 2); 48 | } 49 | 50 | await Task.Delay(PoolingInterval); 51 | } 52 | } 53 | 54 | public void FetchTicker(string ticker) 55 | { 56 | Route = string.Format("v1/pubticker/{0}", ticker); 57 | 58 | HttpResponseMessage response = client.GetAsync(Address + Route).Result; 59 | response.EnsureSuccessStatusCode(); 60 | string responseBody = response.Content.ReadAsStringAsync().Result; 61 | 62 | dynamic stuff = JObject.Parse(responseBody); 63 | 64 | var handler = TickerReady; 65 | 66 | if (handler != null) 67 | { 68 | var args = new Ticker() 69 | { 70 | mid = stuff.mid, 71 | bid = stuff.bid, 72 | ask = stuff.ask, 73 | last_price = stuff.last_price, 74 | low = stuff.low, 75 | high = stuff.high, 76 | volume = stuff.volume, 77 | timestamp = stuff.timestamp 78 | }; 79 | 80 | handler(this, args); 81 | } 82 | } 83 | 84 | public void Stop() 85 | { 86 | Enabled = false; 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /IndicatorsBot.Core/Exchanges/Interfaces/IExchangeTicker.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core.Model; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace IndicatorsBot.Core.Exchanges.Interfaces 6 | { 7 | public interface IExchangeTickerReader 8 | { 9 | event EventHandler TickerReady; 10 | event EventHandler OnError; 11 | bool Enabled { get; set; } 12 | int PoolingInterval { get; set; } 13 | Task Start(string ticker); 14 | void Stop(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Indicators/BollingerBands.cs: -------------------------------------------------------------------------------- 1 |  2 | using IndicatorsBot.Core.Model; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace IndicatorsBot.Core.Indicators 7 | { 8 | public class BollingerBands 9 | { 10 | private readonly List Values = new List(); 11 | private EventHandler indicatorReady; 12 | private EventHandler onError; 13 | 14 | public BBandSignal this[int index] 15 | { 16 | get 17 | { 18 | return this.Values[index]; 19 | } 20 | 21 | set 22 | { 23 | this.Values[index] = value; 24 | } 25 | } 26 | 27 | public void Add(DateTime TradeDate, decimal Price) 28 | { 29 | try 30 | { 31 | var trade = new BBandSignal() { Price = Price, CloseDate = TradeDate}; 32 | 33 | if (this.Values.Count >= 19) 34 | { 35 | decimal sumOfPrices = trade.Price; 36 | this.Values.GetRange(this.Values.Count - 19, 19).ForEach(i => sumOfPrices += i.Price); 37 | 38 | //Middle Band 20-Day SMA 39 | trade.SMA = Math.Round((double)(sumOfPrices / 20), 4); 40 | 41 | //Standard Deviation formula 42 | //SD = Sqrt((∑∣x−μ∣²)/N) 43 | double aux = Math.Pow(Math.Abs((double)Price - trade.SMA), 2); 44 | this.Values.GetRange(this.Values.Count - 19, 19).ForEach(i => aux += Math.Pow(((double)i.Price - trade.SMA), 2)); 45 | trade.SD = Math.Round(Math.Sqrt(aux / 20), 4); 46 | 47 | trade.UpperBandSMA = Math.Round(trade.SMA + trade.SD * 2, 2); 48 | 49 | trade.LowerBandSMA = Math.Round(trade.SMA - trade.SD * 2, 2); 50 | 51 | trade.BandWidth = Math.Round(trade.UpperBandSMA - trade.LowerBandSMA, 2); 52 | 53 | //calc trend based on the inclination 54 | decimal y1, y2; 55 | decimal x1, x2; 56 | 57 | x2 = this.Values.Count; 58 | x1 = x2 - 19; 59 | 60 | y2 = this.Values[this.Values.Count - 1].Price; 61 | y1 = this.Values[this.Values.Count - 19].Price; 62 | 63 | trade.Inclination = (y2 - y1) / (x2 - x1); 64 | 65 | trade.UpTrend = trade.Inclination > 0; 66 | 67 | var pos = (trade.Price - (decimal)trade.LowerBandSMA) / (decimal)(trade.UpperBandSMA - trade.LowerBandSMA); 68 | trade.Position = Math.Round(pos * 100, 4); 69 | } 70 | 71 | Values.Add(trade); 72 | if (this.Values.Count >= 19) 73 | { 74 | IndicatorReady?.Invoke(this, trade); 75 | } 76 | } 77 | catch (Exception ex) 78 | { 79 | if (this.OnError != null) OnError(this, ex.Message); 80 | } 81 | } 82 | 83 | public int Count 84 | { 85 | get => this.Values.Count; 86 | } 87 | public EventHandler OnError { get => onError; set => onError = value; } 88 | public EventHandler IndicatorReady { get => indicatorReady; set => indicatorReady = value; } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Indicators/CCI.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core.Model; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace IndicatorsBot.Core.Indicators 6 | { 7 | public class CCI 8 | { 9 | private List Values = new List(); 10 | public EventHandler IndicatorReady; 11 | public EventHandler OnError; 12 | 13 | public CCISignal this[int index] 14 | { 15 | get 16 | { 17 | return this.Values[index]; 18 | } 19 | 20 | set 21 | { 22 | this.Values[index] = value; 23 | } 24 | } 25 | 26 | public void Add(DateTime TradeDate, decimal HighPrice, decimal LowPrice, decimal Price) 27 | { 28 | try 29 | { 30 | var trade = new CCISignal() { CloseDate = TradeDate, ClosePrice = Price, HighPrice = HighPrice, LowPrice = LowPrice}; 31 | 32 | trade.TypicalPrice = Math.Round((trade.HighPrice + trade.LowPrice + trade.ClosePrice) / 3, 4); 33 | 34 | if (this.Values.Count >= 19) 35 | { 36 | //calculate SMA 37 | decimal sumOfPrices = trade.TypicalPrice; 38 | 39 | this.Values.GetRange(this.Values.Count-19, 19).ForEach(i => sumOfPrices += i.TypicalPrice); 40 | 41 | trade.SMA = Math.Round((double)(sumOfPrices / 20), 4); 42 | 43 | //calculate MAD 44 | double mad = Math.Abs(trade.SMA - (double)trade.TypicalPrice); 45 | this.Values.GetRange(this.Values.Count - 19, 19).ForEach(i => mad += Math.Abs(trade.SMA - ((double)i.TypicalPrice))); 46 | 47 | trade.MAD = Math.Round(mad / 20,4); 48 | 49 | //calculate 20-period CCI 50 | trade.CCI = Math.Round(((double)trade.TypicalPrice - trade.SMA) / (0.015 * trade.MAD), 4); 51 | 52 | //calc trend based on the inclination 53 | double y1, y2; 54 | double x1, x2; 55 | 56 | x2 = this.Values.Count; 57 | x1 = x2 - 19; 58 | 59 | y2 = this.Values[this.Values.Count - 1].CCI; 60 | y1 = this.Values[this.Values.Count - 19].CCI; 61 | 62 | trade.Inclination = (y2 - y1) / (x2 - x1); 63 | 64 | trade.UpTrend = trade.Inclination > 0; 65 | } 66 | 67 | Values.Add(trade); 68 | 69 | if (this.Values.Count >= 19) 70 | { 71 | IndicatorReady?.Invoke(this, trade); 72 | } 73 | } 74 | catch (Exception ex) 75 | { 76 | if (this.OnError != null) OnError(this, ex.Message); 77 | } 78 | } 79 | 80 | public int Count 81 | { 82 | get => this.Values.Count; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Indicators/RSI.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core.Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace IndicatorsBot.Core.Indicators 7 | { 8 | public class RSI 9 | { 10 | private List Values = new List(); 11 | public string Ticker { get; set; } 12 | public EventHandler IndicatorReady; 13 | public EventHandler OnError; 14 | 15 | public RSISignal this[int index] 16 | { 17 | get 18 | { 19 | return this.Values[index]; 20 | } 21 | 22 | set 23 | { 24 | this.Values[index] = value; 25 | } 26 | } 27 | 28 | public void Add(DateTime TradeDate, decimal Price) 29 | { 30 | try 31 | { 32 | var trade = new RSISignal() { CloseDate = TradeDate, ClosePrice = Price }; 33 | if (this.Values.Count > 0) 34 | { 35 | 36 | trade.Change = trade.ClosePrice - this.Values[this.Values.Count - 1].ClosePrice; 37 | 38 | if (trade.Change > 0) 39 | { 40 | trade.Gain = trade.Change; 41 | trade.Loss = 0; 42 | } 43 | else 44 | { 45 | trade.Gain = 0; 46 | trade.Loss = -trade.Change; 47 | } 48 | } 49 | 50 | if (this.Values.Count == 14) 51 | { 52 | decimal averageGain = 0; 53 | decimal averageLoss = 0; 54 | 55 | this.Values.ForEach(i => averageGain += i.Gain); 56 | trade.AverageGain = averageGain / 14; 57 | 58 | this.Values.ForEach(i => averageLoss += i.Loss); 59 | trade.AverageLoss = averageLoss / 14; 60 | 61 | CalculateRSI(trade); 62 | } 63 | else if (this.Values.Count > 14) 64 | { 65 | trade.AverageGain = ((this.Values[this.Values.Count - 1].AverageGain * 13) + trade.Gain) / 14; 66 | trade.AverageLoss = ((this.Values[this.Values.Count - 1].AverageLoss * 13) + trade.Loss) / 14; 67 | 68 | CalculateRSI(trade); 69 | //calc trend based on the inclination 70 | double y1, y2; 71 | double x1, x2; 72 | 73 | x2 = this.Values.Count; 74 | x1 = x2 - 14; 75 | 76 | y2 = this.Values[this.Values.Count - 1].RSI; 77 | y1 = this.Values[this.Values.Count - 15].RSI; 78 | 79 | trade.Inclination = (y2 - y1) / (x2 - x1); 80 | 81 | trade.UpTrend = trade.Inclination > 0; 82 | } 83 | 84 | Values.Add(trade); 85 | 86 | if (this.Values.Count > 27) 87 | { 88 | CalculateStochRSI(Values.Last()); 89 | //calc trend based on the inclination 90 | double y1, y2; 91 | double x1, x2; 92 | 93 | x2 = this.Values.Count; 94 | x1 = x2 - 14; 95 | 96 | y2 = this.Values[this.Values.Count - 1].StochRSI; 97 | y1 = this.Values[this.Values.Count - 15].StochRSI; 98 | 99 | trade.Inclination = (y2 - y1) / (x2 - x1); 100 | 101 | trade.UpTrendSRSI = trade.Inclination > 0; 102 | } 103 | 104 | if (this.Values.Count > 14) 105 | { 106 | IndicatorReady?.Invoke(this, trade); 107 | } 108 | } 109 | catch (Exception ex) 110 | { 111 | if (this.OnError != null) OnError(this, ex.Message); 112 | } 113 | } 114 | 115 | private void CalculateStochRSI(RSISignal trade) 116 | { 117 | var last14 = this.Values.TakeLast(14); 118 | 119 | double highestRSI = (from x in last14 select x.RSI).Max(); 120 | double lowestRSI = (from x in last14 select x.RSI).Min(); 121 | 122 | trade.StochRSI = Math.Round((trade.RSI - lowestRSI) / (highestRSI - lowestRSI), 2); 123 | } 124 | 125 | private void CalculateRSI(RSISignal trade) 126 | { 127 | var rs = (double)(trade.AverageGain / trade.AverageLoss); 128 | 129 | trade.RS = Math.Round(rs, 2); 130 | 131 | trade.RSI = trade.AverageLoss == 0 ? 100 : Math.Round(100 - (100 / (1 + rs)), 2); 132 | } 133 | 134 | public int Count 135 | { 136 | get => this.Values.Count; 137 | } 138 | 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/IndicatorsBot.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Model/BBandSignal.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core.Indicators; 2 | using System; 3 | 4 | namespace IndicatorsBot.Core.Model 5 | { 6 | public class BBandSignal 7 | { 8 | public DateTime CloseDate { get; set; } 9 | public decimal Price { get; set; } 10 | public double SMA { get; set; } //Middle Band 20-Day SMA 11 | public double SD { get; set; } //20-Day Standard Deviation 12 | public double UpperBandSMA { get; set; } //Upper Band 20-Day SMA + STDEV x 2 13 | public double LowerBandSMA { get; set; } //Lower Band 20-Day SMA - STDEV x 2 14 | public double BandWidth { get; set; } 15 | public decimal Inclination { get; set; } 16 | public bool UpTrend { get; set; } 17 | public decimal Position { get; set; } //Position in the band 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Model/CCISIgnal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IndicatorsBot.Core.Model 4 | { 5 | public class CCISignal 6 | { 7 | public DateTime CloseDate { get; set; } 8 | public decimal HighPrice { get; set; } 9 | public decimal LowPrice { get; set; } 10 | public decimal ClosePrice { get; set; } 11 | public decimal TypicalPrice { get; set; } 12 | public double SMA { get; set; } //Simple Moving Average 13 | public double MAD { get; set; } //Moving Average Deviation 14 | public double CCI { get; set; } 15 | public double Inclination { get; set; } 16 | public bool UpTrend { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Model/RSISignal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IndicatorsBot.Core.Model 4 | { 5 | public class RSISignal 6 | { 7 | public DateTime CloseDate { get; set; } 8 | public decimal ClosePrice { get; set; } 9 | public decimal Change { get; set; } 10 | public decimal Gain { get; set; } 11 | public decimal Loss { get; set; } 12 | public decimal AverageGain { get; set; } 13 | public decimal AverageLoss { get; set; } 14 | public double RS { get; set; } 15 | public double RSI { get; set; } 16 | public double StochRSI { get; set; } 17 | public double Inclination { get; set; } 18 | public bool UpTrend { get; set; } 19 | public bool UpTrendSRSI { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/Model/Ticker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IndicatorsBot.Core.Model 4 | { 5 | public class Ticker 6 | { 7 | public decimal mid; 8 | public decimal bid; 9 | public decimal ask; 10 | public decimal last_price; 11 | public decimal low; 12 | public decimal high; 13 | public decimal volume; 14 | public decimal timestamp; 15 | public DateTime UtcDateTime; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /IndicatorsBot.Core/TickerHandler.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core.Exchanges.Bitfinex; 2 | using IndicatorsBot.Core.Exchanges.Interfaces; 3 | using IndicatorsBot.Core.Indicators; 4 | using IndicatorsBot.Core.Model; 5 | using System; 6 | 7 | namespace IndicatorsBot.Core 8 | { 9 | public class TickerHandler 10 | { 11 | //on the next verion, it's gonna be an interface 12 | private readonly RSI _rsi = null; 13 | private readonly CCI _cci = null; 14 | private readonly BollingerBands _bband = null; 15 | private readonly IExchangeTickerReader _tickerReader = null; 16 | public EventHandler RSIReady; 17 | public EventHandler CCIReady; 18 | public EventHandler BBandReady; 19 | public EventHandler OnError; 20 | public TickerHandler(IExchangeTickerReader tickerReader, RSI trades) 21 | { 22 | _tickerReader = tickerReader; 23 | _tickerReader.PoolingInterval = Consts.PoolingInterval; 24 | _tickerReader.TickerReady += _tickerReader_TickerReady; 25 | _tickerReader.OnError += _tickerReader_OnError; 26 | _rsi = trades; 27 | _rsi.IndicatorReady += _rsi_IndicatorReady; 28 | } 29 | 30 | public TickerHandler(IExchangeTickerReader tickerReader, CCI trades) 31 | { 32 | _tickerReader = tickerReader; 33 | _tickerReader.PoolingInterval = Consts.PoolingInterval; 34 | _tickerReader.TickerReady += _tickerReader_TickerReady; 35 | _tickerReader.OnError += _tickerReader_OnError; 36 | _cci = trades; 37 | _cci.IndicatorReady += _cci_IndicatorReady; 38 | } 39 | 40 | public TickerHandler(IExchangeTickerReader tickerReader, BollingerBands trades) 41 | { 42 | _tickerReader = tickerReader; 43 | _tickerReader.PoolingInterval = Consts.PoolingInterval; 44 | _tickerReader.TickerReady += _tickerReader_TickerReady; 45 | _tickerReader.OnError += _tickerReader_OnError; 46 | _bband = trades; 47 | _bband.IndicatorReady += _bband_IndicatorReady; 48 | } 49 | 50 | private void _tickerReader_OnError(object sender, string e) 51 | { 52 | if (this.OnError != null) OnError(this, e); 53 | } 54 | 55 | private void _tickerReader_TickerReady(object sender, Ticker e) 56 | { 57 | _rsi?.Add(DateTime.Now, e.last_price); 58 | _cci?.Add(DateTime.Now, e.high, e.low, e.last_price); 59 | _bband?.Add(DateTime.Now, e.last_price); 60 | } 61 | 62 | private void _rsi_IndicatorReady(object sender, RSISignal e) 63 | { 64 | RSIReady(this, e); 65 | } 66 | 67 | private void _cci_IndicatorReady(object sender, CCISignal e) 68 | { 69 | CCIReady(this, e); 70 | } 71 | 72 | private void _bband_IndicatorReady(object sender, BBandSignal e) 73 | { 74 | BBandReady(this, e); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /IndicatorsBot.Test/BollingerBands.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | 4 | namespace IndicatorsBot.Test 5 | { 6 | [TestClass] 7 | public class BollingerBands 8 | { 9 | readonly Core.Indicators.BollingerBands lista = new Core.Indicators.BollingerBands(); 10 | 11 | [TestInitialize] 12 | public void Initialize() 13 | { 14 | lista.Add(DateTime.Parse("2009/05/01"), (decimal)86.1557); 15 | lista.Add(DateTime.Parse("2009/05/04"), (decimal)89.0867); 16 | lista.Add(DateTime.Parse("2009/05/05"), (decimal)88.7829); 17 | lista.Add(DateTime.Parse("2009/05/06"), (decimal)90.3228); 18 | lista.Add(DateTime.Parse("2009/05/07"), (decimal)89.0671); 19 | lista.Add(DateTime.Parse("2009/05/08"), (decimal)91.1453); 20 | lista.Add(DateTime.Parse("2009/05/11"), (decimal)89.4397); 21 | lista.Add(DateTime.Parse("2009/05/12"), (decimal)89.1750); 22 | lista.Add(DateTime.Parse("2009/05/13"), (decimal)86.9302); 23 | lista.Add(DateTime.Parse("2009/05/14"), (decimal)87.6752); 24 | lista.Add(DateTime.Parse("2009/05/15"), (decimal)86.9596); 25 | lista.Add(DateTime.Parse("2009/05/18"), (decimal)89.4299); 26 | lista.Add(DateTime.Parse("2009/05/19"), (decimal)89.3221); 27 | lista.Add(DateTime.Parse("2009/05/20"), (decimal)88.7241); 28 | lista.Add(DateTime.Parse("2009/05/21"), (decimal)87.4497); 29 | lista.Add(DateTime.Parse("2009/05/22"), (decimal)87.2634); 30 | lista.Add(DateTime.Parse("2009/05/26"), (decimal)89.4985); 31 | lista.Add(DateTime.Parse("2009/05/27"), (decimal)87.9006); 32 | lista.Add(DateTime.Parse("2009/05/28"), (decimal)89.1260); 33 | lista.Add(DateTime.Parse("2009/05/29"), (decimal)90.7043); 34 | lista.Add(DateTime.Parse("2009/06/01"), (decimal)92.9001); 35 | lista.Add(DateTime.Parse("2009/06/02"), (decimal)92.9784); 36 | lista.Add(DateTime.Parse("2009/06/03"), (decimal)91.8021); 37 | lista.Add(DateTime.Parse("2009/06/04"), (decimal)92.6647); 38 | lista.Add(DateTime.Parse("2009/06/05"), (decimal)92.6843); 39 | lista.Add(DateTime.Parse("2009/06/08"), (decimal)92.3021); 40 | lista.Add(DateTime.Parse("2009/06/09"), (decimal)92.7725); 41 | lista.Add(DateTime.Parse("2009/06/10"), (decimal)92.5373); 42 | lista.Add(DateTime.Parse("2009/06/11"), (decimal)92.9490); 43 | lista.Add(DateTime.Parse("2009/06/12"), (decimal)93.2039); 44 | lista.Add(DateTime.Parse("2009/06/15"), (decimal)91.0669); 45 | lista.Add(DateTime.Parse("2009/06/16"), (decimal)89.8318); 46 | lista.Add(DateTime.Parse("2009/06/17"), (decimal)89.7435); 47 | lista.Add(DateTime.Parse("2009/06/18"), (decimal)90.3994); 48 | lista.Add(DateTime.Parse("2009/06/19"), (decimal)90.7387); 49 | lista.Add(DateTime.Parse("2009/06/22"), (decimal)88.0177); 50 | lista.Add(DateTime.Parse("2009/06/23"), (decimal)88.0867); 51 | lista.Add(DateTime.Parse("2009/06/24"), (decimal)88.8439); 52 | lista.Add(DateTime.Parse("2009/06/25"), (decimal)90.7781); 53 | lista.Add(DateTime.Parse("2009/06/26"), (decimal)90.5416); 54 | lista.Add(DateTime.Parse("2009/06/29"), (decimal)91.3894); 55 | lista.Add(DateTime.Parse("2009/06/30"), (decimal)90.6500); 56 | } 57 | 58 | [TestMethod] 59 | public void Test_That_SMA_is_Correct() 60 | { 61 | Assert.AreEqual(0, lista[0].SMA); 62 | Assert.AreEqual(0, lista[1].SMA); 63 | Assert.AreEqual(0, lista[2].SMA); 64 | Assert.AreEqual(0, lista[3].SMA); 65 | Assert.AreEqual(0, lista[4].SMA); 66 | Assert.AreEqual(0, lista[5].SMA); 67 | Assert.AreEqual(0, lista[6].SMA); 68 | Assert.AreEqual(0, lista[7].SMA); 69 | Assert.AreEqual(0, lista[8].SMA); 70 | Assert.AreEqual(0, lista[9].SMA); 71 | Assert.AreEqual(0, lista[10].SMA); 72 | Assert.AreEqual(0, lista[11].SMA); 73 | Assert.AreEqual(0, lista[12].SMA); 74 | Assert.AreEqual(0, lista[13].SMA); 75 | Assert.AreEqual(0, lista[14].SMA); 76 | Assert.AreEqual(0, lista[15].SMA); 77 | Assert.AreEqual(0, lista[15].SMA); 78 | Assert.AreEqual(0, lista[17].SMA); 79 | Assert.AreEqual(0, lista[18].SMA); 80 | Assert.AreEqual(88.7079, lista[19].SMA); 81 | Assert.AreEqual(89.0452, lista[20].SMA); 82 | Assert.AreEqual(89.2397, lista[21].SMA); 83 | Assert.AreEqual(89.3907, lista[22].SMA); 84 | Assert.AreEqual(89.5078, lista[23].SMA); 85 | Assert.AreEqual(89.6887, lista[24].SMA); 86 | Assert.AreEqual(89.7465, lista[25].SMA); 87 | Assert.AreEqual(89.9131, lista[26].SMA); 88 | Assert.AreEqual(90.0813, lista[27].SMA); 89 | Assert.AreEqual(90.3822, lista[28].SMA); 90 | Assert.AreEqual(90.6586, lista[29].SMA); 91 | Assert.AreEqual(90.8640, lista[30].SMA); 92 | Assert.AreEqual(90.8841, lista[31].SMA); 93 | Assert.AreEqual(90.9052, lista[32].SMA); 94 | Assert.AreEqual(90.9889, lista[33].SMA); 95 | Assert.AreEqual(91.1534, lista[34].SMA); 96 | Assert.AreEqual(91.1911, lista[35].SMA); 97 | Assert.AreEqual(91.1205, lista[36].SMA); 98 | Assert.AreEqual(91.1677, lista[37].SMA); 99 | Assert.AreEqual(91.2503, lista[38].SMA); 100 | Assert.AreEqual(91.2421, lista[39].SMA); 101 | Assert.AreEqual(91.1666, lista[40].SMA); 102 | Assert.AreEqual(91.0502, lista[41].SMA); 103 | } 104 | 105 | [TestMethod] 106 | public void Test_That_SD_is_Correct() 107 | { 108 | Assert.AreEqual(0, lista[0].SD); 109 | Assert.AreEqual(0, lista[1].SD); 110 | Assert.AreEqual(0, lista[2].SD); 111 | Assert.AreEqual(0, lista[3].SD); 112 | Assert.AreEqual(0, lista[4].SD); 113 | Assert.AreEqual(0, lista[5].SD); 114 | Assert.AreEqual(0, lista[6].SD); 115 | Assert.AreEqual(0, lista[7].SD); 116 | Assert.AreEqual(0, lista[8].SD); 117 | Assert.AreEqual(0, lista[9].SD); 118 | Assert.AreEqual(0, lista[10].SD); 119 | Assert.AreEqual(0, lista[11].SD); 120 | Assert.AreEqual(0, lista[12].SD); 121 | Assert.AreEqual(0, lista[13].SD); 122 | Assert.AreEqual(0, lista[14].SD); 123 | Assert.AreEqual(0, lista[15].SD); 124 | Assert.AreEqual(0, lista[16].SD); 125 | Assert.AreEqual(0, lista[17].SD); 126 | Assert.AreEqual(0, lista[18].SD); 127 | Assert.AreEqual(1.2920, lista[19].SD); 128 | Assert.AreEqual(1.4521, lista[20].SD); 129 | Assert.AreEqual(1.6864, lista[21].SD); 130 | Assert.AreEqual(1.7717, lista[22].SD); 131 | Assert.AreEqual(1.9021, lista[23].SD); 132 | Assert.AreEqual(2.0199, lista[24].SD); 133 | Assert.AreEqual(2.0765, lista[25].SD); 134 | Assert.AreEqual(2.1766, lista[26].SD); 135 | Assert.AreEqual(2.2419, lista[27].SD); 136 | Assert.AreEqual(2.2024, lista[28].SD); 137 | Assert.AreEqual(2.1922, lista[29].SD); 138 | Assert.AreEqual(2.0218, lista[30].SD); 139 | Assert.AreEqual(2.0094, lista[31].SD); 140 | Assert.AreEqual(1.9951, lista[32].SD); 141 | Assert.AreEqual(1.9360, lista[33].SD); 142 | Assert.AreEqual(1.7601, lista[34].SD); 143 | Assert.AreEqual(1.6828, lista[35].SD); 144 | Assert.AreEqual(1.7791, lista[36].SD); 145 | Assert.AreEqual(1.7041, lista[37].SD); 146 | Assert.AreEqual(1.6420, lista[38].SD); 147 | Assert.AreEqual(1.6451, lista[39].SD); 148 | Assert.AreEqual(1.6013, lista[40].SD); 149 | Assert.AreEqual(1.5492, lista[41].SD); 150 | } 151 | 152 | [TestMethod] 153 | public void Test_That_UpperBand_is_Correct() 154 | { 155 | Assert.AreEqual(0, lista[0].UpperBandSMA); 156 | Assert.AreEqual(0, lista[1].UpperBandSMA); 157 | Assert.AreEqual(0, lista[2].UpperBandSMA); 158 | Assert.AreEqual(0, lista[3].UpperBandSMA); 159 | Assert.AreEqual(0, lista[4].UpperBandSMA); 160 | Assert.AreEqual(0, lista[5].UpperBandSMA); 161 | Assert.AreEqual(0, lista[6].UpperBandSMA); 162 | Assert.AreEqual(0, lista[7].UpperBandSMA); 163 | Assert.AreEqual(0, lista[8].UpperBandSMA); 164 | Assert.AreEqual(0, lista[9].UpperBandSMA); 165 | Assert.AreEqual(0, lista[10].UpperBandSMA); 166 | Assert.AreEqual(0, lista[11].UpperBandSMA); 167 | Assert.AreEqual(0, lista[12].UpperBandSMA); 168 | Assert.AreEqual(0, lista[13].UpperBandSMA); 169 | Assert.AreEqual(0, lista[14].UpperBandSMA); 170 | Assert.AreEqual(0, lista[15].UpperBandSMA); 171 | Assert.AreEqual(0, lista[16].UpperBandSMA); 172 | Assert.AreEqual(0, lista[17].UpperBandSMA); 173 | Assert.AreEqual(0, lista[18].UpperBandSMA); 174 | Assert.AreEqual(91.29, lista[19].UpperBandSMA); 175 | Assert.AreEqual(91.95, lista[20].UpperBandSMA); 176 | Assert.AreEqual(92.61, lista[21].UpperBandSMA); 177 | Assert.AreEqual(92.93, lista[22].UpperBandSMA); 178 | Assert.AreEqual(93.31, lista[23].UpperBandSMA); 179 | Assert.AreEqual(93.73, lista[24].UpperBandSMA); 180 | Assert.AreEqual(93.90, lista[25].UpperBandSMA); 181 | Assert.AreEqual(94.27, lista[26].UpperBandSMA); 182 | Assert.AreEqual(94.57, lista[27].UpperBandSMA); 183 | Assert.AreEqual(94.79, lista[28].UpperBandSMA); 184 | Assert.AreEqual(95.04, lista[29].UpperBandSMA); 185 | Assert.AreEqual(94.91, lista[30].UpperBandSMA); 186 | Assert.AreEqual(94.90, lista[31].UpperBandSMA); 187 | Assert.AreEqual(94.90, lista[32].UpperBandSMA); 188 | Assert.AreEqual(94.86, lista[33].UpperBandSMA); 189 | Assert.AreEqual(94.67, lista[34].UpperBandSMA); 190 | Assert.AreEqual(94.56, lista[35].UpperBandSMA); 191 | Assert.AreEqual(94.68, lista[36].UpperBandSMA); 192 | Assert.AreEqual(94.58, lista[37].UpperBandSMA); 193 | Assert.AreEqual(94.53, lista[38].UpperBandSMA); 194 | Assert.AreEqual(94.53, lista[39].UpperBandSMA); 195 | Assert.AreEqual(94.37, lista[40].UpperBandSMA); 196 | Assert.AreEqual(94.15, lista[41].UpperBandSMA); 197 | 198 | } 199 | 200 | [TestMethod] 201 | public void Test_That_LowerBand_is_Correct() 202 | { 203 | Assert.AreEqual(0, lista[0].LowerBandSMA); 204 | Assert.AreEqual(0, lista[1].LowerBandSMA); 205 | Assert.AreEqual(0, lista[2].LowerBandSMA); 206 | Assert.AreEqual(0, lista[3].LowerBandSMA); 207 | Assert.AreEqual(0, lista[4].LowerBandSMA); 208 | Assert.AreEqual(0, lista[5].LowerBandSMA); 209 | Assert.AreEqual(0, lista[6].LowerBandSMA); 210 | Assert.AreEqual(0, lista[7].LowerBandSMA); 211 | Assert.AreEqual(0, lista[8].LowerBandSMA); 212 | Assert.AreEqual(0, lista[9].LowerBandSMA); 213 | Assert.AreEqual(0, lista[10].LowerBandSMA); 214 | Assert.AreEqual(0, lista[11].LowerBandSMA); 215 | Assert.AreEqual(0, lista[12].LowerBandSMA); 216 | Assert.AreEqual(0, lista[13].LowerBandSMA); 217 | Assert.AreEqual(0, lista[14].LowerBandSMA); 218 | Assert.AreEqual(0, lista[15].LowerBandSMA); 219 | Assert.AreEqual(0, lista[16].LowerBandSMA); 220 | Assert.AreEqual(0, lista[17].LowerBandSMA); 221 | Assert.AreEqual(0, lista[18].LowerBandSMA); 222 | Assert.AreEqual(86.12, lista[19].LowerBandSMA); 223 | Assert.AreEqual(86.14, lista[20].LowerBandSMA); 224 | Assert.AreEqual(85.87, lista[21].LowerBandSMA); 225 | Assert.AreEqual(85.85, lista[22].LowerBandSMA); 226 | Assert.AreEqual(85.70, lista[23].LowerBandSMA); 227 | Assert.AreEqual(85.65, lista[24].LowerBandSMA); 228 | Assert.AreEqual(85.59, lista[25].LowerBandSMA); 229 | Assert.AreEqual(85.56, lista[26].LowerBandSMA); 230 | Assert.AreEqual(85.60, lista[27].LowerBandSMA); 231 | Assert.AreEqual(85.98, lista[28].LowerBandSMA); 232 | Assert.AreEqual(86.27, lista[29].LowerBandSMA); 233 | Assert.AreEqual(86.82, lista[30].LowerBandSMA); 234 | Assert.AreEqual(86.87, lista[31].LowerBandSMA); 235 | Assert.AreEqual(86.92, lista[32].LowerBandSMA); 236 | Assert.AreEqual(87.12, lista[33].LowerBandSMA); 237 | Assert.AreEqual(87.63, lista[34].LowerBandSMA); 238 | Assert.AreEqual(87.83, lista[35].LowerBandSMA); 239 | Assert.AreEqual(87.56, lista[36].LowerBandSMA); 240 | Assert.AreEqual(87.76, lista[37].LowerBandSMA); 241 | Assert.AreEqual(87.97, lista[38].LowerBandSMA); 242 | Assert.AreEqual(87.95, lista[39].LowerBandSMA); 243 | Assert.AreEqual(87.96, lista[40].LowerBandSMA); 244 | Assert.AreEqual(87.95, lista[41].LowerBandSMA); 245 | 246 | } 247 | 248 | [TestMethod] 249 | public void Test_That_Bandwidth_is_Correct() 250 | { 251 | Assert.AreEqual(0, lista[0].BandWidth); 252 | Assert.AreEqual(0, lista[1].BandWidth); 253 | Assert.AreEqual(0, lista[2].BandWidth); 254 | Assert.AreEqual(0, lista[3].BandWidth); 255 | Assert.AreEqual(0, lista[4].BandWidth); 256 | Assert.AreEqual(0, lista[5].BandWidth); 257 | Assert.AreEqual(0, lista[6].BandWidth); 258 | Assert.AreEqual(0, lista[7].BandWidth); 259 | Assert.AreEqual(0, lista[8].BandWidth); 260 | Assert.AreEqual(0, lista[9].BandWidth); 261 | Assert.AreEqual(0, lista[10].BandWidth); 262 | Assert.AreEqual(0, lista[11].BandWidth); 263 | Assert.AreEqual(0, lista[12].BandWidth); 264 | Assert.AreEqual(0, lista[13].BandWidth); 265 | Assert.AreEqual(0, lista[14].BandWidth); 266 | Assert.AreEqual(0, lista[15].BandWidth); 267 | Assert.AreEqual(0, lista[16].BandWidth); 268 | Assert.AreEqual(0, lista[17].BandWidth); 269 | Assert.AreEqual(0, lista[18].BandWidth); 270 | Assert.AreEqual(5.17, lista[19].BandWidth); 271 | Assert.AreEqual(5.81, lista[20].BandWidth); 272 | Assert.AreEqual(6.74, lista[21].BandWidth); 273 | Assert.AreEqual(7.08, lista[22].BandWidth); 274 | Assert.AreEqual(7.61, lista[23].BandWidth); 275 | Assert.AreEqual(8.08, lista[24].BandWidth); 276 | Assert.AreEqual(8.31, lista[25].BandWidth); 277 | Assert.AreEqual(8.71, lista[26].BandWidth); 278 | Assert.AreEqual(8.97, lista[27].BandWidth); 279 | Assert.AreEqual(8.81, lista[28].BandWidth); 280 | Assert.AreEqual(8.77, lista[29].BandWidth); 281 | Assert.AreEqual(8.09, lista[30].BandWidth); 282 | Assert.AreEqual(8.03, lista[31].BandWidth); 283 | Assert.AreEqual(7.98, lista[32].BandWidth); 284 | Assert.AreEqual(7.74, lista[33].BandWidth); 285 | Assert.AreEqual(7.04, lista[34].BandWidth); 286 | Assert.AreEqual(6.73, lista[35].BandWidth); 287 | Assert.AreEqual(7.12, lista[36].BandWidth); 288 | Assert.AreEqual(6.82, lista[37].BandWidth); 289 | Assert.AreEqual(6.56, lista[38].BandWidth); 290 | Assert.AreEqual(6.58, lista[39].BandWidth); 291 | Assert.AreEqual(6.41, lista[40].BandWidth); 292 | Assert.AreEqual(6.20, lista[41].BandWidth); 293 | 294 | } 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /IndicatorsBot.Test/CCI.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | 4 | namespace IndicatorsBot.Test 5 | { 6 | [TestClass] 7 | public class CCI 8 | { 9 | Core.Indicators.CCI lista = new Core.Indicators.CCI(); 10 | 11 | [TestInitialize] 12 | public void Initialize() 13 | { 14 | lista.Add(DateTime.Parse("2010/08/24"), (decimal)24.2013, (decimal)23.8534, (decimal)23.8932); 15 | lista.Add(DateTime.Parse("2010/08/25"), (decimal)24.0721, (decimal)23.7242, (decimal)23.9528); 16 | lista.Add(DateTime.Parse("2010/08/26"), (decimal)24.0423, (decimal)23.6447, (decimal)23.6745); 17 | lista.Add(DateTime.Parse("2010/08/27"), (decimal)23.8733, (decimal)23.3664, (decimal)23.7839); 18 | lista.Add(DateTime.Parse("2010/08/30"), (decimal)23.6745, (decimal)23.4559, (decimal)23.4956); 19 | lista.Add(DateTime.Parse("2010/08/31"), (decimal)23.5851, (decimal)23.1776, (decimal)23.3217); 20 | lista.Add(DateTime.Parse("2010/09/01"), (decimal)23.8037, (decimal)23.3962, (decimal)23.7540); 21 | lista.Add(DateTime.Parse("2010/09/02"), (decimal)23.8036, (decimal)23.5652, (decimal)23.7938); 22 | lista.Add(DateTime.Parse("2010/09/03"), (decimal)24.3007, (decimal)24.0522, (decimal)24.1417); 23 | lista.Add(DateTime.Parse("2010/09/07"), (decimal)24.1516, (decimal)23.7739, (decimal)23.8137); 24 | lista.Add(DateTime.Parse("2010/09/08"), (decimal)24.0522, (decimal)23.5950, (decimal)23.7839); 25 | lista.Add(DateTime.Parse("2010/09/09"), (decimal)24.0622, (decimal)23.8435, (decimal)23.8634); 26 | lista.Add(DateTime.Parse("2010/09/10"), (decimal)23.8833, (decimal)23.6447, (decimal)23.7044); 27 | lista.Add(DateTime.Parse("2010/09/13"), (decimal)25.1356, (decimal)23.9429, (decimal)24.9567); 28 | lista.Add(DateTime.Parse("2010/09/14"), (decimal)25.1952, (decimal)24.7380, (decimal)24.8771); 29 | lista.Add(DateTime.Parse("2010/09/15"), (decimal)25.0660, (decimal)24.7678, (decimal)24.9616); 30 | lista.Add(DateTime.Parse("2010/09/16"), (decimal)25.2151, (decimal)24.8970, (decimal)25.1753); 31 | lista.Add(DateTime.Parse("2010/09/17"), (decimal)25.3741, (decimal)24.9268, (decimal)25.0660); 32 | lista.Add(DateTime.Parse("2010/09/20"), (decimal)25.3642, (decimal)24.9567, (decimal)25.2747); 33 | lista.Add(DateTime.Parse("2010/09/21"), (decimal)25.2648, (decimal)24.9268, (decimal)24.9964); 34 | lista.Add(DateTime.Parse("2010/09/22"), (decimal)24.8175, (decimal)24.2112, (decimal)24.4597); 35 | lista.Add(DateTime.Parse("2010/09/23"), (decimal)24.4398, (decimal)24.2112, (decimal)24.2808); 36 | lista.Add(DateTime.Parse("2010/09/24"), (decimal)24.6485, (decimal)24.4299, (decimal)24.6237); 37 | lista.Add(DateTime.Parse("2010/09/27"), (decimal)24.8374, (decimal)24.4398, (decimal)24.5815); 38 | lista.Add(DateTime.Parse("2010/09/28"), (decimal)24.7479, (decimal)24.2013, (decimal)24.5268); 39 | lista.Add(DateTime.Parse("2010/09/29"), (decimal)24.5094, (decimal)24.2510, (decimal)24.3504); 40 | lista.Add(DateTime.Parse("2010/09/30"), (decimal)24.6784, (decimal)24.2112, (decimal)24.3404); 41 | lista.Add(DateTime.Parse("2010/10/01"), (decimal)24.6684, (decimal)24.1516, (decimal)24.2311); 42 | lista.Add(DateTime.Parse("2010/10/04"), (decimal)23.8435, (decimal)23.6348, (decimal)23.7640); 43 | lista.Add(DateTime.Parse("2010/10/05"), (decimal)24.3007, (decimal)23.7640, (decimal)24.2013); 44 | } 45 | 46 | [TestMethod] 47 | public void Test_That_Typical_Price_Is_Equals_To_Sum_of_Prices_Divided_by_3() 48 | { 49 | Assert.AreEqual((decimal)23.9826, lista[0].TypicalPrice); 50 | Assert.AreEqual((decimal)23.9164, lista[1].TypicalPrice); 51 | Assert.AreEqual((decimal)23.7872, lista[2].TypicalPrice); 52 | Assert.AreEqual((decimal)23.6745, lista[3].TypicalPrice); 53 | Assert.AreEqual((decimal)23.5420, lista[4].TypicalPrice); 54 | Assert.AreEqual((decimal)23.3615, lista[5].TypicalPrice); 55 | Assert.AreEqual((decimal)23.6513, lista[6].TypicalPrice); 56 | Assert.AreEqual((decimal)23.7209, lista[7].TypicalPrice); 57 | Assert.AreEqual((decimal)24.1649, lista[8].TypicalPrice); 58 | Assert.AreEqual((decimal)23.9131, lista[9].TypicalPrice); 59 | Assert.AreEqual((decimal)23.8104, lista[10].TypicalPrice); 60 | Assert.AreEqual((decimal)23.9230, lista[11].TypicalPrice); 61 | Assert.AreEqual((decimal)23.7441, lista[12].TypicalPrice); 62 | Assert.AreEqual((decimal)24.6784, lista[13].TypicalPrice); 63 | Assert.AreEqual((decimal)24.9368, lista[14].TypicalPrice); 64 | Assert.AreEqual((decimal)24.9318, lista[15].TypicalPrice); 65 | Assert.AreEqual((decimal)25.0958, lista[16].TypicalPrice); 66 | Assert.AreEqual((decimal)25.1223, lista[17].TypicalPrice); 67 | Assert.AreEqual((decimal)25.1985, lista[18].TypicalPrice); 68 | Assert.AreEqual((decimal)25.0627, lista[19].TypicalPrice); 69 | Assert.AreEqual((decimal)24.4961, lista[20].TypicalPrice); 70 | Assert.AreEqual((decimal)24.3106, lista[21].TypicalPrice); 71 | Assert.AreEqual((decimal)24.5674, lista[22].TypicalPrice); 72 | Assert.AreEqual((decimal)24.6196, lista[23].TypicalPrice); 73 | Assert.AreEqual((decimal)24.4920, lista[24].TypicalPrice); 74 | Assert.AreEqual((decimal)24.3703, lista[25].TypicalPrice); 75 | Assert.AreEqual((decimal)24.4100, lista[26].TypicalPrice); 76 | Assert.AreEqual((decimal)24.3504, lista[27].TypicalPrice); 77 | Assert.AreEqual((decimal)23.7474, lista[28].TypicalPrice); 78 | Assert.AreEqual((decimal)24.0887, lista[29].TypicalPrice); 79 | } 80 | 81 | [TestMethod] 82 | public void Test_That_SMA_is_Correct() 83 | { 84 | Assert.AreEqual(0, lista[0].SMA); 85 | Assert.AreEqual(0, lista[1].SMA); 86 | Assert.AreEqual(0, lista[2].SMA); 87 | Assert.AreEqual(0, lista[3].SMA); 88 | Assert.AreEqual(0, lista[4].SMA); 89 | Assert.AreEqual(0, lista[5].SMA); 90 | Assert.AreEqual(0, lista[6].SMA); 91 | Assert.AreEqual(0, lista[7].SMA); 92 | Assert.AreEqual(0, lista[8].SMA); 93 | Assert.AreEqual(0, lista[9].SMA); 94 | Assert.AreEqual(0, lista[10].SMA); 95 | Assert.AreEqual(0, lista[11].SMA); 96 | Assert.AreEqual(0, lista[12].SMA); 97 | Assert.AreEqual(0, lista[13].SMA); 98 | Assert.AreEqual(0, lista[14].SMA); 99 | Assert.AreEqual(0, lista[15].SMA); 100 | Assert.AreEqual(0, lista[16].SMA); 101 | Assert.AreEqual(0, lista[17].SMA); 102 | Assert.AreEqual(0, lista[18].SMA); 103 | Assert.AreEqual(24.2109, lista[19].SMA); 104 | Assert.AreEqual(24.2366, lista[20].SMA); 105 | Assert.AreEqual(24.2563, lista[21].SMA); 106 | Assert.AreEqual(24.2953, lista[22].SMA); 107 | Assert.AreEqual(24.3426, lista[23].SMA); 108 | Assert.AreEqual(24.3901, lista[24].SMA); 109 | Assert.AreEqual(24.4405, lista[25].SMA); 110 | Assert.AreEqual(24.4784, lista[26].SMA); 111 | Assert.AreEqual(24.5099, lista[27].SMA); 112 | Assert.AreEqual(24.4890, lista[28].SMA); 113 | Assert.AreEqual(24.4978, lista[29].SMA); 114 | } 115 | 116 | [TestMethod] 117 | public void Test_That_MAD_is_Correct() 118 | { 119 | Assert.AreEqual(0, lista[0].MAD); 120 | Assert.AreEqual(0, lista[1].MAD); 121 | Assert.AreEqual(0, lista[2].MAD); 122 | Assert.AreEqual(0, lista[3].MAD); 123 | Assert.AreEqual(0, lista[4].MAD); 124 | Assert.AreEqual(0, lista[5].MAD); 125 | Assert.AreEqual(0, lista[6].MAD); 126 | Assert.AreEqual(0, lista[7].MAD); 127 | Assert.AreEqual(0, lista[8].MAD); 128 | Assert.AreEqual(0, lista[9].MAD); 129 | Assert.AreEqual(0, lista[10].MAD); 130 | Assert.AreEqual(0, lista[11].MAD); 131 | Assert.AreEqual(0, lista[12].MAD); 132 | Assert.AreEqual(0, lista[13].MAD); 133 | Assert.AreEqual(0, lista[14].MAD); 134 | Assert.AreEqual(0, lista[15].MAD); 135 | Assert.AreEqual(0, lista[16].MAD); 136 | Assert.AreEqual(0, lista[17].MAD); 137 | Assert.AreEqual(0, lista[18].MAD); 138 | Assert.AreEqual(0.5550, lista[19].MAD); 139 | Assert.AreEqual(0.5630, lista[20].MAD); 140 | Assert.AreEqual(0.5526, lista[21].MAD); 141 | Assert.AreEqual(0.5447, lista[22].MAD); 142 | Assert.AreEqual(0.5284, lista[23].MAD); 143 | Assert.AreEqual(0.4911, lista[24].MAD); 144 | Assert.AreEqual(0.4356, lista[25].MAD); 145 | Assert.AreEqual(0.3939, lista[26].MAD); 146 | Assert.AreEqual(0.3624, lista[27].MAD); 147 | Assert.AreEqual(0.3822, lista[28].MAD); 148 | Assert.AreEqual(0.3733, lista[29].MAD); 149 | 150 | } 151 | 152 | [TestMethod] 153 | public void Test_That_CCI_is_Correct() 154 | { 155 | Assert.AreEqual(0, lista[0].CCI); 156 | Assert.AreEqual(0, lista[1].CCI); 157 | Assert.AreEqual(0, lista[2].CCI); 158 | Assert.AreEqual(0, lista[3].CCI); 159 | Assert.AreEqual(0, lista[4].CCI); 160 | Assert.AreEqual(0, lista[5].CCI); 161 | Assert.AreEqual(0, lista[6].CCI); 162 | Assert.AreEqual(0, lista[7].CCI); 163 | Assert.AreEqual(0, lista[8].CCI); 164 | Assert.AreEqual(0, lista[9].CCI); 165 | Assert.AreEqual(0, lista[10].CCI); 166 | Assert.AreEqual(0, lista[11].CCI); 167 | Assert.AreEqual(0, lista[12].CCI); 168 | Assert.AreEqual(0, lista[13].CCI); 169 | Assert.AreEqual(0, lista[14].CCI); 170 | Assert.AreEqual(0, lista[15].CCI); 171 | Assert.AreEqual(0, lista[16].CCI); 172 | Assert.AreEqual(0, lista[17].CCI); 173 | Assert.AreEqual(0, lista[18].CCI); 174 | Assert.AreEqual(102.3183, lista[19].CCI); 175 | Assert.AreEqual(30.7282, lista[20].CCI); 176 | Assert.AreEqual(6.5509, lista[21].CCI); 177 | Assert.AreEqual(33.3027, lista[22].CCI); 178 | Assert.AreEqual(34.9483, lista[23].CCI); 179 | Assert.AreEqual(13.8329, lista[24].CCI); 180 | Assert.AreEqual(-10.7438, lista[25].CCI); 181 | Assert.AreEqual(-11.5765, lista[26].CCI); 182 | Assert.AreEqual(-29.3414, lista[27].CCI); 183 | Assert.AreEqual(-129.3564, lista[28].CCI); 184 | Assert.AreEqual(-73.0601, lista[29].CCI); 185 | 186 | } 187 | 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /IndicatorsBot.Test/IndicatorsBot.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /IndicatorsBot.Test/RSI.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using System; 3 | 4 | namespace IndicatorsBot.Test 5 | { 6 | [TestClass] 7 | public class RSI 8 | { 9 | readonly Core.Indicators.RSI lista = new Core.Indicators.RSI(); 10 | 11 | [TestInitialize] 12 | public void Initialize() 13 | { 14 | lista.Add(DateTime.Parse("2009/12/14"), (decimal)44.33890000); 15 | lista.Add(DateTime.Parse("2009/12/15"), (decimal)44.09020000); 16 | lista.Add(DateTime.Parse("2009/12/16"), (decimal)44.14970000); 17 | lista.Add(DateTime.Parse("2009/12/17"), (decimal)43.61240000); 18 | lista.Add(DateTime.Parse("2009/12/18"), (decimal)44.32780000); 19 | lista.Add(DateTime.Parse("2009/12/21"), (decimal)44.82640000); 20 | lista.Add(DateTime.Parse("2009/12/22"), (decimal)45.09550000); 21 | lista.Add(DateTime.Parse("2009/12/23"), (decimal)45.42450000); 22 | lista.Add(DateTime.Parse("2009/12/24"), (decimal)45.84330000); 23 | lista.Add(DateTime.Parse("2009/12/28"), (decimal)46.08260000); 24 | lista.Add(DateTime.Parse("2009/12/29"), (decimal)45.89310000); 25 | lista.Add(DateTime.Parse("2009/12/30"), (decimal)46.03280000); 26 | lista.Add(DateTime.Parse("2009/12/31"), (decimal)45.61400000); 27 | lista.Add(DateTime.Parse("2010/01/04"), (decimal)46.28200000); 28 | lista.Add(DateTime.Parse("2010/01/05"), (decimal)46.28200000); 29 | lista.Add(DateTime.Parse("2010/01/06"), (decimal)46.00280000); 30 | lista.Add(DateTime.Parse("2010/01/07"), (decimal)46.03280000); 31 | lista.Add(DateTime.Parse("2010/01/08"), (decimal)46.41160000); 32 | lista.Add(DateTime.Parse("2010/01/11"), (decimal)46.22220000); 33 | lista.Add(DateTime.Parse("2010/01/12"), (decimal)45.64390000); 34 | lista.Add(DateTime.Parse("2010/01/13"), (decimal)46.21220000); 35 | lista.Add(DateTime.Parse("2010/01/14"), (decimal)46.25210000); 36 | lista.Add(DateTime.Parse("2010/01/15"), (decimal)45.71370000); 37 | lista.Add(DateTime.Parse("2010/01/19"), (decimal)46.45150000); 38 | lista.Add(DateTime.Parse("2010/01/20"), (decimal)45.78350000); 39 | lista.Add(DateTime.Parse("2010/01/21"), (decimal)45.35480000); 40 | lista.Add(DateTime.Parse("2010/01/22"), (decimal)44.02880000); 41 | lista.Add(DateTime.Parse("2010/01/25"), (decimal)44.17830000); 42 | lista.Add(DateTime.Parse("2010/01/26"), (decimal)44.21810000); 43 | lista.Add(DateTime.Parse("2010/01/27"), (decimal)44.56720000); 44 | lista.Add(DateTime.Parse("2010/01/28"), (decimal)43.42050000); 45 | lista.Add(DateTime.Parse("2010/01/29"), (decimal)42.66280000); 46 | lista.Add(DateTime.Parse("2010/02/01"), (decimal)43.13140000); 47 | lista.Add(DateTime.Parse("2010/02/02"), (decimal)25); 48 | } 49 | 50 | [TestMethod] 51 | public void Test_That_Change_Is_Equals_To_Current_Minus_Last() 52 | { 53 | Assert.AreEqual(0, lista[0].Change); 54 | Assert.AreEqual((decimal)-0.24870000, lista[1].Change); 55 | Assert.AreEqual((decimal)0.05950000, lista[2].Change); 56 | Assert.AreEqual((decimal)-0.53730000, lista[3].Change); 57 | Assert.AreEqual((decimal)0.71540000, lista[4].Change); 58 | Assert.AreEqual((decimal)0.49860000, lista[5].Change); 59 | Assert.AreEqual((decimal)0.26910000, lista[6].Change); 60 | Assert.AreEqual((decimal)0.32900000, lista[7].Change); 61 | Assert.AreEqual((decimal)0.41880000, lista[8].Change); 62 | Assert.AreEqual((decimal)0.23930000, lista[9].Change); 63 | Assert.AreEqual((decimal)-0.18950000, lista[10].Change); 64 | Assert.AreEqual((decimal)0.13970000, lista[11].Change); 65 | Assert.AreEqual((decimal)-0.41880000, lista[12].Change); 66 | Assert.AreEqual((decimal)0.66800000, lista[13].Change); 67 | Assert.AreEqual((decimal)0, lista[14].Change); 68 | Assert.AreEqual((decimal)-0.27920000, lista[15].Change); 69 | Assert.AreEqual((decimal)0.03000000, lista[16].Change); 70 | Assert.AreEqual((decimal)0.37880000, lista[17].Change); 71 | Assert.AreEqual((decimal)-0.18940000, lista[18].Change); 72 | Assert.AreEqual((decimal)-0.57830000, lista[19].Change); 73 | Assert.AreEqual((decimal)0.56830000, lista[20].Change); 74 | Assert.AreEqual((decimal)0.03990000, lista[21].Change); 75 | Assert.AreEqual((decimal)-0.53840000, lista[22].Change); 76 | Assert.AreEqual((decimal)0.73780000, lista[23].Change); 77 | Assert.AreEqual((decimal)-0.66800000, lista[24].Change); 78 | Assert.AreEqual((decimal)-0.42870000, lista[25].Change); 79 | Assert.AreEqual((decimal)-1.32600000, lista[26].Change); 80 | Assert.AreEqual((decimal)0.14950000, lista[27].Change); 81 | Assert.AreEqual((decimal)0.03980000, lista[28].Change); 82 | Assert.AreEqual((decimal)0.34910000, lista[29].Change); 83 | Assert.AreEqual((decimal)-1.14670000, lista[30].Change); 84 | Assert.AreEqual((decimal)-0.75770000, lista[31].Change); 85 | Assert.AreEqual((decimal)0.46860000, lista[32].Change); 86 | } 87 | 88 | [TestMethod] 89 | public void Test_That_Gain_Is_Correct() 90 | { 91 | Assert.AreEqual(0, lista[0].Gain); 92 | Assert.AreEqual(0, lista[1].Gain); 93 | Assert.AreEqual((decimal)0.05950000, lista[2].Gain); 94 | Assert.AreEqual(0, lista[3].Gain); 95 | Assert.AreEqual((decimal)0.71540000, lista[4].Gain); 96 | Assert.AreEqual((decimal)0.49860000, lista[5].Gain); 97 | Assert.AreEqual((decimal)0.26910000, lista[6].Gain); 98 | Assert.AreEqual((decimal)0.32900000, lista[7].Gain); 99 | Assert.AreEqual((decimal)0.41880000, lista[8].Gain); 100 | Assert.AreEqual((decimal)0.23930000, lista[9].Gain); 101 | Assert.AreEqual(0, lista[10].Gain); 102 | Assert.AreEqual((decimal)0.13970000, lista[11].Gain); 103 | Assert.AreEqual(0, lista[12].Gain); 104 | Assert.AreEqual((decimal)0.66800000, lista[13].Gain); 105 | Assert.AreEqual(0, lista[14].Gain); 106 | Assert.AreEqual(0, lista[15].Gain); 107 | Assert.AreEqual((decimal)0.03000000, lista[16].Gain); 108 | Assert.AreEqual((decimal)0.37880000, lista[17].Gain); 109 | Assert.AreEqual(0, lista[18].Gain); 110 | Assert.AreEqual(0, lista[19].Gain); 111 | Assert.AreEqual((decimal)0.56830000, lista[20].Gain); 112 | Assert.AreEqual((decimal)0.03990000, lista[21].Gain); 113 | Assert.AreEqual(0, lista[22].Gain); 114 | Assert.AreEqual((decimal)0.73780000, lista[23].Gain); 115 | Assert.AreEqual(0, lista[24].Gain); 116 | Assert.AreEqual(0, lista[25].Gain); 117 | Assert.AreEqual(0, lista[26].Gain); 118 | Assert.AreEqual((decimal)0.14950000, lista[27].Gain); 119 | Assert.AreEqual((decimal)0.03980000, lista[28].Gain); 120 | Assert.AreEqual((decimal)0.34910000, lista[29].Gain); 121 | Assert.AreEqual(0, lista[30].Gain); 122 | Assert.AreEqual(0, lista[31].Gain); 123 | Assert.AreEqual((decimal)0.46860000, lista[32].Gain); 124 | } 125 | 126 | [TestMethod] 127 | public void Test_That_Loss_Is_Correct() 128 | { 129 | Assert.AreEqual(0, lista[0].Loss); 130 | Assert.AreEqual((decimal)0.24870000, lista[1].Loss); 131 | Assert.AreEqual(0, lista[2].Loss); 132 | Assert.AreEqual((decimal)0.53730000, lista[3].Loss); 133 | Assert.AreEqual(0, lista[4].Loss); 134 | Assert.AreEqual(0, lista[5].Loss); 135 | Assert.AreEqual(0, lista[6].Loss); 136 | Assert.AreEqual(0, lista[7].Loss); 137 | Assert.AreEqual(0, lista[8].Loss); 138 | Assert.AreEqual(0, lista[9].Loss); 139 | Assert.AreEqual((decimal)0.18950000, lista[10].Loss); 140 | Assert.AreEqual(0, lista[11].Loss); 141 | Assert.AreEqual((decimal)0.41880000, lista[12].Loss); 142 | Assert.AreEqual(0, lista[13].Loss); 143 | Assert.AreEqual(0, lista[14].Loss); 144 | Assert.AreEqual((decimal)0.27920000, lista[15].Loss); 145 | Assert.AreEqual(0, lista[16].Loss); 146 | Assert.AreEqual(0, lista[17].Loss); 147 | Assert.AreEqual((decimal)0.18940000, lista[18].Loss); 148 | Assert.AreEqual((decimal)0.57830000, lista[19].Loss); 149 | Assert.AreEqual(0, lista[20].Loss); 150 | Assert.AreEqual(0, lista[21].Loss); 151 | Assert.AreEqual((decimal)0.53840000, lista[22].Loss); 152 | Assert.AreEqual(0, lista[23].Loss); 153 | Assert.AreEqual((decimal)0.66800000, lista[24].Loss); 154 | Assert.AreEqual((decimal)0.42870000, lista[25].Loss); 155 | Assert.AreEqual((decimal)1.32600000, lista[26].Loss); 156 | Assert.AreEqual(0, lista[27].Loss); 157 | Assert.AreEqual(0, lista[28].Loss); 158 | Assert.AreEqual(0, lista[29].Loss); 159 | Assert.AreEqual((decimal)1.14670000, lista[30].Loss); 160 | Assert.AreEqual((decimal)0.75770000, lista[31].Loss); 161 | Assert.AreEqual(0, lista[32].Loss); 162 | } 163 | 164 | [TestMethod] 165 | public void Test_That_AverageGain_Is_Correct() 166 | { 167 | Assert.AreEqual(0, lista[0].AverageGain); 168 | Assert.AreEqual(0, lista[1].AverageGain); 169 | Assert.AreEqual(0, lista[2].AverageGain); 170 | Assert.AreEqual(0, lista[3].AverageGain); 171 | Assert.AreEqual(0, lista[4].AverageGain); 172 | Assert.AreEqual(0, lista[5].AverageGain); 173 | Assert.AreEqual(0, lista[6].AverageGain); 174 | Assert.AreEqual(0, lista[7].AverageGain); 175 | Assert.AreEqual(0, lista[8].AverageGain); 176 | Assert.AreEqual(0, lista[9].AverageGain); 177 | Assert.AreEqual(0, lista[10].AverageGain); 178 | Assert.AreEqual(0, lista[11].AverageGain); 179 | Assert.AreEqual(0, lista[12].AverageGain); 180 | Assert.AreEqual(0, lista[13].AverageGain); 181 | Assert.AreEqual((decimal)0.23838571, Math.Round(lista[14].AverageGain, 8)); 182 | Assert.AreEqual((decimal)0.22135816, Math.Round(lista[15].AverageGain, 8)); 183 | Assert.AreEqual((decimal)0.20768972, Math.Round(lista[16].AverageGain, 8)); 184 | Assert.AreEqual((decimal)0.21991189, Math.Round(lista[17].AverageGain, 8)); 185 | Assert.AreEqual((decimal)0.20420389, Math.Round(lista[18].AverageGain, 8)); 186 | Assert.AreEqual((decimal)0.18961790, Math.Round(lista[19].AverageGain, 8)); 187 | Assert.AreEqual((decimal)0.21666662, Math.Round(lista[20].AverageGain, 8)); 188 | Assert.AreEqual((decimal)0.20404044, Math.Round(lista[21].AverageGain, 8)); 189 | Assert.AreEqual((decimal)0.18946612, Math.Round(lista[22].AverageGain, 8)); 190 | Assert.AreEqual((decimal)0.22863282, Math.Round(lista[23].AverageGain, 8)); 191 | Assert.AreEqual((decimal)0.21230191, Math.Round(lista[24].AverageGain, 8)); 192 | Assert.AreEqual((decimal)0.19713749, Math.Round(lista[25].AverageGain, 8)); 193 | Assert.AreEqual((decimal)0.18305624, Math.Round(lista[26].AverageGain, 8)); 194 | Assert.AreEqual((decimal)0.18065936, Math.Round(lista[27].AverageGain, 8)); 195 | Assert.AreEqual((decimal)0.17059798, Math.Round(lista[28].AverageGain, 8)); 196 | Assert.AreEqual((decimal)0.18334812, Math.Round(lista[29].AverageGain, 8)); 197 | Assert.AreEqual((decimal)0.17025183, Math.Round(lista[30].AverageGain, 8)); 198 | Assert.AreEqual((decimal)0.15809098, Math.Round(lista[31].AverageGain, 8)); 199 | Assert.AreEqual((decimal)0.18027020, Math.Round(lista[32].AverageGain, 8)); 200 | } 201 | 202 | [TestMethod] 203 | public void Test_That_AverageLoss_Is_Correct() 204 | { 205 | Assert.AreEqual(0, lista[0].AverageLoss); 206 | Assert.AreEqual(0, lista[1].AverageLoss); 207 | Assert.AreEqual(0, lista[2].AverageLoss); 208 | Assert.AreEqual(0, lista[3].AverageLoss); 209 | Assert.AreEqual(0, lista[4].AverageLoss); 210 | Assert.AreEqual(0, lista[5].AverageLoss); 211 | Assert.AreEqual(0, lista[6].AverageLoss); 212 | Assert.AreEqual(0, lista[7].AverageLoss); 213 | Assert.AreEqual(0, lista[8].AverageLoss); 214 | Assert.AreEqual(0, lista[9].AverageLoss); 215 | Assert.AreEqual(0, lista[10].AverageLoss); 216 | Assert.AreEqual(0, lista[11].AverageLoss); 217 | Assert.AreEqual(0, lista[12].AverageLoss); 218 | Assert.AreEqual(0, lista[13].AverageLoss); 219 | Assert.AreEqual((decimal)0.09959286, Math.Round(lista[14].AverageLoss, 8)); 220 | Assert.AreEqual((decimal)0.11242194, Math.Round(lista[15].AverageLoss, 8)); 221 | Assert.AreEqual((decimal)0.10439180, Math.Round(lista[16].AverageLoss, 8)); 222 | Assert.AreEqual((decimal)0.09693524, Math.Round(lista[17].AverageLoss, 8)); 223 | Assert.AreEqual((decimal)0.10353987, Math.Round(lista[18].AverageLoss, 8)); 224 | Assert.AreEqual((decimal)0.13745131, Math.Round(lista[19].AverageLoss, 8)); 225 | Assert.AreEqual((decimal)0.12763336, Math.Round(lista[20].AverageLoss, 8)); 226 | Assert.AreEqual((decimal)0.11851669, Math.Round(lista[21].AverageLoss, 8)); 227 | Assert.AreEqual((decimal)0.14850835, Math.Round(lista[22].AverageLoss, 8)); 228 | Assert.AreEqual((decimal)0.13790061, Math.Round(lista[23].AverageLoss, 8)); 229 | Assert.AreEqual((decimal)0.17576486, Math.Round(lista[24].AverageLoss, 8)); 230 | Assert.AreEqual((decimal)0.19383165, Math.Round(lista[25].AverageLoss, 8)); 231 | Assert.AreEqual((decimal)0.27470082, Math.Round(lista[26].AverageLoss, 8)); 232 | Assert.AreEqual((decimal)0.25507933, Math.Round(lista[27].AverageLoss, 8)); 233 | Assert.AreEqual((decimal)0.23685938, Math.Round(lista[28].AverageLoss, 8)); 234 | Assert.AreEqual((decimal)0.21994085, Math.Round(lista[29].AverageLoss, 8)); 235 | Assert.AreEqual((decimal)0.28613793, Math.Round(lista[30].AverageLoss, 8)); 236 | Assert.AreEqual((decimal)0.31982094, Math.Round(lista[31].AverageLoss, 8)); 237 | Assert.AreEqual((decimal)0.29697659, Math.Round(lista[32].AverageLoss, 8)); 238 | } 239 | 240 | [TestMethod] 241 | public void Test_That_RS_Is_Correct() 242 | { 243 | Assert.AreEqual(0, lista[0].RS); 244 | Assert.AreEqual(0, lista[1].RS); 245 | Assert.AreEqual(0, lista[2].RS); 246 | Assert.AreEqual(0, lista[3].RS); 247 | Assert.AreEqual(0, lista[4].RS); 248 | Assert.AreEqual(0, lista[5].RS); 249 | Assert.AreEqual(0, lista[6].RS); 250 | Assert.AreEqual(0, lista[7].RS); 251 | Assert.AreEqual(0, lista[8].RS); 252 | Assert.AreEqual(0, lista[9].RS); 253 | Assert.AreEqual(0, lista[10].RS); 254 | Assert.AreEqual(0, lista[11].RS); 255 | Assert.AreEqual(0, lista[12].RS); 256 | Assert.AreEqual(0, lista[13].RS); 257 | Assert.AreEqual(2.39, lista[14].RS); 258 | Assert.AreEqual(1.97, lista[15].RS); 259 | Assert.AreEqual(1.99, lista[16].RS); 260 | Assert.AreEqual(2.27, lista[17].RS); 261 | Assert.AreEqual(1.97, lista[18].RS); 262 | Assert.AreEqual(1.38, lista[19].RS); 263 | Assert.AreEqual(1.70, lista[20].RS); 264 | Assert.AreEqual(1.72, lista[21].RS); 265 | Assert.AreEqual(1.28, lista[22].RS); 266 | Assert.AreEqual(1.66, lista[23].RS); 267 | Assert.AreEqual(1.21, lista[24].RS); 268 | Assert.AreEqual(1.02, lista[25].RS); 269 | Assert.AreEqual(0.67, lista[26].RS); 270 | Assert.AreEqual(0.71, lista[27].RS); 271 | Assert.AreEqual(0.72, lista[28].RS); 272 | Assert.AreEqual(0.83, lista[29].RS); 273 | Assert.AreEqual(0.59, lista[30].RS); 274 | Assert.AreEqual(0.49, lista[31].RS); 275 | Assert.AreEqual(0.61, lista[32].RS); 276 | } 277 | 278 | [TestMethod] 279 | public void Test_That_RSI_Is_Correct() 280 | { 281 | Assert.AreEqual(0, lista[0].RSI); 282 | Assert.AreEqual(0, lista[1].RSI); 283 | Assert.AreEqual(0, lista[2].RSI); 284 | Assert.AreEqual(0, lista[3].RSI); 285 | Assert.AreEqual(0, lista[4].RSI); 286 | Assert.AreEqual(0, lista[5].RSI); 287 | Assert.AreEqual(0, lista[6].RSI); 288 | Assert.AreEqual(0, lista[7].RSI); 289 | Assert.AreEqual(0, lista[8].RSI); 290 | Assert.AreEqual(0, lista[9].RSI); 291 | Assert.AreEqual(0, lista[10].RSI); 292 | Assert.AreEqual(0, lista[11].RSI); 293 | Assert.AreEqual(0, lista[12].RSI); 294 | Assert.AreEqual(0, lista[13].RSI); 295 | Assert.AreEqual(70.53, lista[14].RSI); 296 | Assert.AreEqual(66.32, lista[15].RSI); 297 | Assert.AreEqual(66.55, lista[16].RSI); 298 | Assert.AreEqual(69.41, lista[17].RSI); 299 | Assert.AreEqual(66.36, lista[18].RSI); 300 | Assert.AreEqual(57.97, lista[19].RSI); 301 | Assert.AreEqual(62.93, lista[20].RSI); 302 | Assert.AreEqual(63.26, lista[21].RSI); 303 | Assert.AreEqual(56.06, lista[22].RSI); 304 | Assert.AreEqual(62.38, lista[23].RSI); 305 | Assert.AreEqual(54.71, lista[24].RSI); 306 | Assert.AreEqual(50.42, lista[25].RSI); 307 | Assert.AreEqual(39.99, lista[26].RSI); 308 | Assert.AreEqual(41.46, lista[27].RSI); 309 | Assert.AreEqual(41.87, lista[28].RSI); 310 | Assert.AreEqual(45.46, lista[29].RSI); 311 | Assert.AreEqual(37.30, lista[30].RSI); 312 | Assert.AreEqual(33.08, lista[31].RSI); 313 | Assert.AreEqual(37.77, lista[32].RSI); 314 | } 315 | 316 | [TestMethod] 317 | public void Test_That_Uptrend_Is_Correct() 318 | { 319 | Assert.AreEqual(false, lista[0].UpTrend); 320 | Assert.AreEqual(false, lista[1].UpTrend); 321 | Assert.AreEqual(false, lista[2].UpTrend); 322 | Assert.AreEqual(false, lista[3].UpTrend); 323 | Assert.AreEqual(false, lista[4].UpTrend); 324 | Assert.AreEqual(false, lista[5].UpTrend); 325 | Assert.AreEqual(false, lista[6].UpTrend); 326 | Assert.AreEqual(false, lista[7].UpTrend); 327 | Assert.AreEqual(false, lista[8].UpTrend); 328 | Assert.AreEqual(false, lista[9].UpTrend); 329 | Assert.AreEqual(false, lista[10].UpTrend); 330 | Assert.AreEqual(false, lista[11].UpTrend); 331 | Assert.AreEqual(false, lista[12].UpTrend); 332 | Assert.AreEqual(false, lista[13].UpTrend); 333 | Assert.AreEqual(false, lista[14].UpTrend); 334 | Assert.AreEqual(true, lista[15].UpTrend); 335 | Assert.AreEqual(true, lista[16].UpTrend); 336 | Assert.AreEqual(true, lista[17].UpTrend); 337 | Assert.AreEqual(true, lista[18].UpTrend); 338 | Assert.AreEqual(true, lista[19].UpTrend); 339 | Assert.AreEqual(true, lista[20].UpTrend); 340 | Assert.AreEqual(true, lista[21].UpTrend); 341 | Assert.AreEqual(true, lista[22].UpTrend); 342 | Assert.AreEqual(true, lista[23].UpTrend); 343 | Assert.AreEqual(true, lista[24].UpTrend); 344 | Assert.AreEqual(true, lista[25].UpTrend); 345 | Assert.AreEqual(true, lista[26].UpTrend); 346 | Assert.AreEqual(true, lista[27].UpTrend); 347 | Assert.AreEqual(true, lista[28].UpTrend); 348 | Assert.AreEqual(false, lista[29].UpTrend); 349 | Assert.AreEqual(false, lista[30].UpTrend); 350 | Assert.AreEqual(false, lista[31].UpTrend); 351 | Assert.AreEqual(false, lista[32].UpTrend); 352 | } 353 | 354 | [TestMethod] 355 | public void Test_That_StochasticRSI_Is_Correct() 356 | { 357 | Assert.AreEqual(0, lista[0].StochRSI); 358 | Assert.AreEqual(0, lista[1].StochRSI); 359 | Assert.AreEqual(0, lista[2].StochRSI); 360 | Assert.AreEqual(0, lista[3].StochRSI); 361 | Assert.AreEqual(0, lista[4].StochRSI); 362 | Assert.AreEqual(0, lista[5].StochRSI); 363 | Assert.AreEqual(0, lista[6].StochRSI); 364 | Assert.AreEqual(0, lista[7].StochRSI); 365 | Assert.AreEqual(0, lista[8].StochRSI); 366 | Assert.AreEqual(0, lista[9].StochRSI); 367 | Assert.AreEqual(0, lista[10].StochRSI); 368 | Assert.AreEqual(0, lista[11].StochRSI); 369 | Assert.AreEqual(0, lista[12].StochRSI); 370 | Assert.AreEqual(0, lista[13].StochRSI); 371 | Assert.AreEqual(0, lista[14].StochRSI); 372 | Assert.AreEqual(0, lista[15].StochRSI); 373 | Assert.AreEqual(0, lista[16].StochRSI); 374 | Assert.AreEqual(0, lista[17].StochRSI); 375 | Assert.AreEqual(0, lista[18].StochRSI); 376 | Assert.AreEqual(0, lista[19].StochRSI); 377 | Assert.AreEqual(0, lista[20].StochRSI); 378 | Assert.AreEqual(0, lista[21].StochRSI); 379 | Assert.AreEqual(0, lista[22].StochRSI); 380 | Assert.AreEqual(0, lista[23].StochRSI); 381 | Assert.AreEqual(0, lista[24].StochRSI); 382 | Assert.AreEqual(0, lista[25].StochRSI); 383 | Assert.AreEqual(0, lista[26].StochRSI); 384 | Assert.AreEqual(0.05, lista[27].StochRSI); 385 | Assert.AreEqual(0.06, lista[28].StochRSI); 386 | Assert.AreEqual(0.19, lista[29].StochRSI); 387 | Assert.AreEqual(0.00, lista[30].StochRSI); 388 | Assert.AreEqual(0.00, lista[31].StochRSI); 389 | Assert.AreEqual(0.16, lista[32].StochRSI); 390 | } 391 | } 392 | } 393 | -------------------------------------------------------------------------------- /IndicatorsBot.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2006 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IndicatorsBot.ConsoleApp", "IndicatorsBot\IndicatorsBot.ConsoleApp.csproj", "{411297EE-D26F-4504-A224-B776B92D9ABD}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IndicatorsBot.Test", "IndicatorsBot.Test\IndicatorsBot.Test.csproj", "{DDA63203-F350-4B8E-80FA-3E8DD6D043AA}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndicatorsBot.Core", "IndicatorsBot.Core\IndicatorsBot.Core.csproj", "{0D463602-997D-424F-89EA-8B732E0BC4B8}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {411297EE-D26F-4504-A224-B776B92D9ABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {411297EE-D26F-4504-A224-B776B92D9ABD}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {411297EE-D26F-4504-A224-B776B92D9ABD}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {411297EE-D26F-4504-A224-B776B92D9ABD}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {DDA63203-F350-4B8E-80FA-3E8DD6D043AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {DDA63203-F350-4B8E-80FA-3E8DD6D043AA}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {DDA63203-F350-4B8E-80FA-3E8DD6D043AA}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {DDA63203-F350-4B8E-80FA-3E8DD6D043AA}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {0D463602-997D-424F-89EA-8B732E0BC4B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {0D463602-997D-424F-89EA-8B732E0BC4B8}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {0D463602-997D-424F-89EA-8B732E0BC4B8}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {0D463602-997D-424F-89EA-8B732E0BC4B8}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {24C98747-640F-4444-B130-C210EEC09A0B} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /IndicatorsBot/IndicatorsBot.ConsoleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /IndicatorsBot/Program.cs: -------------------------------------------------------------------------------- 1 | using IndicatorsBot.Core; 2 | using IndicatorsBot.Core.Indicators; 3 | using IndicatorsBot.Core.Model; 4 | using System; 5 | using System.Threading.Tasks; 6 | 7 | namespace IndicatorsBot.ConsoleApp 8 | { 9 | class Program 10 | { 11 | static bool enabled = true; 12 | 13 | static void Main(string[] args) 14 | { 15 | Console.ForegroundColor = ConsoleColor.Gray; //Console.ResetColor() is not working :( 16 | Console.CancelKeyPress += Console_CancelKeyPress; 17 | 18 | var ticker = string.Empty; 19 | string indicator = string.Empty; 20 | 21 | HandleArgs(args, ref ticker, ref indicator); 22 | 23 | Console.WriteLine($"Fetching trade data for {ticker.ToUpper()}..."); 24 | 25 | //on the next version, it's gonna be an interface 26 | RSI RSITrades = null; 27 | CCI CCITrades = null; 28 | BollingerBands BBandTrades = null; 29 | 30 | var bfxReader = new Core.Exchanges.Bitfinex.TickerReader(); 31 | 32 | TickerHandler tickerHndl = null; 33 | 34 | //getting the 14 last minutes history 35 | var hist = new Core.Exchanges.Bitfinex.TickerCandlesReader(); 36 | 37 | if (indicator.ToUpper() == "RSI") 38 | { 39 | RSICalc(out RSITrades, bfxReader, out tickerHndl, hist); 40 | } 41 | else if (indicator.ToUpper() == "CCI") 42 | { 43 | CCICalc(out CCITrades, bfxReader, out tickerHndl, hist); 44 | } 45 | else if (indicator.ToUpper() == "BBANDS") 46 | { 47 | BBandCalc(out BBandTrades, bfxReader, out tickerHndl, hist); 48 | } else 49 | { 50 | Console.WriteLine("Invalid Parameter"); 51 | return; 52 | } 53 | 54 | tickerHndl.OnError += tickerHndl_OnError; 55 | 56 | bfxReader.Enabled = true; 57 | Task.Run(async () => 58 | { 59 | await bfxReader.Start(ticker.ToUpper()); 60 | }); 61 | 62 | while (enabled) ; 63 | 64 | Console.ForegroundColor = ConsoleColor.Gray; 65 | Console.WriteLine($"Program ended."); 66 | } 67 | 68 | private static void HandleArgs(string[] args, ref string ticker, ref string indicator) 69 | { 70 | if (args.Length > 0) 71 | { 72 | ticker = args[0]; 73 | 74 | if (args.Length > 1) indicator = args[1]; 75 | 76 | } 77 | else 78 | { 79 | while (ticker == string.Empty) 80 | { 81 | Console.WriteLine("Type in the ticker name: (hit ENTER for BTCUSD)"); 82 | ticker = Console.ReadLine(); 83 | if (string.IsNullOrEmpty(ticker)) ticker = "BTCUSD"; 84 | } 85 | } 86 | 87 | while (indicator == string.Empty) 88 | { 89 | Console.WriteLine("Type in the indicator name (RSI, CCI, BBands) to start calculation: (hit ENTER for RSI)"); 90 | indicator = Console.ReadLine(); 91 | if (string.IsNullOrEmpty(indicator)) indicator = "RSI"; 92 | } 93 | } 94 | 95 | private static void BBandCalc(out BollingerBands BBandTrades, Core.Exchanges.Bitfinex.TickerReader bfxReader, out TickerHandler tickerHndl, Core.Exchanges.Bitfinex.TickerCandlesReader hist) 96 | { 97 | BBandTrades = new BollingerBands(); 98 | tickerHndl = new TickerHandler(bfxReader, BBandTrades); 99 | tickerHndl.BBandReady += tickerHndl_BBand_IndicatorReady; 100 | 101 | var lista = hist.GetHistory("BTCUSD", Core.Exchanges.Bitfinex.Consts.CandleInterval1Min, 22); 102 | foreach (Ticker t in lista) 103 | { 104 | BBandTrades.Add(t.UtcDateTime, t.last_price); 105 | } 106 | } 107 | 108 | private static void CCICalc(out CCI CCITrades, Core.Exchanges.Bitfinex.TickerReader bfxReader, out TickerHandler tickerHndl, Core.Exchanges.Bitfinex.TickerCandlesReader hist) 109 | { 110 | CCITrades = new CCI(); 111 | tickerHndl = new TickerHandler(bfxReader, CCITrades); 112 | tickerHndl.CCIReady += tickerHndl_CCI_IndicatorReady; 113 | 114 | var lista = hist.GetHistory("BTCUSD", Core.Exchanges.Bitfinex.Consts.CandleInterval1Min, 22); 115 | foreach (Ticker t in lista) 116 | { 117 | CCITrades.Add(t.UtcDateTime, t.high, t.low, t.last_price); 118 | } 119 | } 120 | 121 | private static void RSICalc(out RSI RSITrades, Core.Exchanges.Bitfinex.TickerReader bfxReader, out TickerHandler tickerHndl, Core.Exchanges.Bitfinex.TickerCandlesReader hist) 122 | { 123 | RSITrades = new RSI(); 124 | tickerHndl = new TickerHandler(bfxReader, RSITrades); 125 | tickerHndl.RSIReady += tickerHndl_RSI_IndicatorReady; 126 | 127 | var lista = hist.GetHistory("BTCUSD", Core.Exchanges.Bitfinex.Consts.CandleInterval1Min, 28); 128 | foreach (Ticker t in lista) 129 | { 130 | RSITrades.Add(t.UtcDateTime, t.last_price); 131 | } 132 | } 133 | 134 | private static void tickerHndl_OnError(object sender, string e) 135 | { 136 | Console.WriteLine($"Error: {e}"); 137 | } 138 | 139 | private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) 140 | { 141 | enabled = false; 142 | Console.ForegroundColor = ConsoleColor.Gray; 143 | Console.WriteLine($"Finishing..."); 144 | } 145 | 146 | private static void tickerHndl_RSI_IndicatorReady(object sender, RSISignal e) 147 | { 148 | Console.ForegroundColor = ConsoleColor.Gray; 149 | 150 | if (!e.UpTrend && (e.RSI <= 70)) 151 | { 152 | //bearishing 153 | Console.ForegroundColor = ConsoleColor.Red; 154 | } 155 | 156 | if (e.UpTrend && (e.RSI >= 30)) 157 | { 158 | //bullishing 159 | Console.ForegroundColor = ConsoleColor.Green; 160 | } 161 | 162 | Console.WriteLine($"{e.CloseDate.ToString("HH:mm:ss")} Last Trade: {e.ClosePrice} - RSI: {e.RSI} - Stochastich RSI: {e.StochRSI}"); 163 | } 164 | 165 | private static void tickerHndl_CCI_IndicatorReady(object sender, CCISignal e) 166 | { 167 | Console.ForegroundColor = ConsoleColor.Gray; 168 | 169 | if (!e.UpTrend && (e.CCI <= -100)) 170 | { 171 | //bearishing 172 | Console.ForegroundColor = ConsoleColor.Red; 173 | } 174 | 175 | if (e.UpTrend && (e.CCI >= 100)) 176 | { 177 | //bullishing 178 | Console.ForegroundColor = ConsoleColor.Green; 179 | } 180 | 181 | Console.WriteLine($"{e.CloseDate.ToString("HH:mm:ss")} Last Trade: {e.ClosePrice} - CCI: {e.CCI}"); 182 | } 183 | 184 | private static void tickerHndl_BBand_IndicatorReady(object sender, BBandSignal e) 185 | { 186 | Console.ForegroundColor = ConsoleColor.Gray; 187 | 188 | if (!e.UpTrend && (e.Position <= (decimal)0.8)) 189 | { 190 | //bearishing 191 | Console.ForegroundColor = ConsoleColor.Red; 192 | } 193 | 194 | if (e.UpTrend && (e.Position >= (decimal)0.2)) 195 | { 196 | //bullishing 197 | Console.ForegroundColor = ConsoleColor.Green; 198 | } 199 | 200 | Console.WriteLine($"{e.CloseDate.ToString("HH:mm:ss")} Last Trade: {e.Price} - Upper Band: {e.UpperBandSMA} - Middle Band: {e.SMA} - Lower Band: {e.LowerBandSMA} - Bandwidth: {e.BandWidth} - Position: {e.Position}"); 201 | } 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Michael Costa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IndicatorsBot 2 | A .Net Core project to automatize the calculation or some trading indicators, like (RSI, CCI, Moving Averages and etc.). 3 | 4 | On the console app, it checks for cryptocurrency trades 5 | 6 | Usage: On a command shell, type in: 7 | dotnet IndicatorsBot.ConsoleApp.dll [Ticker] 8 | 9 | 10 | Version 0.1 - Reading RSI for the last 1 minute at Bitfinex. 11 | For reading 5, 15, 60 minutes and so on, you just need to create threads that get the last trade price whithin those intervals and add it to another respective IndicatorsBot.Core.Indicators.Trades list. 12 | 13 | Version 0.2 - Handling CCI calculations. Just need to implement its use on the program. 14 | 15 | Version 0.3 - Getting historical candles data, so it is not necessary to wait for X measures to get the first indicator ready. 16 | 17 | Version 0.4 - Calculating Stochastic RSI. 18 | 19 | Version 0.5 - Calculating Bollinger Bands. 20 | --------------------------------------------------------------------------------