To calculate the script data, you can use a standard algorithm using the Perfomance class.
Below is an example of a script that calculates the main metrics and displays them in the log. To shorten the code, the trading algorithm itself is not given; instead, put any of your own or from the examples.
Add TSLab.ScriptEngine.dll to the External script block.
usingSystem.Text;usingTSLab.Script;usingTSLab.Script.Handlers;usingTSLab.Script.Helpers;usingTSLab.Script.Optimization;usingTSLab.ScriptEngine;namespaceMyLib{publicclassTestPerfomance:IExternalScript {publicvirtualvoidExecute(IContext ctx,ISecurity sec) { // Trading algorithm // .... // Statistics are calculated at the end of the script, after the trading algorithm. // Do not forget to add TSLab.ScriptEngine.dll to the External script blockvar list =new [] { (ISecurity2)sec };var perfomance =newPerfomance(list, ((IRuntime2)ctx.Runtime).InitDeposit);perfomance.UpdateDataFromRuntime(); // Loggingvar sb =newStringBuilder();sb.AppendLine($"AllTrades: {perfomance.AllTrades}");sb.AppendLine($"WinTrades: {perfomance.WinTrades}");sb.AppendLine($"LossTrades: {perfomance.LossTrades}");sb.AppendLine($"MaxDrawdown: {perfomance.MaxDrawdown}");sb.AppendLine($"MaxDrawdownPct: {perfomance.MaxDrawdownPct}");sb.AppendLine($"ProfitFactor: {perfomance.ProfitFactor}");sb.AppendLine($"RecoveryFactor: {perfomance.RecoveryFactor}");ctx.Log(sb.ToString(),MessageType.Info,true); }}