Refactoring DataStream
This commit is contained in:
@@ -32,8 +32,8 @@ uses
|
||||
System.UITypes,
|
||||
System.Types,
|
||||
Vcl.FileCtrl, // Added for SelectDirectory
|
||||
Myc.Trade.DataSeries, // For TTickData, FindOldestFilesPerSymbol, TryParseFileName [cite: 231, 237, 238]
|
||||
Myc.OHLCCache, // For TOHLC, IGenericCandleBuilder, TF_ constants
|
||||
Myc.Trade.DataPoint, Myc.Trade.DataStream,
|
||||
Myc.ChartDataController, // Uses the updated DataController
|
||||
Vcl.Buttons;
|
||||
|
||||
@@ -68,6 +68,7 @@ type
|
||||
procedure PaintBoxMouseLeave(Sender: TObject);
|
||||
procedure SymbolComboBoxChange(Sender: TObject); // Event handler for symbol selection change
|
||||
private
|
||||
FDataServer: IDataServer<TAskBidItem>;
|
||||
FActiveOHLCCache: TOHLC;
|
||||
FCandleWidthInPixels: Integer;
|
||||
FCandleSpacing: Integer;
|
||||
@@ -116,8 +117,8 @@ type
|
||||
FDescriptionText: string; // User-friendly description
|
||||
public
|
||||
constructor Create(ATickCount: Integer);
|
||||
function Init(const ADataSet: TArray<TAskBid.TTick>): Boolean;
|
||||
function IsNewBar(AIndex: Integer; const ATick: TAskBid.TTick): Boolean;
|
||||
function Init(const ADataSet: TArray<TDataRecord<TAskBidItem>>): Boolean;
|
||||
function IsNewBar(AIndex: Integer; const ATick: TDataRecord<TAskBidItem>): Boolean;
|
||||
function GetCaption: string; // Returns the Description for UI
|
||||
property Caption: string read GetCaption; // Interface property uses GetCaption
|
||||
end;
|
||||
@@ -129,8 +130,8 @@ type
|
||||
FDescriptionText: string; // User-friendly description
|
||||
public
|
||||
constructor Create(ATargetTickVolume: Integer);
|
||||
function Init(const ADataSet: TArray<TAskBid.TTick>): Boolean;
|
||||
function IsNewBar(AIndex: Integer; const ATick: TAskBid.TTick): Boolean;
|
||||
function Init(const ADataSet: TArray<TDataRecord<TAskBidItem>>): Boolean;
|
||||
function IsNewBar(AIndex: Integer; const ATick: TDataRecord<TAskBidItem>): Boolean;
|
||||
function GetCaption: string; // Returns the Description for UI
|
||||
property Caption: string read GetCaption; // Interface property uses GetCaption
|
||||
end;
|
||||
@@ -146,12 +147,12 @@ begin
|
||||
FDescriptionText := Format('Every %d Ticks', [FTickCountForNewBar]);
|
||||
end;
|
||||
|
||||
function TEveryNTicksBuilder.Init(const ADataSet: TArray<TAskBid.TTick>): Boolean;
|
||||
function TEveryNTicksBuilder.Init(const ADataSet: TArray<TDataRecord<TAskBidItem>>): Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TEveryNTicksBuilder.IsNewBar(AIndex: Integer; const ATick: TAskBid.TTick): Boolean;
|
||||
function TEveryNTicksBuilder.IsNewBar(AIndex: Integer; const ATick: TDataRecord<TAskBidItem>): Boolean;
|
||||
begin
|
||||
Result := (AIndex mod FTickCountForNewBar = 0);
|
||||
end;
|
||||
@@ -172,13 +173,13 @@ begin
|
||||
FCurrentTickInBarCount := 0;
|
||||
end;
|
||||
|
||||
function TVolumeAccumulationBuilder.Init(const ADataSet: TArray<TAskBid.TTick>): Boolean;
|
||||
function TVolumeAccumulationBuilder.Init(const ADataSet: TArray<TDataRecord<TAskBidItem>>): Boolean;
|
||||
begin
|
||||
FCurrentTickInBarCount := 0;
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TVolumeAccumulationBuilder.IsNewBar(AIndex: Integer; const ATick: TAskBid.TTick): Boolean;
|
||||
function TVolumeAccumulationBuilder.IsNewBar(AIndex: Integer; const ATick: TDataRecord<TAskBidItem>): Boolean;
|
||||
begin
|
||||
Inc(FCurrentTickInBarCount);
|
||||
if FCurrentTickInBarCount >= FTargetTickVolumePerBar then
|
||||
@@ -259,6 +260,8 @@ var
|
||||
BuilderNCaptionKey, BuilderVCaptionKey: string; // These will be the unique keys
|
||||
BuilderNDescription, BuilderVDescription: string;
|
||||
begin
|
||||
FDataServer := TAskBidServer.Create;
|
||||
|
||||
IsMemoryLow :=
|
||||
function: Boolean
|
||||
var
|
||||
@@ -284,7 +287,7 @@ begin
|
||||
FDragStartX := 0;
|
||||
FDragStartDisplayIndex := 0;
|
||||
|
||||
FDataController := TChartDataController.Create(Memo.Lines);
|
||||
FDataController := TChartDataController.Create(FDataServer, Memo.Lines);
|
||||
|
||||
// Create and register generic builders
|
||||
BuilderN := TEveryNTicksBuilder.Create(DefaultEveryNTicksCount);
|
||||
@@ -331,6 +334,9 @@ begin
|
||||
FreeAndNil(FDataController);
|
||||
FreeAndNil(FBufferBitmap);
|
||||
FActiveOHLCCache := nil;
|
||||
|
||||
FDataServer.ClearCache;
|
||||
FDataServer := nil;
|
||||
end;
|
||||
|
||||
procedure TChartForm.ClearAllCachesInForm;
|
||||
@@ -752,8 +758,8 @@ begin
|
||||
and (HoveredCandle.OriginalDataIndexEnd >= 0)
|
||||
and (HoveredCandle.OriginalDataIndexEnd < FDataController.GetTickDataLength) then // Use GetTickDataLength
|
||||
begin
|
||||
UTCTimeStart := FDataController.GetTickDataItem(HoveredCandle.OriginalDataIndexStart).OADateTime;
|
||||
UTCTimeEnd := FDataController.GetTickDataItem(HoveredCandle.OriginalDataIndexEnd).OADateTime;
|
||||
UTCTimeStart := FDataController.GetTickDataItem(HoveredCandle.OriginalDataIndexStart).TimeStamp;
|
||||
UTCTimeEnd := FDataController.GetTickDataItem(HoveredCandle.OriginalDataIndexEnd).TimeStamp;
|
||||
LocalTimeStart := TTimeZone.Local.ToLocalTime(UTCTimeStart);
|
||||
LocalTimeEnd := TTimeZone.Local.ToLocalTime(UTCTimeEnd);
|
||||
TimeZoneStr := TTimeZone.Local.GetAbbreviation(LocalTimeStart); // Get abbreviation for the local time zone
|
||||
@@ -1296,7 +1302,7 @@ begin
|
||||
if (CrosshairCandle.OriginalDataIndexStart >= 0)
|
||||
and (CrosshairCandle.OriginalDataIndexStart < FDataController.GetTickDataLength) then // Use GetTickDataLength
|
||||
begin
|
||||
UTCTimeStart := FDataController.GetTickDataItem(CrosshairCandle.OriginalDataIndexStart).OADateTime;
|
||||
UTCTimeStart := FDataController.GetTickDataItem(CrosshairCandle.OriginalDataIndexStart).TimeStamp;
|
||||
LocalTimeStart := TTimeZone.Local.ToLocalTime(UTCTimeStart);
|
||||
TimeStr := FormatDateTime('hh:nn:ss', LocalTimeStart); // Display time part
|
||||
|
||||
|
||||
Reference in New Issue
Block a user