RTL and Data value refactoring and defered values
This commit is contained in:
+105
-50
@@ -136,6 +136,61 @@ begin
|
||||
|
||||
FWorkspace.OnMouseDown := WorkspaceMouseDown;
|
||||
|
||||
Tast.RegisterLibrary(
|
||||
procedure(const Scope: IExecutionScope)
|
||||
begin
|
||||
var smaAst :=
|
||||
TAst.LambdaExpr(
|
||||
[TAst.Identifier('len')],
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.VarDecl(TAst.Identifier('sum'), TAst.Constant(TScalar.FromDouble(0.0))),
|
||||
TAst.VarDecl(TAst.Identifier('count'), TAst.Constant(TScalar.FromInt64(0))),
|
||||
TAst.LambdaExpr(
|
||||
[TAst.Identifier('series'), TAst.Identifier('val')],
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.Assign(
|
||||
TAst.Identifier('sum'),
|
||||
TAst.BinaryExpr(TAst.Identifier('sum'), boAdd, TAst.Identifier('val'))
|
||||
),
|
||||
TAst.Assign(
|
||||
TAst.Identifier('count'),
|
||||
TAst.BinaryExpr(TAst.Identifier('count'), boAdd, TAst.Constant(TScalar.FromInt64(1)))
|
||||
),
|
||||
TAst.Assign(
|
||||
TAst.Identifier('sum'),
|
||||
TAst.TernaryExpr(
|
||||
TAst.BinaryExpr(TAst.Identifier('count'), boGreater, TAst.Identifier('len')),
|
||||
TAst.BinaryExpr(
|
||||
TAst.Identifier('sum'),
|
||||
boSubtract,
|
||||
TAst.Indexer(TAst.Identifier('series'), TAst.Identifier('len'))
|
||||
),
|
||||
TAst.Identifier('sum')
|
||||
)
|
||||
),
|
||||
TAst.BinaryExpr(
|
||||
TAst.Identifier('sum'),
|
||||
boDivide,
|
||||
TAst.TernaryExpr(
|
||||
TAst.BinaryExpr(TAst.Identifier('count'), boLess, TAst.Identifier('len')),
|
||||
TAst.Identifier('count'),
|
||||
TAst.Identifier('len')
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
Scope.Define('CreateSMA', smaAst.Accept(TEvaluatorVisitor.Create(TAstBinder.Bind(smaAst, FGScope).CreateScope(FGScope))));
|
||||
end
|
||||
);
|
||||
|
||||
// Setup global scope
|
||||
ClearButtonClick(Self);
|
||||
end;
|
||||
|
||||
@@ -401,54 +456,54 @@ begin
|
||||
var setupAst :=
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.VarDecl(
|
||||
TAst.Identifier('CreateSMA'),
|
||||
TAst.LambdaExpr(
|
||||
[TAst.Identifier('len')],
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.VarDecl(TAst.Identifier('sum'), TAst.Constant(TScalar.FromDouble(0.0))),
|
||||
TAst.VarDecl(TAst.Identifier('count'), TAst.Constant(TScalar.FromInt64(0))),
|
||||
TAst.LambdaExpr(
|
||||
[TAst.Identifier('series'), TAst.Identifier('val')],
|
||||
TAst.Block(
|
||||
[
|
||||
TAst.Assign(
|
||||
TAst.Identifier('sum'),
|
||||
TAst.BinaryExpr(TAst.Identifier('sum'), boAdd, TAst.Identifier('val'))
|
||||
),
|
||||
TAst.Assign(
|
||||
TAst.Identifier('count'),
|
||||
TAst.BinaryExpr(TAst.Identifier('count'), boAdd, TAst.Constant(TScalar.FromInt64(1)))
|
||||
),
|
||||
TAst.IfExpr(
|
||||
TAst.BinaryExpr(TAst.Identifier('count'), boGreater, TAst.Identifier('len')),
|
||||
TAst.Assign(
|
||||
TAst.Identifier('sum'),
|
||||
TAst.BinaryExpr(
|
||||
TAst.Identifier('sum'),
|
||||
boSubtract,
|
||||
TAst.Indexer(TAst.Identifier('series'), TAst.Identifier('len'))
|
||||
)
|
||||
),
|
||||
nil
|
||||
),
|
||||
TAst.BinaryExpr(
|
||||
TAst.Identifier('sum'),
|
||||
boDivide,
|
||||
TAst.TernaryExpr(
|
||||
TAst.BinaryExpr(TAst.Identifier('count'), boLess, TAst.Identifier('len')),
|
||||
TAst.Identifier('count'),
|
||||
TAst.Identifier('len')
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
),
|
||||
// TAst.VarDecl(
|
||||
// TAst.Identifier('CreateSMA'),
|
||||
// TAst.LambdaExpr(
|
||||
// [TAst.Identifier('len')],
|
||||
// TAst.Block(
|
||||
// [
|
||||
// TAst.VarDecl(TAst.Identifier('sum'), TAst.Constant(TScalar.FromDouble(0.0))),
|
||||
// TAst.VarDecl(TAst.Identifier('count'), TAst.Constant(TScalar.FromInt64(0))),
|
||||
// TAst.LambdaExpr(
|
||||
// [TAst.Identifier('series'), TAst.Identifier('val')],
|
||||
// TAst.Block(
|
||||
// [
|
||||
// TAst.Assign(
|
||||
// TAst.Identifier('sum'),
|
||||
// TAst.BinaryExpr(TAst.Identifier('sum'), boAdd, TAst.Identifier('val'))
|
||||
// ),
|
||||
// TAst.Assign(
|
||||
// TAst.Identifier('count'),
|
||||
// TAst.BinaryExpr(TAst.Identifier('count'), boAdd, TAst.Constant(TScalar.FromInt64(1)))
|
||||
// ),
|
||||
// TAst.IfExpr(
|
||||
// TAst.BinaryExpr(TAst.Identifier('count'), boGreater, TAst.Identifier('len')),
|
||||
// TAst.Assign(
|
||||
// TAst.Identifier('sum'),
|
||||
// TAst.BinaryExpr(
|
||||
// TAst.Identifier('sum'),
|
||||
// boSubtract,
|
||||
// TAst.Indexer(TAst.Identifier('series'), TAst.Identifier('len'))
|
||||
// )
|
||||
// ),
|
||||
// nil
|
||||
// ),
|
||||
// TAst.BinaryExpr(
|
||||
// TAst.Identifier('sum'),
|
||||
// boDivide,
|
||||
// TAst.TernaryExpr(
|
||||
// TAst.BinaryExpr(TAst.Identifier('count'), boLess, TAst.Identifier('len')),
|
||||
// TAst.Identifier('count'),
|
||||
// TAst.Identifier('len')
|
||||
// )
|
||||
// )
|
||||
// ]
|
||||
// )
|
||||
// )
|
||||
// ]
|
||||
// )
|
||||
// )
|
||||
// ),
|
||||
TAst.VarDecl(
|
||||
TAst.Identifier('smaFast'),
|
||||
TAst.FunctionCall(TAst.Identifier('CreateSMA'), [TAst.Constant(TScalar.FromInt64(smaFastLength))])
|
||||
@@ -548,9 +603,9 @@ begin
|
||||
TScalarValue.FromInt64(ohlcvRec.Volume)
|
||||
]
|
||||
);
|
||||
series.AsRecordSeries.Value.Add(recordValue, lookback);
|
||||
series.AsRecordSeries.Add(recordValue, lookback);
|
||||
|
||||
if series.AsRecordSeries.Value.TotalCount >= smaSlowLength then
|
||||
if series.AsRecordSeries.TotalCount >= smaSlowLength then
|
||||
begin
|
||||
scope[seriesAddress] := series;
|
||||
var resultValue := callAst.Accept(visitor);
|
||||
|
||||
Reference in New Issue
Block a user