Generic indicator factory
This commit is contained in:
@@ -136,15 +136,8 @@ end;
|
||||
|
||||
procedure TDataRecord.CopyFrom<T>(const Src: T);
|
||||
begin
|
||||
var ctx := TRttiContext.Create;
|
||||
var rttiType := ctx.GetType(TypeInfo(T));
|
||||
|
||||
for var i := 0 to High(FLayout.FFields) do
|
||||
begin
|
||||
var P: PByte := @Src;
|
||||
inc(P, FLayout.Fields[i].Offset);
|
||||
FLayout.Fields[i].FromType(FBuffer, Src);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDataRecord.CopyValue(const SrcRec: TDataRecord; SrcIdx, DstIdx: Integer);
|
||||
|
||||
+800
-244
File diff suppressed because it is too large
Load Diff
@@ -3,13 +3,13 @@ unit Myc.Trade.Indicators;
|
||||
interface
|
||||
|
||||
uses
|
||||
Myc.Data.Pipeline,
|
||||
Myc.Data.Records;
|
||||
|
||||
{$M+}
|
||||
|
||||
type
|
||||
TIndicatorProc<TValue, TResult> = reference to function(const Value: TValue): TResult;
|
||||
TIndicatorFactoryProc<TParams, TValue, TResult> = reference to function(const Params: TParams): TIndicatorProc<TValue, TResult>;
|
||||
TIndicatorFactoryProc<TParams, TValue, TResult> = reference to function(const Params: TParams): TConvertFunc<TValue, TResult>;
|
||||
|
||||
(*
|
||||
Sample definition of an indicator template:
|
||||
@@ -33,6 +33,9 @@ type
|
||||
|
||||
[IndicatorFactory]
|
||||
class function CreateFactory: TIndicatorFactoryProc<TParams, TArgs, TResult>; static;
|
||||
|
||||
// Hard coded version:
|
||||
class function CreateHMA( Period: Integer ): TConvertFunc<Double, Double>; static;
|
||||
end;
|
||||
*)
|
||||
|
||||
@@ -66,7 +69,7 @@ type
|
||||
function GetResultLayout: TDataRecord.TLayout;
|
||||
{$endregion}
|
||||
|
||||
function CreateIndicator(const Params: TDataRecord): TIndicatorProc<TDataRecord, TDataRecord>;
|
||||
function CreateIndicator(const Params: TDataRecord): TConvertFunc<TDataRecord, TDataRecord>;
|
||||
|
||||
property ParameterLayout: TDataRecord.TLayout read GetParameterLayout;
|
||||
property ArgumentLayout: TDataRecord.TLayout read GetArgumentLayout;
|
||||
@@ -94,7 +97,7 @@ type
|
||||
|
||||
class function CreateFromTemplate<T>: TGenericIndicatorFactory;
|
||||
|
||||
function CreateIndicator(const Params: TDataRecord): TIndicatorProc<TDataRecord, TDataRecord>;
|
||||
function CreateIndicator(const Params: TDataRecord): TConvertFunc<TDataRecord, TDataRecord>;
|
||||
|
||||
property ParameterLayout: TDataRecord.TLayout read GetParameterLayout;
|
||||
property ArgumentLayout: TDataRecord.TLayout read GetArgumentLayout;
|
||||
@@ -297,7 +300,7 @@ begin
|
||||
// Create the main factory procedure. This is a double-nested anonymous method
|
||||
// that wraps the template's specific factory and worker functions.
|
||||
factoryProc :=
|
||||
function(const Params: TDataRecord): TIndicatorProc<TDataRecord, TDataRecord>
|
||||
function(const Params: TDataRecord): TConvertFunc<TDataRecord, TDataRecord>
|
||||
begin
|
||||
// Outer anonymous method: This is the factory proc.
|
||||
// It gets called with a TDataRecord of parameters.
|
||||
@@ -364,7 +367,7 @@ begin
|
||||
Result := TGenericIndicatorFactory.Create(parameterLayout, argumentLayout, resultLayout, factoryProc, shortName, name, hint);
|
||||
end;
|
||||
|
||||
function TGenericIndicatorFactory.CreateIndicator(const Params: TDataRecord): TIndicatorProc<TDataRecord, TDataRecord>;
|
||||
function TGenericIndicatorFactory.CreateIndicator(const Params: TDataRecord): TConvertFunc<TDataRecord, TDataRecord>;
|
||||
begin
|
||||
Assert(
|
||||
(not Assigned(FParameterLayout.Fields)) or (Params.Layout = FParameterLayout),
|
||||
|
||||
Reference in New Issue
Block a user