To write trading robots, you can use the functionality of third-party C# libraries. Before using, copy the required dll to the folder ..\BotAssemblies\
The Math.NET Numerics library that has methods and algorithms for numerical computations in science, technology and everyday use was included in the distribution.
Topics covered include Special Functions, Linear Algebra, Probabilistic Models, Random Numbers, Interpolation, Integral Transforms, and more. For more information, visit the official website https://numerics.mathdotnet.com/
MathNet.Numerics
An example of using mathematical statistics functions:
usingSystem;usingTraderAPI;usingSystem.IO;usingSystem.Reflection;usingSystem.Runtime.InteropServices;usingSystem.Collections.Generic;usingMathNet.Numerics.Statistics;namespaceuAlgo.Bots{publicclassNewBot:Bot{//------------------------------------------------////------------------------------------------------privatevoidPrint(string f,string l){// get the path to the folder with our robotstring AssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)+ Path.DirectorySeparatorChar.ToString();// full path to the file for recording service information string mLog = AssemblyPath + f;using(StreamWriter sw =newStreamWriter(mLog,true))
sw.WriteLine(l);}//------------------------------------------------////------------------------------------------------publicvoidOnTick(){}publicvoidOnStart(){IEnumerable<double> data =newdouble[]{7,2,3,4,5};IEnumerable<double> data2 =newdouble[]{4,5,5,5,5};double minimum = data.Minimum();double maximum = data.Maximum();double mean = data.Mean();double sd = data.StandardDeviation();double median = data.Median();double gmean = data.GeometricMean();double covar = data.Covariance(data2);Print("result.txt","\nMean = "+ mean.ToString()+"\nMinimum = "+ minimum.ToString()+"\nMaximum = "+ maximum.ToString()+"\nSD = "+ sd.ToString()+"\nMedian = "+ median.ToString()+"\ngMean = "+ gmean.ToString()+"\nCovar = "+ covar.ToString());}publicvoidOnStop(){// Put your deinitialization logic here}}}
// Result:// Mean = 4.2// Minimumu = 2// Maximum = 7// SD = 1.92353840616713// Median = 4// gMean = 3ю844641568// Covar = -0.7