Sample SMA strategy
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<ProjectVersion>20.3</ProjectVersion>
|
||||
<FrameworkType>FMX</FrameworkType>
|
||||
<Base>True</Base>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<Config Condition="'$(Config)'==''">Release</Config>
|
||||
<Platform Condition="'$(Platform)'==''">Win64</Platform>
|
||||
<ProjectName Condition="'$(ProjectName)'==''">ASTPlayground</ProjectName>
|
||||
<TargetedPlatforms>2</TargetedPlatforms>
|
||||
|
||||
@@ -664,7 +664,7 @@ end;
|
||||
|
||||
procedure TForm1.OHLCButtonClick(Sender: TObject);
|
||||
const
|
||||
numRecs = 100;
|
||||
numRecs = 1000;
|
||||
lookback = 50;
|
||||
smaSlowLength = 20;
|
||||
smaFastLength = 5;
|
||||
@@ -827,8 +827,8 @@ begin
|
||||
FGScope.SetValue('current_series', TAstValue.FromRecordSeries(series));
|
||||
resultValue := callAst.Accept(visitor);
|
||||
|
||||
Memo1.Lines.Add(Format('Tick %d/%d: Close = %.2f, Signal = %s', [i, numRecs, ohlcvRec.Close, resultValue.ToString]));
|
||||
Application.ProcessMessages;
|
||||
// Memo1.Lines.Add(Format('Tick %d/%d: Close = %.2f, Signal = %s', [i, numRecs, ohlcvRec.Close, resultValue.ToString]));
|
||||
// Application.ProcessMessages;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@@ -363,7 +363,6 @@ function TEvaluatorVisitor.VisitCreateSeries(const Node: ICreateSeriesNode): TAs
|
||||
var
|
||||
def: string;
|
||||
begin
|
||||
// CORRECTED: Node.Definition is now a simple string.
|
||||
def := Node.Definition.Trim;
|
||||
|
||||
// Based on the content, create a scalar or a record series.
|
||||
@@ -421,13 +420,13 @@ begin
|
||||
case baseValue.Kind of
|
||||
avkSeries:
|
||||
begin
|
||||
var series := baseValue.AsSeries.Value;
|
||||
if (index < 0) or (index >= series.Items.TotalCount) then
|
||||
raise EArgumentException
|
||||
.CreateFmt('Index %d is out of bounds for series with %d elements.', [index, series.Items.TotalCount]);
|
||||
with baseValue.AsSeries.Value do
|
||||
begin
|
||||
if (index < 0) or (index >= Items.TotalCount) then
|
||||
raise EArgumentException.CreateFmt('Index %d is out of bounds for series with %d elements.', [index, Items.TotalCount]);
|
||||
|
||||
var scalarValue := series.Items[Integer(index)];
|
||||
Result := TAstValue.FromScalar(TScalar.Create(series.Kind, scalarValue));
|
||||
Result := TAstValue.FromScalar(TScalar.Create(Kind, Items[Integer(index)]));
|
||||
end;
|
||||
end;
|
||||
avkRecordSeries:
|
||||
begin
|
||||
@@ -464,15 +463,17 @@ begin
|
||||
case baseValue.Kind of
|
||||
avkSeries:
|
||||
begin
|
||||
var series := baseValue.AsSeries.Value;
|
||||
if SameText(memberName, 'Count') then
|
||||
Result := TAstValue.FromScalar(TScalar.FromInt64(series.Items.Count))
|
||||
else if SameText(memberName, 'TotalCount') then
|
||||
Result := TAstValue.FromScalar(TScalar.FromInt64(series.Items.TotalCount))
|
||||
else if SameText(memberName, 'Kind') then
|
||||
Result := TAstValue.FromText(ScalarKindToString(series.Kind))
|
||||
else
|
||||
raise EArgumentException.CreateFmt('Member "%s" not found on TScalarSeries.', [memberName]);
|
||||
with baseValue.AsSeries.Value do
|
||||
begin
|
||||
if SameText(memberName, 'Count') then
|
||||
Result := TAstValue.FromScalar(TScalar.FromInt64(Items.Count))
|
||||
else if SameText(memberName, 'TotalCount') then
|
||||
Result := TAstValue.FromScalar(TScalar.FromInt64(Items.TotalCount))
|
||||
else if SameText(memberName, 'Kind') then
|
||||
Result := TAstValue.FromText(ScalarKindToString(Kind))
|
||||
else
|
||||
raise EArgumentException.CreateFmt('Member "%s" not found on TScalarSeries.', [memberName]);
|
||||
end;
|
||||
end;
|
||||
avkRecordSeries: Result := TAstValue.FromMemberSeries(baseValue.AsRecordSeries.Value.CreateMemberSeries(memberName));
|
||||
avkRecord: Result := TAstValue.FromScalar(baseValue.AsRecord.Items[memberName]);
|
||||
|
||||
Reference in New Issue
Block a user