Chart X grid, standard timeframes
This commit is contained in:
@@ -36,19 +36,19 @@ type
|
||||
class function CalculateWMA(const Series: TMycDataArray<Double>; const Period: Integer): Double; static;
|
||||
public
|
||||
// Simple Moving Average
|
||||
class function CreateSMA(Period: Integer): TFunc<Double, Double>; static;
|
||||
class function CreateSMA(Period: Integer): TIndicatorFunc<Double, Double>; static;
|
||||
// Exponential Moving Average
|
||||
class function CreateEMA(Period: Integer): TFunc<Double, Double>; static;
|
||||
class function CreateEMA(Period: Integer): TIndicatorFunc<Double, Double>; static;
|
||||
// Hull Moving Average
|
||||
class function CreateHMA(Period: Integer): TFunc<Double, Double>; static;
|
||||
class function CreateHMA(Period: Integer): TIndicatorFunc<Double, Double>; static;
|
||||
// Relative Strength Index
|
||||
class function CreateRSI(Period: Integer): TFunc<Double, Double>; static;
|
||||
class function CreateRSI(Period: Integer): TIndicatorFunc<Double, Double>; static;
|
||||
// Moving Average Convergence Divergence
|
||||
class function CreateMACD(FastPeriod, SlowPeriod, SignalPeriod: Integer): TFunc<Double, TMacdResult>; static;
|
||||
class function CreateMACD(FastPeriod, SlowPeriod, SignalPeriod: Integer): TIndicatorFunc<Double, TMacdResult>; static;
|
||||
// Stochastic Oscillator
|
||||
class function CreateStochastic(KPeriod, DPeriod: Integer): TFunc<TOhlcItem, TStochasticResult>; static;
|
||||
class function CreateStochastic(KPeriod, DPeriod: Integer): TIndicatorFunc<TOhlcItem, TStochasticResult>; static;
|
||||
// Bollinger Bands
|
||||
class function CreateBollingerBands(Period: Integer; Multiplier: Double): TFunc<Double, TBollingerBandsResult>; static;
|
||||
class function CreateBollingerBands(Period: Integer; Multiplier: Double): TIndicatorFunc<Double, TBollingerBandsResult>; static;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -112,11 +112,11 @@ begin
|
||||
Result := numerator / denominator;
|
||||
end;
|
||||
|
||||
class function TIndicators.CreateBollingerBands(Period: Integer; Multiplier: Double): TFunc<Double, TBollingerBandsResult>;
|
||||
class function TIndicators.CreateBollingerBands(Period: Integer; Multiplier: Double): TIndicatorFunc<Double, TBollingerBandsResult>;
|
||||
begin
|
||||
var sourceData := TMycDataArray<Double>.CreateEmpty;
|
||||
Result :=
|
||||
function(Value: Double): TBollingerBandsResult
|
||||
function(const Value: Double): TBollingerBandsResult
|
||||
var
|
||||
stdDev: Double;
|
||||
begin
|
||||
@@ -135,14 +135,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TIndicators.CreateEMA(Period: Integer): TFunc<Double, Double>;
|
||||
class function TIndicators.CreateEMA(Period: Integer): TIndicatorFunc<Double, Double>;
|
||||
begin
|
||||
var lastEma: Double := Double.NaN;
|
||||
var sourceData := TMycDataArray<Double>.CreateEmpty;
|
||||
var multiplier := 2 / (Period + 1);
|
||||
|
||||
Result :=
|
||||
function(Value: Double): Double
|
||||
function(const Value: Double): Double
|
||||
begin
|
||||
sourceData := sourceData.Add(Value, Period);
|
||||
|
||||
@@ -166,7 +166,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TIndicators.CreateHMA(Period: Integer): TFunc<Double, Double>;
|
||||
class function TIndicators.CreateHMA(Period: Integer): TIndicatorFunc<Double, Double>;
|
||||
begin
|
||||
var periodHalf := Period div 2;
|
||||
var periodSqrt := Round(Sqrt(Period));
|
||||
@@ -174,7 +174,7 @@ begin
|
||||
var diffSeries := TMycDataArray<Double>.CreateEmpty;
|
||||
|
||||
Result :=
|
||||
function(Value: Double): Double
|
||||
function(const Value: Double): Double
|
||||
var
|
||||
price: Double;
|
||||
wmaHalf, wmaFull, diff: Double;
|
||||
@@ -208,14 +208,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TIndicators.CreateMACD(FastPeriod, SlowPeriod, SignalPeriod: Integer): TFunc<Double, TMacdResult>;
|
||||
class function TIndicators.CreateMACD(FastPeriod, SlowPeriod, SignalPeriod: Integer): TIndicatorFunc<Double, TMacdResult>;
|
||||
begin
|
||||
var emaFast := CreateEMA(FastPeriod);
|
||||
var emaSlow := CreateEMA(SlowPeriod);
|
||||
var emaSignal := CreateEMA(SignalPeriod);
|
||||
|
||||
Result :=
|
||||
function(Value: Double): TMacdResult
|
||||
function(const Value: Double): TMacdResult
|
||||
var
|
||||
fastVal, slowVal: Double;
|
||||
begin
|
||||
@@ -240,14 +240,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TIndicators.CreateRSI(Period: Integer): TFunc<Double, Double>;
|
||||
class function TIndicators.CreateRSI(Period: Integer): TIndicatorFunc<Double, Double>;
|
||||
begin
|
||||
var avgGain: Double := Double.NaN;
|
||||
var avgLoss: Double := Double.NaN;
|
||||
var sourceData := TMycDataArray<Double>.CreateEmpty;
|
||||
|
||||
Result :=
|
||||
function(Value: Double): Double
|
||||
function(const Value: Double): Double
|
||||
var
|
||||
change, gain, loss, rs: Double;
|
||||
gainSum, lossSum: Double;
|
||||
@@ -299,11 +299,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TIndicators.CreateSMA(Period: Integer): TFunc<Double, Double>;
|
||||
class function TIndicators.CreateSMA(Period: Integer): TIndicatorFunc<Double, Double>;
|
||||
begin
|
||||
var sourceData := TMycDataArray<Double>.CreateEmpty;
|
||||
Result :=
|
||||
function(Value: Double): Double
|
||||
function(const Value: Double): Double
|
||||
begin
|
||||
sourceData := sourceData.Add(Value, Period);
|
||||
if (sourceData.Count >= Period) then
|
||||
@@ -313,13 +313,13 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TIndicators.CreateStochastic(KPeriod, DPeriod: Integer): TFunc<TOhlcItem, TStochasticResult>;
|
||||
class function TIndicators.CreateStochastic(KPeriod, DPeriod: Integer): TIndicatorFunc<TOhlcItem, TStochasticResult>;
|
||||
begin
|
||||
var sourceData := TMycDataArray<TOhlcItem>.CreateEmpty;
|
||||
var smaD := CreateSMA(DPeriod);
|
||||
|
||||
Result :=
|
||||
function(Value: TOhlcItem): TStochasticResult
|
||||
function(const Value: TOhlcItem): TStochasticResult
|
||||
var
|
||||
i: Integer;
|
||||
highestHigh, lowestLow: Double;
|
||||
|
||||
Reference in New Issue
Block a user