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