Sample SMA strategy

This commit is contained in:
Michael Schimmel
2025-09-03 19:21:31 +02:00
parent 6b9dcee417
commit 696fb2f9a0
8 changed files with 709 additions and 204 deletions
+51 -4
View File
@@ -35,6 +35,9 @@ type
function VisitAssignment(const Node: IAssignmentNode): TAstValue;
function VisitIndexer(const Node: IIndexerNode): TAstValue;
function VisitMemberAccess(const Node: IMemberAccessNode): TAstValue;
function VisitCreateSeries(const Node: ICreateSeriesNode): TAstValue;
function VisitAddSeriesItem(const Node: IAddSeriesItemNode): TAstValue;
function VisitSeriesLength(const Node: ISeriesLengthNode): TAstValue;
end;
implementation
@@ -123,10 +126,13 @@ begin
Indent;
Node.ThenBranch.Accept(Self);
Unindent;
AppendLine('Else:');
Indent;
Node.ElseBranch.Accept(Self);
Unindent;
if Node.ElseBranch <> nil then
begin
AppendLine('Else:');
Indent;
Node.ElseBranch.Accept(Self);
Unindent;
end;
Unindent;
Result := TAstValue.Void;
end;
@@ -255,4 +261,45 @@ begin
Result := TAstValue.Void;
end;
function TPrettyPrintVisitor.VisitCreateSeries(const Node: ICreateSeriesNode): TAstValue;
begin
AppendLine('CreateSeries');
Indent;
AppendLine('Definition: ' + Node.Definition);
Unindent;
Result := TAstValue.Void;
end;
function TPrettyPrintVisitor.VisitAddSeriesItem(const Node: IAddSeriesItemNode): TAstValue;
begin
AppendLine('AddSeriesItem');
Indent;
AppendLine('Series:');
Indent;
Node.Series.Accept(Self);
Unindent;
AppendLine('Value:');
Indent;
Node.Value.Accept(Self);
Unindent;
if Assigned(Node.Lookback) then
begin
AppendLine('Lookback:');
Indent;
Node.Lookback.Accept(Self);
Unindent;
end;
Unindent;
Result := TAstValue.Void;
end;
function TPrettyPrintVisitor.VisitSeriesLength(const Node: ISeriesLengthNode): TAstValue;
var
seriesStr: string;
begin
// Get the string representation of the series identifier by visiting the node.
seriesStr := Node.Series.Accept(Self).ToString;
Result := TAstValue.FromText(Format('length(%s)', [seriesStr]));
end;
end.