mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 16:41:19 +00:00
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
namespace StockSharp.Algo.Analytics;
|
|
|
|
/// <summary>
|
|
/// The analytic script, normalize securities close prices and shows on same chart.
|
|
/// </summary>
|
|
public class NormalizePriceScript : IAnalyticsScript
|
|
{
|
|
async Task IAnalyticsScript.Run(ILogReceiver logs, IAnalyticsPanel panel, SecurityId[] securities, DateTime from, DateTime to, IStorageRegistry storage, IMarketDataDrive drive, StorageFormats format, DataType dataType, CancellationToken cancellationToken)
|
|
{
|
|
if (securities.Length == 0)
|
|
{
|
|
logs.LogWarning("No instruments.");
|
|
return;
|
|
}
|
|
|
|
var chart = panel.CreateChart<DateTime, decimal>();
|
|
|
|
foreach (var security in securities)
|
|
{
|
|
// stop calculation if user cancel script execution
|
|
if (cancellationToken.IsCancellationRequested)
|
|
break;
|
|
|
|
var series = new Dictionary<DateTime, decimal>();
|
|
|
|
// get candle storage
|
|
var candleStorage = storage.GetCandleMessageStorage(security, dataType, drive, format);
|
|
|
|
decimal? firstClose = null;
|
|
|
|
await foreach (var candle in candleStorage.LoadAsync(from, to).WithCancellation(cancellationToken))
|
|
{
|
|
firstClose ??= candle.ClosePrice;
|
|
|
|
// normalize close prices by dividing on first close
|
|
series[candle.OpenTime] = candle.ClosePrice / firstClose.Value;
|
|
}
|
|
|
|
// draw series on chart
|
|
chart.Append(security.ToStringId(), series.Keys, series.Values);
|
|
}
|
|
}
|
|
} |