mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-18 18:48:05 +00:00
Documentation
This commit is contained in:
+3
-3
@@ -25,7 +25,7 @@ public class BarIndicatorTests
|
|||||||
private static readonly ITValue[] indicators = new ITValue[]
|
private static readonly ITValue[] indicators = new ITValue[]
|
||||||
{
|
{
|
||||||
new Atr(period: 14),
|
new Atr(period: 14),
|
||||||
new Jvolty(period: 14)
|
|
||||||
// Add other TBar-based indicators here
|
// Add other TBar-based indicators here
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,14 +80,14 @@ public class BarIndicatorTests
|
|||||||
if (methods.Count > 0)
|
if (methods.Count > 0)
|
||||||
{
|
{
|
||||||
// Prefer the method with TBar parameter
|
// Prefer the method with TBar parameter
|
||||||
var method = methods.FirstOrDefault(m =>
|
var method = methods.Find(m =>
|
||||||
{
|
{
|
||||||
var parameters = m.GetParameters();
|
var parameters = m.GetParameters();
|
||||||
return parameters.Length == 1 && parameters[0].ParameterType == typeof(TBar);
|
return parameters.Length == 1 && parameters[0].ParameterType == typeof(TBar);
|
||||||
});
|
});
|
||||||
|
|
||||||
// If not found, return the first method
|
// If not found, return the first method
|
||||||
return method ?? methods.First();
|
return method ?? methods[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
type = type.BaseType!;
|
type = type.BaseType!;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace QuanTAlib
|
|||||||
{
|
{
|
||||||
public class QuantowerTests
|
public class QuantowerTests
|
||||||
{
|
{
|
||||||
private void TestIndicator<T>(string fieldName = "ma") where T : Indicator, new()
|
private static void TestIndicator<T>(string fieldName = "ma") where T : Indicator, new()
|
||||||
{
|
{
|
||||||
var indicator = new T();
|
var indicator = new T();
|
||||||
try
|
try
|
||||||
@@ -95,7 +95,6 @@ namespace QuanTAlib
|
|||||||
|
|
||||||
// Volatility Indicators
|
// Volatility Indicators
|
||||||
[Fact] public void Atr() => TestIndicator<AtrIndicator>("atr");
|
[Fact] public void Atr() => TestIndicator<AtrIndicator>("atr");
|
||||||
[Fact] public void Jvolty() => TestIndicator<JvoltyIndicator>("jvolty");
|
|
||||||
|
|
||||||
[Fact] public void Historical() => TestIndicator<HistoricalIndicator>("historical");
|
[Fact] public void Historical() => TestIndicator<HistoricalIndicator>("historical");
|
||||||
[Fact] public void Realized() => TestIndicator<RealizedIndicator>("realized");
|
[Fact] public void Realized() => TestIndicator<RealizedIndicator>("realized");
|
||||||
|
|||||||
@@ -57,21 +57,6 @@ public class VolatilityUpdateTests
|
|||||||
Assert.Equal(initialValue, finalValue, precision);
|
Assert.Equal(initialValue, finalValue, precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Jvolty_Update()
|
|
||||||
{
|
|
||||||
var indicator = new Jvolty(period: 14);
|
|
||||||
double initialValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: true));
|
|
||||||
|
|
||||||
for (int i = 0; i < RandomUpdates; i++)
|
|
||||||
{
|
|
||||||
indicator.Calc(GetRandomBar(false));
|
|
||||||
}
|
|
||||||
double finalValue = indicator.Calc(new TBar(DateTime.Now, ReferenceValue, ReferenceValue, ReferenceValue, ReferenceValue, 1000, IsNew: false));
|
|
||||||
|
|
||||||
Assert.Equal(initialValue, finalValue, precision);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Realized_Update()
|
public void Realized_Update()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
AC,Acceleration Oscillator
|
||||||
|
AD,Chaikin A/D Line
|
||||||
|
ADOSC,Chaikin A/D Oscillator
|
||||||
|
ADL,Accumulation / Distribution Line
|
||||||
|
ADX,Average Directional Movement Index
|
||||||
|
ADXR,Average Directional Movement Index Rating
|
||||||
|
Alligator,Alligator Indicator
|
||||||
|
ALMA,Arnaud Legoux Moving Average
|
||||||
|
AO,Awesome Oscillator
|
||||||
|
APO,Absolute Price Oscillator
|
||||||
|
AROON,Aroon Indicator
|
||||||
|
AROONOSC,Aroon Oscillator
|
||||||
|
ATS,ATR Trailing Stop
|
||||||
|
ATR,Average True Range
|
||||||
|
AVGPRICE,Average Price
|
||||||
|
BB,Bollinger Bands
|
||||||
|
BBF,Bollinger Bands Flat
|
||||||
|
BBP,Bull and Bear Power
|
||||||
|
BC,Beta Coefficient
|
||||||
|
BETA,Beta
|
||||||
|
BOP,Balance of Power
|
||||||
|
CCI,Commodity Channel Index
|
||||||
|
CE,Chandelier Exit
|
||||||
|
Channel,Price Channel
|
||||||
|
CI,Choppiness Index
|
||||||
|
CMF,Chaikin Money Flow
|
||||||
|
CMO,Chande Momentum Oscillator
|
||||||
|
CORREL,Pearson's Correlation Coefficient
|
||||||
|
CRSI,ConnorsRSI
|
||||||
|
DC,Donchian Channels
|
||||||
|
DCP,Dominant Cycle Periods
|
||||||
|
DEMA,Double Exponential Moving Average
|
||||||
|
DMI,Directional Movement Index
|
||||||
|
DPO,Detrended Price Oscillator
|
||||||
|
DX,Directional Movement Index
|
||||||
|
EMA,Exponential Moving Average
|
||||||
|
EPMA,Endpoint Moving Average
|
||||||
|
ERI,Elder-ray Index
|
||||||
|
FCB,Fractal Chaos Bands
|
||||||
|
FI,Force Index
|
||||||
|
GO,Gator Oscillator
|
||||||
|
HE,Hurst Exponent
|
||||||
|
HMA,Hull Moving Average
|
||||||
|
HT_TRENDLINE,Hilbert Transform - Instantaneous Trendline
|
||||||
|
HT_TRENDMODE,Hilbert Transform - Trend vs Cycle Mode
|
||||||
|
HV,Historical Volatility
|
||||||
|
IC,Ichimoku Cloud
|
||||||
|
KAMA,Kaufman Adaptive Moving Average
|
||||||
|
KDJ,KDJ Index
|
||||||
|
Keltner,Keltner Channel
|
||||||
|
KVO,Klinger Volume Oscillator
|
||||||
|
LINEARREG,Linear Regression
|
||||||
|
LINEARREG_ANGLE,Linear Regression Angle
|
||||||
|
LINEARREG_INTERCEPT,Linear Regression Intercept
|
||||||
|
LINEARREG_SLOPE,Linear Regression Slope
|
||||||
|
LSMA,Least Squares Moving Average
|
||||||
|
LWMA,Linearly Weighted Moving Average
|
||||||
|
MACDEXT,MACD with controllable MA type
|
||||||
|
MACDFIX,Moving Average Convergence Divergence Fix 12/26
|
||||||
|
MAD,Mean absolute deviation
|
||||||
|
MAE,Moving Average Envelope
|
||||||
|
MAMA,MESA Adaptive Moving Average
|
||||||
|
MAPE,Mean absolute percentage error
|
||||||
|
MAX,Highest value over a specified period
|
||||||
|
MAXINDEX,Index of highest value over a specified period
|
||||||
|
MD,McGinley Dynamic
|
||||||
|
MEDPRICE,Median Price
|
||||||
|
MFI,Money Flow Index
|
||||||
|
MIN,Lowest value over a specified period
|
||||||
|
MININDEX,Index of lowest value over a specified period
|
||||||
|
MINMAX,Lowest and highest values over a specified period
|
||||||
|
MINMAXINDEX,Indexes of lowest and highest values over a period
|
||||||
|
MMA,Modified Moving Average
|
||||||
|
MOM,Momentum
|
||||||
|
MSE,Mean square error
|
||||||
|
NATR,Normalized Average True Range
|
||||||
|
OBV,On Balance Volume
|
||||||
|
OsMA,Moving Average of Oscillator
|
||||||
|
PAZ,Price Action Zones
|
||||||
|
Pivots,Pivots
|
||||||
|
PMO,Price Momentum Oscillator
|
||||||
|
PP,Pivot Points
|
||||||
|
PPO,Percentage Price Oscillator
|
||||||
|
PPMA,Pivot Point Moving Average
|
||||||
|
PRS,Price Relative Strength
|
||||||
|
PVI,Positive Volume Index
|
||||||
|
PVO,Percentage Volume Oscillator
|
||||||
|
Qstick,Qstick Indicator
|
||||||
|
R2,R-Squared (Coefficient of Determination)
|
||||||
|
Regression,Regression Line Indicator
|
||||||
|
RLW,%R Larry Williams
|
||||||
|
RMA,Running Moving Average
|
||||||
|
ROC,Rate of Change
|
||||||
|
ROCB,ROC with Bands
|
||||||
|
RPP,Rolling Pivot Points
|
||||||
|
RRA,Rescaled Range Analysis
|
||||||
|
RSI,Relative Strength Index
|
||||||
|
SAR,Parabolic SAR
|
||||||
|
SAREXT,Parabolic SAR - Extended
|
||||||
|
SDC,Standard Deviation Channels
|
||||||
|
SI,Swing Index
|
||||||
|
SLR,Slope and Linear Regression
|
||||||
|
SMA,Simple Moving Average
|
||||||
|
SMI,Stochastic Momentum Index
|
||||||
|
SMMA,Smoothed Moving Average
|
||||||
|
ST,SuperTrend
|
||||||
|
STARC,STARC Bands
|
||||||
|
STC,Schaff Trend Cycle
|
||||||
|
STDDEV,Standard Deviation
|
||||||
|
STOCH,Stochastic
|
||||||
|
STOCHF,Stochastic Fast
|
||||||
|
STOCHRSI,Stochastic Relative Strength Index
|
||||||
|
SUM,Summation
|
||||||
|
T3,Triple Exponential Moving Average (T3)
|
||||||
|
TEMA,Triple Exponential Moving Average
|
||||||
|
TRANGE,True Range
|
||||||
|
TRIMA,Triangular Moving Average
|
||||||
|
TRIX,1-day Rate-Of-Change (ROC) of a Triple Smooth EMA
|
||||||
|
TSI,True Strength Index
|
||||||
|
TYPPRICE,Typical Price
|
||||||
|
UI,Ulcer Index
|
||||||
|
ULTOSC,Ultimate Oscillator
|
||||||
|
VAR,Variance
|
||||||
|
VI,Vortex Indicator
|
||||||
|
Volume,Volume Indicator
|
||||||
|
VS,Volatility Stop
|
||||||
|
VWAP,Volume Weighted Average Price
|
||||||
|
VWMA,Volume Weighted Moving Average
|
||||||
|
WA,Williams Alligator
|
||||||
|
WCLPRICE,Weighted Close Price
|
||||||
|
WF,Williams Fractal
|
||||||
|
WMA,Weighted Moving Average
|
||||||
|
ZS,Z-Score
|
||||||
|
ZZ,ZigZag Indicator
|
||||||
|
+313
-5
@@ -1,5 +1,313 @@
|
|||||||
# Backlog and done
|
| AD | Chaikin A/D Line |
|
||||||
|
| AROON | Aroon Indicator |
|
||||||
|**QT**|**Chart**|Cmnt|Docs|isNew|Validation|
|
| ADX | Average Directional Movement Index |
|
||||||
|--|:--:|:--:|:--:|:--:|:--:|
|
| ADXR | Average Directional Movement Index Rating |
|
||||||
|AFIRMA|✔️|||||
|
| DX | Directional Movement Index |
|
||||||
|
| SAR | Parabolic SAR |
|
||||||
|
| SAREXT | Parabolic SAR - Extended |
|
||||||
|
| HT_TRENDLINE | Hilbert Transform - Instantaneous Trendline |
|
||||||
|
| HT_TRENDMODE | Hilbert Transform - Trend vs Cycle Mode |
|
||||||
|
| ZZ | ZigZag Indicator |
|
||||||
|
| DMI | Directional Movement Index |
|
||||||
|
| Alligator | Alligator Indicator |
|
||||||
|
| Regression | Regression Line Indicator |
|
||||||
|
| SI | Swing Index |
|
||||||
|
| ATS | ATR Trailing Stop |
|
||||||
|
| ERI | Elder-ray Index |
|
||||||
|
| GO | Gator Oscillator |
|
||||||
|
| HE | Hurst Exponent |
|
||||||
|
| IC | Ichimoku Cloud |
|
||||||
|
| ST | SuperTrend |
|
||||||
|
| VI | Vortex Indicator |
|
||||||
|
| WA | Williams Alligator |
|
||||||
|
| RSI | Relative Strength Index |
|
||||||
|
| CCI | Commodity Channel Index |
|
||||||
|
| MOM | Momentum |
|
||||||
|
| ROC | Rate of Change |
|
||||||
|
| PPO | Percentage Price Oscillator |
|
||||||
|
| AO | Awesome Oscillator |
|
||||||
|
| CMO | Chande Momentum Oscillator |
|
||||||
|
| TRIX | 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA |
|
||||||
|
| ULTOSC | Ultimate Oscillator |
|
||||||
|
| AROONOSC | Aroon Oscillator |
|
||||||
|
| ADOSC | Chaikin A/D Oscillator |
|
||||||
|
| APO | Absolute Price Oscillator |
|
||||||
|
| STOCH | Stochastic |
|
||||||
|
| STOCHF | Stochastic Fast |
|
||||||
|
| STOCHRSI | Stochastic Relative Strength Index |
|
||||||
|
| Qstick | Qstick Indicator |
|
||||||
|
| RLW | %R Larry Williams |
|
||||||
|
| AC | Acceleration Oscillator |
|
||||||
|
| TSI | True Strength Index |
|
||||||
|
| CRSI | ConnorsRSI |
|
||||||
|
| DPO | Detrended Price Oscillator |
|
||||||
|
| KDJ | KDJ Index |
|
||||||
|
| STC | Schaff Trend Cycle |
|
||||||
|
| SMI | Stochastic Momentum Index |
|
||||||
|
| BB | Bollinger Bands |
|
||||||
|
| Keltner | Keltner Channel |
|
||||||
|
| BBF | Bollinger Bands Flat |
|
||||||
|
| Channel | Price Channel |
|
||||||
|
| MAE | Moving Average Envelope |
|
||||||
|
| PAZ | Price Action Zones |
|
||||||
|
| DC | Donchian Channels |
|
||||||
|
| FCB | Fractal Chaos Bands |
|
||||||
|
| PP | Pivot Points |
|
||||||
|
| RPP | Rolling Pivot Points |
|
||||||
|
| STARC | STARC Bands |
|
||||||
|
| SDC | Standard Deviation Channels |
|
||||||
|
| OBV | On Balance Volume |
|
||||||
|
| PVI | Positive Volume Index |
|
||||||
|
| Volume | Volume Indicator |
|
||||||
|
| MFI | Money Flow Index |
|
||||||
|
| ADL | Accumulation / Distribution Line |
|
||||||
|
| CMF | Chaikin Money Flow |
|
||||||
|
| FI | Force Index |
|
||||||
|
| KVO | Klinger Volume Oscillator |
|
||||||
|
| PVO | Percentage Volume Oscillator |
|
||||||
|
| ATS | ATR Trailing Stop |
|
||||||
|
| CE | Chandelier Exit |
|
||||||
|
| SAR | Parabolic SAR |
|
||||||
|
| ST | SuperTrend |
|
||||||
|
| VS | Volatility Stop |
|
||||||
|
| Pivots | Pivots |
|
||||||
|
| WF | Williams Fractal |
|
||||||
|
| EMA | Exponential Moving Average |
|
||||||
|
| SMA | Simple Moving Average |
|
||||||
|
| LWMA | Linearly Weighted Moving Average |
|
||||||
|
| SMMA | Smoothed Moving Average |
|
||||||
|
| MMA | Modified Moving Average |
|
||||||
|
| KAMA | Kaufman Adaptive Moving Average |
|
||||||
|
| DEMA | Double Exponential Moving Average |
|
||||||
|
| TEMA | Triple Exponential Moving Average |
|
||||||
|
| MAMA | MESA Adaptive Moving Average |
|
||||||
|
| TRIMA | Triangular Moving Average |
|
||||||
|
| T3 | Triple Exponential Moving Average (T3) |
|
||||||
|
| PPMA | Pivot Point Moving Average |
|
||||||
|
| WMA | Weighted Moving Average |
|
||||||
|
| ALMA | Arnaud Legoux Moving Average |
|
||||||
|
| EPMA | Endpoint Moving Average |
|
||||||
|
| HMA | Hull Moving Average |
|
||||||
|
| LSMA | Least Squares Moving Average |
|
||||||
|
| MD | McGinley Dynamic |
|
||||||
|
| RMA | Running Moving Average |
|
||||||
|
| VWAP | Volume Weighted Average Price |
|
||||||
|
| VWMA | Volume Weighted Moving Average |
|
||||||
|
| ATR | Average True Range |
|
||||||
|
| NATR | Normalized Average True Range |
|
||||||
|
| TRANGE | True Range |
|
||||||
|
| STDDEV | Standard Deviation |
|
||||||
|
| HV | Historical Volatility |
|
||||||
|
| BOP | Balance of Power |
|
||||||
|
| BBP | Bull and Bear Power |
|
||||||
|
| CI | Choppiness Index |
|
||||||
|
| DCP | Dominant Cycle Periods |
|
||||||
|
| PMO | Price Momentum Oscillator |
|
||||||
|
| PRS | Price Relative Strength |
|
||||||
|
| ROCB | ROC with Bands |
|
||||||
|
| RRA | Rescaled Range Analysis |
|
||||||
|
| UI | Ulcer Index |
|
||||||
|
| CORREL | Pearson's Correlation Coefficient |
|
||||||
|
| BETA | Beta |
|
||||||
|
| VAR | Variance |
|
||||||
|
| AVGPRICE | Average Price |
|
||||||
|
| MEDPRICE | Median Price |
|
||||||
|
| TYPPRICE | Typical Price |
|
||||||
|
| WCLPRICE | Weighted Close Price |
|
||||||
|
| SUM | Summation |
|
||||||
|
| MAX | Highest value over a specified period |
|
||||||
|
| MIN | Lowest value over a specified period |
|
||||||
|
| MAXINDEX | Index of highest value over a specified period |
|
||||||
|
| MININDEX | Index of lowest value over a specified period |
|
||||||
|
| MINMAX | Lowest and highest values over a specified period |
|
||||||
|
| MINMAXINDEX | Indexes of lowest and highest values over a period |
|
||||||
|
| BC | Beta Coefficient |
|
||||||
|
| MAD | Mean absolute deviation |
|
||||||
|
| MAPE | Mean absolute percentage error |
|
||||||
|
| MSE | Mean square error |
|
||||||
|
| R2 | R-Squared (Coefficient of Determination) |
|
||||||
|
| SLR | Slope and Linear Regression |
|
||||||
|
| ZS | Z-Score |
|
||||||
|
| AD | Chaikin A/D Line |
|
||||||
|
| AROON | Aroon Indicator |
|
||||||
|
| ADX | Average Directional Movement Index |
|
||||||
|
| ADXR | Average Directional Movement Index Rating |
|
||||||
|
| DX | Directional Movement Index |
|
||||||
|
| SAR | Parabolic SAR |
|
||||||
|
| SAREXT | Parabolic SAR - Extended |
|
||||||
|
| HT_TRENDLINE | Hilbert Transform - Instantaneous Trendline |
|
||||||
|
| HT_TRENDMODE | Hilbert Transform - Trend vs Cycle Mode |
|
||||||
|
| ZZ | ZigZag Indicator |
|
||||||
|
| DMI | Directional Movement Index |
|
||||||
|
| Alligator | Alligator Indicator |
|
||||||
|
| Regression | Regression Line Indicator |
|
||||||
|
| SI | Swing Index |
|
||||||
|
| ATS | ATR Trailing Stop |
|
||||||
|
| ERI | Elder-ray Index |
|
||||||
|
| GO | Gator Oscillator |
|
||||||
|
| HE | Hurst Exponent |
|
||||||
|
| IC | Ichimoku Cloud |
|
||||||
|
| ST | SuperTrend |
|
||||||
|
| VI | Vortex Indicator |
|
||||||
|
| WA | Williams Alligator |
|
||||||
|
| RSI | Relative Strength Index |
|
||||||
|
| CCI | Commodity Channel Index |
|
||||||
|
| MOM | Momentum |
|
||||||
|
| ROC | Rate of Change |
|
||||||
|
| PPO | Percentage Price Oscillator |
|
||||||
|
| AO | Awesome Oscillator |
|
||||||
|
| CMO | Chande Momentum Oscillator |
|
||||||
|
| TRIX | 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA |
|
||||||
|
| ULTOSC | Ultimate Oscillator |
|
||||||
|
| AROONOSC | Aroon Oscillator |
|
||||||
|
| ADOSC | Chaikin A/D Oscillator |
|
||||||
|
| APO | Absolute Price Oscillator |
|
||||||
|
| STOCH | Stochastic |
|
||||||
|
| STOCHF | Stochastic Fast |
|
||||||
|
| STOCHRSI | Stochastic Relative Strength Index |
|
||||||
|
| Qstick | Qstick Indicator |
|
||||||
|
| RLW | %R Larry Williams |
|
||||||
|
| AC | Acceleration Oscillator |
|
||||||
|
| TSI | True Strength Index |
|
||||||
|
| CRSI | ConnorsRSI |
|
||||||
|
| DPO | Detrended Price Oscillator |
|
||||||
|
| KDJ | KDJ Index |
|
||||||
|
| STC | Schaff Trend Cycle |
|
||||||
|
| SMI | Stochastic Momentum Index |
|
||||||
|
| BB | Bollinger Bands |
|
||||||
|
| Keltner | Keltner Channel |
|
||||||
|
| BBF | Bollinger Bands Flat |
|
||||||
|
| Channel | Price Channel |
|
||||||
|
| MAE | Moving Average Envelope |
|
||||||
|
| PAZ | Price Action Zones |
|
||||||
|
| DC | Donchian Channels |
|
||||||
|
| FCB | Fractal Chaos Bands |
|
||||||
|
| PP | Pivot Points |
|
||||||
|
| RPP | Rolling Pivot Points |
|
||||||
|
| STARC | STARC Bands |
|
||||||
|
| SDC | Standard Deviation Channels |
|
||||||
|
| OBV | On Balance Volume |
|
||||||
|
| PVI | Positive Volume Index |
|
||||||
|
| Volume | Volume Indicator |
|
||||||
|
| MFI | Money Flow Index |
|
||||||
|
| ADL | Accumulation / Distribution Line |
|
||||||
|
| CMF | Chaikin Money Flow |
|
||||||
|
| FI | Force Index |
|
||||||
|
| KVO | Klinger Volume Oscillator |
|
||||||
|
| PVO | Percentage Volume Oscillator |
|
||||||
|
| ATS | ATR Trailing Stop |
|
||||||
|
| CE | Chandelier Exit |
|
||||||
|
| SAR | Parabolic SAR |
|
||||||
|
| ST | SuperTrend |
|
||||||
|
| VS | Volatility Stop |
|
||||||
|
| Pivots | Pivots |
|
||||||
|
| WF | Williams Fractal |
|
||||||
|
| ALMA | Arnaud Legoux Moving Average |
|
||||||
|
| EPMA | Endpoint Moving Average |
|
||||||
|
| HMA | Hull Moving Average |
|
||||||
|
| LSMA | Least Squares Moving Average |
|
||||||
|
| MD | McGinley Dynamic |
|
||||||
|
| RMA | Running Moving Average |
|
||||||
|
| T3 | Tillson T3 Moving Average |
|
||||||
|
| VWAP | Volume Weighted Average Price |
|
||||||
|
| VWMA | Volume Weighted Moving Average |
|
||||||
|
| BOP | Balance of Power |
|
||||||
|
| BBP | Bull and Bear Power |
|
||||||
|
| CI | Choppiness Index |
|
||||||
|
| DCP | Dominant Cycle Periods |
|
||||||
|
| PMO | Price Momentum Oscillator |
|
||||||
|
| PRS | Price Relative Strength |
|
||||||
|
| ROCB | ROC with Bands |
|
||||||
|
| RRA | Rescaled Range Analysis |
|
||||||
|
| UI | Ulcer Index |
|
||||||
|
| BC | Beta Coefficient |
|
||||||
|
| MAD | Mean absolute deviation |
|
||||||
|
| MAPE | Mean absolute percentage error |
|
||||||
|
| MSE | Mean square error |
|
||||||
|
| R2 | R-Squared (Coefficient of Determination) |
|
||||||
|
| SLR | Slope and Linear Regression |
|
||||||
|
| ZS | Z-Score |
|
||||||
|
| EMA | Exponential Moving Average |
|
||||||
|
| SMA | Simple Moving Average |
|
||||||
|
| LWMA | Linearly Weighted Moving Average |
|
||||||
|
| SMMA | Smoothed Moving Average |
|
||||||
|
| MMA | Modified Moving Average |
|
||||||
|
| KAMA | Kaufman Adaptive Moving Average |
|
||||||
|
| DEMA | Double Exponential Moving Average |
|
||||||
|
| TEMA | Triple Exponential Moving Average |
|
||||||
|
| MAMA | MESA Adaptive Moving Average |
|
||||||
|
| TRIMA | Triangular Moving Average |
|
||||||
|
| T3 | Triple Exponential Moving Average (T3) |
|
||||||
|
| PPMA | Pivot Point Moving Average |
|
||||||
|
| MAE | Moving Average Envelope |
|
||||||
|
| MACD | Moving Average Convergence Divergence |
|
||||||
|
| MACDEXT | MACD with controllable MA type |
|
||||||
|
| MACDFIX | Moving Average Convergence Divergence Fix 12/26 |
|
||||||
|
| OsMA | Moving Average of Oscillator |
|
||||||
|
| Regression | Regression Indicator |
|
||||||
|
| LINEARREG | Linear Regression |
|
||||||
|
| LINEARREG_ANGLE | Linear Regression Angle |
|
||||||
|
| LINEARREG_INTERCEPT | Linear Regression Intercept |
|
||||||
|
| LINEARREG_SLOPE | Linear Regression Slope |
|
||||||
|
| RSI | Relative Strength Index |
|
||||||
|
| CCI | Commodity Channel Index |
|
||||||
|
| MOM | Momentum |
|
||||||
|
| ROC | Rate of Change |
|
||||||
|
| PPO | Percentage Price Oscillator |
|
||||||
|
| AO | Awesome Oscillator |
|
||||||
|
| CMO | Chande Momentum Oscillator |
|
||||||
|
| TRIX | 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA |
|
||||||
|
| ULTOSC | Ultimate Oscillator |
|
||||||
|
| AROONOSC | Aroon Oscillator |
|
||||||
|
| ADOSC | Chaikin A/D Oscillator |
|
||||||
|
| APO | Absolute Price Oscillator |
|
||||||
|
| STOCH | Stochastic |
|
||||||
|
| STOCHF | Stochastic Fast |
|
||||||
|
| STOCHRSI | Stochastic Relative Strength Index |
|
||||||
|
| Qstick | Qstick Indicator |
|
||||||
|
| RLW | %R Larry Williams |
|
||||||
|
| AC | Acceleration Oscillator |
|
||||||
|
| TSI | True Strength Index |
|
||||||
|
| AD | Chaikin A/D Line |
|
||||||
|
| AROON | Aroon Indicator |
|
||||||
|
| ADX | Average Directional Movement Index |
|
||||||
|
| ADXR | Average Directional Movement Index Rating |
|
||||||
|
| DX | Directional Movement Index |
|
||||||
|
| SAR | Parabolic SAR |
|
||||||
|
| SAREXT | Parabolic SAR - Extended |
|
||||||
|
| HT_TRENDLINE | Hilbert Transform - Instantaneous Trendline |
|
||||||
|
| HT_TRENDMODE | Hilbert Transform - Trend vs Cycle Mode |
|
||||||
|
| ZZ | ZigZag Indicator |
|
||||||
|
| DMI | Directional Movement Index |
|
||||||
|
| Alligator | Alligator Indicator |
|
||||||
|
| Regression | Regression Line Indicator |
|
||||||
|
| SI | Swing Index |
|
||||||
|
| ATR | Average True Range |
|
||||||
|
| NATR | Normalized Average True Range |
|
||||||
|
| TRANGE | True Range |
|
||||||
|
| STDDEV | Standard Deviation |
|
||||||
|
| HV | Historical Volatility |
|
||||||
|
| BB | Bollinger Bands |
|
||||||
|
| Keltner | Keltner Channel |
|
||||||
|
| BBF | Bollinger Bands Flat |
|
||||||
|
| Channel | Price Channel |
|
||||||
|
| MAE | Moving Average Envelope |
|
||||||
|
| PAZ | Price Action Zones |
|
||||||
|
| OBV | On Balance Volume |
|
||||||
|
| PVI | Positive Volume Index |
|
||||||
|
| Volume | Volume Indicator |
|
||||||
|
| MFI | Money Flow Index |
|
||||||
|
| CORREL | Pearson's Correlation Coefficient |
|
||||||
|
| BETA | Beta |
|
||||||
|
| VAR | Variance |
|
||||||
|
| AVGPRICE | Average Price |
|
||||||
|
| MEDPRICE | Median Price |
|
||||||
|
| TYPPRICE | Typical Price |
|
||||||
|
| WCLPRICE | Weighted Close Price |
|
||||||
|
| SUM | Summation |
|
||||||
|
| MAX | Highest value over a specified period |
|
||||||
|
| MIN | Lowest value over a specified period |
|
||||||
|
| MAXINDEX | Index of highest value over a specified period |
|
||||||
|
| MININDEX | Index of lowest value over a specified period |
|
||||||
|
| MINMAX | Lowest and highest values over a specified period |
|
||||||
|
| MINMAXINDEX | Indexes of lowest and highest values over a period |
|
||||||
|
|||||||
+34
-10
@@ -1,7 +1,34 @@
|
|||||||
* [QuanTAlib](/)
|
|
||||||
|
* [Home](/)
|
||||||
|
* Introduction
|
||||||
|
* [Overview]()
|
||||||
|
* [Features]()
|
||||||
* [Historical vs Real-time analysis](essays/realtime.md)
|
* [Historical vs Real-time analysis](essays/realtime.md)
|
||||||
* [Indicators](indicators/indicators.md)
|
|
||||||
* Averages & Trends
|
* Core Concepts
|
||||||
|
* [Time Series Data Handling]()
|
||||||
|
* [Calculation classes]()
|
||||||
|
* [Presentation Classes]()
|
||||||
|
|
||||||
|
* QuanTAlib C# Library
|
||||||
|
* [Installation]()
|
||||||
|
* [Quick Start Guide]()
|
||||||
|
* [Usage Examples]()
|
||||||
|
* [Tests and Validation]()
|
||||||
|
|
||||||
|
* Quantower Charts
|
||||||
|
* [Installation]()
|
||||||
|
* [Quick Start Guide]()
|
||||||
|
* [Using VS Code for QuanTower coding](setup/vscode.md)
|
||||||
|
* [Using DotPeek](setup/dotpeek.md)
|
||||||
|
* [Creating Custom Indicators]()
|
||||||
|
* [Inspecting Quantower Internals]()
|
||||||
|
|
||||||
|
* [Available Indicators](indicators/indicators.md)
|
||||||
|
* Basic Transforms
|
||||||
|
* Numerical Analysis
|
||||||
|
* Errors
|
||||||
|
* Moving Averages
|
||||||
* [AFIRMA - Adaptive Filtering Integrated Recursive Moving Average](indicators/averages/afirma/afirma.md)
|
* [AFIRMA - Adaptive Filtering Integrated Recursive Moving Average](indicators/averages/afirma/afirma.md)
|
||||||
* [Calculation](indicators/averages/afirma/calc.md)
|
* [Calculation](indicators/averages/afirma/calc.md)
|
||||||
* [Analysis](indicators/averages/afirma/analysis.md)
|
* [Analysis](indicators/averages/afirma/analysis.md)
|
||||||
@@ -14,7 +41,6 @@
|
|||||||
* [Calculation](indicators/averages/ama/calc.md)
|
* [Calculation](indicators/averages/ama/calc.md)
|
||||||
* [Analysis](indicators/averages/ama/analysis.md)
|
* [Analysis](indicators/averages/ama/analysis.md)
|
||||||
* [Charts](indicators/averages/ama/charts.md)
|
* [Charts](indicators/averages/ama/charts.md)
|
||||||
* [Convolutiuon]
|
|
||||||
* [DEMA - Double Exponential Moving Average](indicators/averages/dema/dema.md)
|
* [DEMA - Double Exponential Moving Average](indicators/averages/dema/dema.md)
|
||||||
* [Calculation](indicators/averages/dema/calc.md)
|
* [Calculation](indicators/averages/dema/calc.md)
|
||||||
* [Analysis](indicators/averages/dema/analysis.md)
|
* [Analysis](indicators/averages/dema/analysis.md)
|
||||||
@@ -61,11 +87,9 @@
|
|||||||
* VIDYA - Variable Index Dynamic Average
|
* VIDYA - Variable Index Dynamic Average
|
||||||
* WMA - Weighted Moving Average
|
* WMA - Weighted Moving Average
|
||||||
* ZLEMA - Weighted Moving Average
|
* ZLEMA - Weighted Moving Average
|
||||||
* Basic Data Transforms
|
* Trends
|
||||||
* [Statistics & Numerical Analysis](indicators/statistics/list.md)
|
* Momentum
|
||||||
|
* Oscillators
|
||||||
* Volatility
|
* Volatility
|
||||||
* Volume
|
* Volume
|
||||||
* Momentum & Oscillators
|
|
||||||
* Development
|
|
||||||
* [VS Code](setup/vscode.md)
|
|
||||||
* [DotPeek](setup/dotpeek.md)
|
|
||||||
|
|||||||
+46
-69
@@ -2,76 +2,38 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Document</title>
|
<title>QuanTAlib Documentation</title>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
<meta name="description" content="Description">
|
<meta name="description" content="Documentation for QuanTAlib, a quantitative technical analysis library">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css" integrity="sha384-G+RAlt+LEfAH/nY+DZh3+XIhRboypMI32hiJ9BwnmjF41May5BWQKyrDrEkNdV/i" crossorigin="anonymous">
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/katex.min.css" integrity="sha384-3UiQGuEI4TTMaFmGIZumfRPtfKQ3trwQE2JgosJxCnGmQpL/lJdjpcHkaaFwHlcI" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/katex.min.css" integrity="sha384-3UiQGuEI4TTMaFmGIZumfRPtfKQ3trwQE2JgosJxCnGmQpL/lJdjpcHkaaFwHlcI" crossorigin="anonymous">
|
||||||
|
<link rel="stylesheet" href="styles.css">
|
||||||
<style>
|
|
||||||
.markdown-section {
|
|
||||||
max-width: none !important;
|
|
||||||
width: 100% !important;
|
|
||||||
}
|
|
||||||
.sidebar-nav {
|
|
||||||
line-height: 1.5;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
.markdown-section table tbody td {
|
|
||||||
padding: 4px 1px;
|
|
||||||
}
|
|
||||||
:root {
|
|
||||||
--sidebar-width: 350px;
|
|
||||||
--sidebar-nav-link-padding: 2px 0;
|
|
||||||
--sidebar-nav-pagelink-padding: 2px 0 2px 12px;
|
|
||||||
--sidebar-nav-indent: 12px;
|
|
||||||
}
|
|
||||||
.content {
|
|
||||||
left: var(--sidebar-width);
|
|
||||||
}
|
|
||||||
.sidebar-toggle {
|
|
||||||
width: var(--sidebar-width);
|
|
||||||
}
|
|
||||||
/* Updated styles for partially expandable sidebar */
|
|
||||||
.sidebar-nav ul ul ul ul {
|
|
||||||
overflow: hidden;
|
|
||||||
max-height: 0;
|
|
||||||
transition: max-height 0.3s ease-out;
|
|
||||||
}
|
|
||||||
.sidebar-nav ul ul ul li:hover > ul {
|
|
||||||
max-height: 1000px;
|
|
||||||
transition: max-height 0.3s ease-in;
|
|
||||||
}
|
|
||||||
.sidebar-nav .collapse.level-4 > ul {
|
|
||||||
max-height: 0 !important;
|
|
||||||
}
|
|
||||||
.sidebar-nav .collapse.level-4:hover > ul {
|
|
||||||
max-height: 1000px !important;
|
|
||||||
}
|
|
||||||
.sidebar-nav .folder > .app-sub-sidebar {
|
|
||||||
display: block !important;
|
|
||||||
}
|
|
||||||
/* Ensure levels 1, 2, and 3 are always visible */
|
|
||||||
.sidebar-nav > ul,
|
|
||||||
.sidebar-nav > ul > li > ul,
|
|
||||||
.sidebar-nav > ul > li > ul > li > ul {
|
|
||||||
max-height: none !important;
|
|
||||||
overflow: visible !important;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script>
|
<script>
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
|
name: 'QuanTAlib',
|
||||||
|
repo: 'https://github.com/mihakralj/quantalib',
|
||||||
homepage: 'readme.md',
|
homepage: 'readme.md',
|
||||||
loadSidebar: true,
|
loadSidebar: true,
|
||||||
subMaxLevel: 4, // Increased to allow for level 4+ items
|
auto2top: true,
|
||||||
name: '',
|
mergeNavbar: true,
|
||||||
repo: '',
|
sidebarDisplayLevel: 0, // Add this line to collapse all sidebar items initially
|
||||||
sidebarDisplayLevel: 3, // Changed to keep levels 1, 2, and 3 expanded
|
search: {
|
||||||
|
maxAge: 86400000,
|
||||||
|
paths: 'auto',
|
||||||
|
placeholder: 'Type to search',
|
||||||
|
noData: 'No Results!',
|
||||||
|
depth: 6,
|
||||||
|
hideOtherSidebarContent: false,
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
previousText: 'Previous',
|
||||||
|
nextText: 'Next',
|
||||||
|
crossChapter: true,
|
||||||
|
crossChapterText: true,
|
||||||
|
},
|
||||||
themeable: {
|
themeable: {
|
||||||
readyTransition: true,
|
readyTransition: true,
|
||||||
responsiveTables: true
|
responsiveTables: true
|
||||||
@@ -79,18 +41,33 @@
|
|||||||
latex: {
|
latex: {
|
||||||
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
||||||
displayMath: [['$$', '$$']],
|
displayMath: [['$$', '$$']],
|
||||||
}
|
},
|
||||||
|
executeScript: true,
|
||||||
|
externalLinkTarget: '_blank',
|
||||||
|
cornerExternalLinkTarget: '_blank',
|
||||||
|
relativePath: false,
|
||||||
|
toc: {
|
||||||
|
scope: '.markdown-section',
|
||||||
|
headings: 'h1, h2, h3, h4, h5, h6',
|
||||||
|
title: 'Table of Contents',
|
||||||
|
},
|
||||||
|
copyCode: {
|
||||||
|
buttonText: 'Copy to clipboard',
|
||||||
|
errorText: 'Error',
|
||||||
|
successText: 'Copied'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
]
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<!-- plugins -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify-sidebar-collapse/dist/docsify-sidebar-collapse.min.js" integrity="sha384-lMHOyuqf3B/T/BgfYxUKprN0bdRf8KhVTE11w76Tvtze86XHVSDYzxqNGDGgIi9I" crossorigin="anonymous"></script>
|
|
||||||
<!-- Docsify v4 -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/docsify.min.js" integrity="sha384-KaHhgnx/OTLoJ4J33SSJsF4x1pk4I7q3s5ZOfIDHJYl6IG7Oyn2vNDsHiWJe46fD" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/docsify.min.js" integrity="sha384-KaHhgnx/OTLoJ4J33SSJsF4x1pk4I7q3s5ZOfIDHJYl6IG7Oyn2vNDsHiWJe46fD" crossorigin="anonymous"></script>
|
||||||
<!-- docsify-themeable -->
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js" integrity="sha384-ibjVZCUwWPrRrNc9BNkbbJvtYmTh8GYDNQgj+2jQVNDudOFgSQWs+Es6JhdoTIvf" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js" integrity="sha384-ibjVZCUwWPrRrNc9BNkbbJvtYmTh8GYDNQgj+2jQVNDudOFgSQWs+Es6JhdoTIvf" crossorigin="anonymous"></script>
|
||||||
<!-- KaTeX -->
|
<script src="https://cdn.jsdelivr.net/npm/docsify-sidebar-collapse/dist/docsify-sidebar-collapse.min.js" integrity="sha384-lMHOyuqf3B/T/BgfYxUKprN0bdRf8KhVTE11w76Tvtze86XHVSDYzxqNGDGgIi9I" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.7/dist/katex.min.js" integrity="sha384-G0zcxDFp5LWZtDuRMnBkk3EphCK1lhEf4UEyEM693ka574TZGwo4IWwS6QLzM/2t" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
|
||||||
<!-- docsify-katex plugin -->
|
<script src="https://cdn.jsdelivr.net/npm/docsify-copy-code/dist/docsify-copy-code.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify-pagination/dist/docsify-pagination.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/zoom-image.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify-tabs/dist/docsify-tabs.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify-katex@1.4.3/dist/docsify-katex.js" integrity="sha384-M76M/x5vGyeoej1covQQifl7T945mY+qgzNVrM/urHMCYjP8tnMsx5WCdeLZ74UE" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/docsify-katex@1.4.3/dist/docsify-katex.js" integrity="sha384-M76M/x5vGyeoej1covQQifl7T945mY+qgzNVrM/urHMCYjP8tnMsx5WCdeLZ74UE" crossorigin="anonymous"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+1602
File diff suppressed because it is too large
Load Diff
+57
-6
@@ -2,10 +2,11 @@ namespace QuanTAlib;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// EMA: Exponential Moving Average
|
/// EMA: Exponential Moving Average
|
||||||
/// EMA needs very short history buffer and calculates the EMA value using just the
|
|
||||||
/// previous EMA value. The weight of the new datapoint (alpha) is alpha = 2 / (period + 1)
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
/// EMA needs very short history buffer and calculates the EMA value using just the
|
||||||
|
/// previous EMA value. The weight of the new datapoint (alpha) is alpha = 2 / (period + 1)
|
||||||
|
///
|
||||||
/// Key characteristics:
|
/// Key characteristics:
|
||||||
/// - Uses no buffer, relying only on the previous EMA value.
|
/// - Uses no buffer, relying only on the previous EMA value.
|
||||||
/// - The weight of new data points is calculated as alpha = 2 / (period + 1).
|
/// - The weight of new data points is calculated as alpha = 2 / (period + 1).
|
||||||
@@ -19,19 +20,52 @@ namespace QuanTAlib;
|
|||||||
/// - https://www.investopedia.com/ask/answers/122314/what-exponential-moving-average-ema-formula-and-how-ema-calculated.asp
|
/// - https://www.investopedia.com/ask/answers/122314/what-exponential-moving-average-ema-formula-and-how-ema-calculated.asp
|
||||||
/// - https://blog.fugue88.ws/archives/2017-01/The-correct-way-to-start-an-Exponential-Moving-Average-EMA
|
/// - https://blog.fugue88.ws/archives/2017-01/The-correct-way-to-start-an-Exponential-Moving-Average-EMA
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
public class Ema : AbstractBase
|
public class Ema : AbstractBase
|
||||||
{
|
{
|
||||||
// inherited _index
|
// inherited _index
|
||||||
// inherited _value
|
// inherited _value
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The period for the EMA calculation.
|
||||||
|
/// </summary>
|
||||||
private readonly int _period;
|
private readonly int _period;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Circular buffer for SMA calculation.
|
||||||
|
/// </summary>
|
||||||
private CircularBuffer _sma;
|
private CircularBuffer _sma;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The last calculated EMA value.
|
||||||
|
/// </summary>
|
||||||
private double _lastEma, _p_lastEma;
|
private double _lastEma, _p_lastEma;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compensator for early EMA values.
|
||||||
|
/// </summary>
|
||||||
private double _e, _p_e;
|
private double _e, _p_e;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The smoothing factor for EMA calculation.
|
||||||
|
/// </summary>
|
||||||
private readonly double _k;
|
private readonly double _k;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Flags to track initialization status.
|
||||||
|
/// </summary>
|
||||||
private bool _isInit, _p_isInit;
|
private bool _isInit, _p_isInit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Flag to determine whether to use SMA for initial values.
|
||||||
|
/// </summary>
|
||||||
private readonly bool _useSma;
|
private readonly bool _useSma;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Ema class with a specified period.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="period">The period for EMA calculation.</param>
|
||||||
|
/// <param name="useSma">Whether to use SMA for initial values. Default is true.</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||||
public Ema(int period, bool useSma = true)
|
public Ema(int period, bool useSma = true)
|
||||||
{
|
{
|
||||||
if (period < 1)
|
if (period < 1)
|
||||||
@@ -47,6 +81,10 @@ public class Ema : AbstractBase
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Ema class with a specified alpha value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="alpha">The smoothing factor for EMA calculation.</param>
|
||||||
public Ema(double alpha)
|
public Ema(double alpha)
|
||||||
{
|
{
|
||||||
_k = alpha;
|
_k = alpha;
|
||||||
@@ -57,13 +95,21 @@ public class Ema : AbstractBase
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Ema class with a specified source and period.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">The source object for event subscription.</param>
|
||||||
|
/// <param name="period">The period for EMA calculation.</param>
|
||||||
|
/// <param name="useSma">Whether to use SMA for initial values. Default is true.</param>
|
||||||
public Ema(object source, int period, bool useSma = true) : this(period, useSma)
|
public Ema(object source, int period, bool useSma = true) : this(period, useSma)
|
||||||
{
|
{
|
||||||
var pubEvent = source.GetType().GetEvent("Pub");
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
||||||
}
|
}
|
||||||
//inhereted public void Sub(object source, in ValueEventArgs args)
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the Ema instance.
|
||||||
|
/// </summary>
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
base.Init();
|
base.Init();
|
||||||
@@ -74,6 +120,10 @@ public class Ema : AbstractBase
|
|||||||
_sma = new(_period);
|
_sma = new(_period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Manages the state of the Ema instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isNew">Indicates whether the input is new.</param>
|
||||||
protected override void ManageState(bool isNew)
|
protected override void ManageState(bool isNew)
|
||||||
{
|
{
|
||||||
if (isNew)
|
if (isNew)
|
||||||
@@ -92,8 +142,9 @@ public class Ema : AbstractBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Core EMA calculation
|
/// Performs the EMA calculation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <returns>The calculated EMA value.</returns>
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
{
|
{
|
||||||
double result, _ema;
|
double result, _ema;
|
||||||
@@ -118,7 +169,7 @@ public class Ema : AbstractBase
|
|||||||
_ema = _k * (Input.Value - _lastEma) + _lastEma;
|
_ema = _k * (Input.Value - _lastEma) + _lastEma;
|
||||||
|
|
||||||
// _useSma decides if we use compensator or not
|
// _useSma decides if we use compensator or not
|
||||||
result = (_useSma || _e == 0) ? _ema : _ema / (1 - _e);
|
result = (_useSma || _e <= double.Epsilon) ? _ema : _ema / (1 - _e);
|
||||||
}
|
}
|
||||||
_lastEma = _ema;
|
_lastEma = _ema;
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
|
|||||||
+85
-61
@@ -1,68 +1,91 @@
|
|||||||
|
/// <summary>
|
||||||
|
/// Represents a Jurik Moving Average, based on known and reverse-engineered insights
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
namespace QuanTAlib;
|
namespace QuanTAlib;
|
||||||
//TODO fails consistency test
|
|
||||||
public class Jma : AbstractBase
|
public class Jma : AbstractBase
|
||||||
{
|
{
|
||||||
public readonly int Period;
|
private readonly int _period;
|
||||||
private readonly double _phase;
|
private readonly double _phase;
|
||||||
private readonly int _vshort, _vlong;
|
|
||||||
private readonly CircularBuffer _values;
|
|
||||||
private readonly CircularBuffer _voltyShort;
|
|
||||||
private readonly CircularBuffer _vsumBuff;
|
private readonly CircularBuffer _vsumBuff;
|
||||||
private readonly CircularBuffer _avoltyBuff;
|
private readonly CircularBuffer _avoltyBuff;
|
||||||
|
|
||||||
private double _beta, _len1, _pow1;
|
private double _len1;
|
||||||
private double _upperBand, _lowerBand, _prevMa1, _prevDet0, _prevDet1, _prevJma;
|
private double _pow1;
|
||||||
private double _p_UpperBand, _p_LowerBand, _p_prevMa1, _p_prevDet0, _p_prevDet1, _p_prevJma;
|
private readonly double _beta;
|
||||||
|
private double _upperBand, _lowerBand, _p_upperBand, _p_lowerBand;
|
||||||
|
private double _prevMa1, _prevDet0, _prevDet1, _prevJma, _p_prevMa1, _p_prevDet0, _p_prevDet1, _p_prevJma;
|
||||||
|
private double _vSum, _p_vSum;
|
||||||
|
|
||||||
public Jma(int period, double phase = 0, int vshort = 10)
|
|
||||||
|
public double UpperBand { get; set; }
|
||||||
|
public double LowerBand { get; set; }
|
||||||
|
public double Volty { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Jma class with the specified parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="period">The period over which to calculate the Jvolty.</param>
|
||||||
|
/// <param name="phase">The phase parameter for the JMA-style calculation.</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// Thrown when period is less than 1.
|
||||||
|
/// </exception>
|
||||||
|
public Jma(int period, int phase = 0)
|
||||||
{
|
{
|
||||||
if (period < 1)
|
if (period < 1)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
||||||
}
|
}
|
||||||
Period = period;
|
_period = period;
|
||||||
_vshort = vshort;
|
|
||||||
_vlong = 65;
|
|
||||||
_phase = Math.Clamp((phase * 0.01) + 1.5, 0.5, 2.5);
|
_phase = Math.Clamp((phase * 0.01) + 1.5, 0.5, 2.5);
|
||||||
|
|
||||||
_values = new CircularBuffer(period);
|
_vsumBuff = new CircularBuffer(10);
|
||||||
_voltyShort = new CircularBuffer(vshort);
|
_avoltyBuff = new CircularBuffer(65);
|
||||||
_vsumBuff = new CircularBuffer(_vlong);
|
_beta = 0.45 * (period - 1) / (0.45 * (period - 1) + 2);
|
||||||
_avoltyBuff = new CircularBuffer(2);
|
|
||||||
|
|
||||||
Name = "JMA";
|
|
||||||
WarmupPeriod = period * 2;
|
WarmupPeriod = period * 2;
|
||||||
Init();
|
Name = $"JMA({period})";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jma(object source, int period, double phase = 0, int vshort = 10) : this(period, phase, vshort)
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Jvolty class with the specified source and parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">The source object to subscribe to for value updates.</param>
|
||||||
|
/// <param name="period">The period over which to calculate the Jvolty.</param>
|
||||||
|
/// <param name="phase">The phase parameter for the JMA-style calculation.</param>
|
||||||
|
public Jma(object source, int period, int phase = 0) : this(period, phase)
|
||||||
{
|
{
|
||||||
var pubEvent = source.GetType().GetEvent("Pub");
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the Jma instance by setting up the initial state.
|
||||||
|
/// </summary>
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
_upperBand = _lowerBand = _prevMa1 = _prevDet0 = _prevDet1 = _prevJma = 0.0;
|
base.Init();
|
||||||
_p_UpperBand = _p_LowerBand = _p_prevMa1 = _p_prevDet0 = _p_prevDet1 = _p_prevJma = 0.0;
|
_upperBand = _lowerBand = 0.0;
|
||||||
_beta = 0.45 * (Period - 1) / (0.45 * (Period - 1) + 2);
|
_p_upperBand = _p_lowerBand = 0.0;
|
||||||
_len1 = Math.Max((Math.Log(Math.Sqrt(Period - 1)) / Math.Log(2.0)) + 2.0, 0);
|
_len1 = Math.Max((Math.Log(Math.Sqrt(_period - 1)) / Math.Log(2.0)) + 2.0, 0);
|
||||||
_pow1 = Math.Max(_len1 - 2.0, 0.5);
|
_pow1 = Math.Max(_len1 - 2.0, 0.5);
|
||||||
_avoltyBuff.Clear();
|
_avoltyBuff.Clear();
|
||||||
_avoltyBuff.Add(0, true);
|
_vsumBuff.Clear();
|
||||||
_avoltyBuff.Add(0, true);
|
|
||||||
base.Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Manages the state of the Jma instance based on whether a new value is being processed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isNew">Indicates whether the current input is a new value.</param>
|
||||||
protected override void ManageState(bool isNew)
|
protected override void ManageState(bool isNew)
|
||||||
{
|
{
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
_lastValidValue = Input.Value;
|
|
||||||
_index++;
|
_index++;
|
||||||
// Save current state
|
_p_upperBand = _upperBand;
|
||||||
_p_UpperBand = _upperBand;
|
_p_lowerBand = _lowerBand;
|
||||||
_p_LowerBand = _lowerBand;
|
_p_vSum = _vSum;
|
||||||
_p_prevMa1 = _prevMa1;
|
_p_prevMa1 = _prevMa1;
|
||||||
_p_prevDet0 = _prevDet0;
|
_p_prevDet0 = _prevDet0;
|
||||||
_p_prevDet1 = _prevDet1;
|
_p_prevDet1 = _prevDet1;
|
||||||
@@ -70,67 +93,68 @@ public class Jma : AbstractBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Restore previous state
|
_upperBand = _p_upperBand;
|
||||||
_upperBand = _p_UpperBand;
|
_lowerBand = _p_lowerBand;
|
||||||
_lowerBand = _p_LowerBand;
|
_vSum = _p_vSum;
|
||||||
_prevMa1 = _p_prevMa1;
|
_prevMa1 = _p_prevMa1;
|
||||||
_prevDet0 = _p_prevDet0;
|
_prevDet0 = _p_prevDet0;
|
||||||
_prevDet1 = _p_prevDet1;
|
_prevDet1 = _p_prevDet1;
|
||||||
_prevJma = _p_prevJma;
|
_prevJma = _p_prevJma;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs the Jma calculation for the current value.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The calculated Jma value for the current input.
|
||||||
|
/// </returns>
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
{
|
{
|
||||||
ManageState(Input.IsNew);
|
ManageState(Input.IsNew);
|
||||||
|
|
||||||
_values.Add(Input.Value, Input.IsNew);
|
double price = Input.Value;
|
||||||
|
|
||||||
if (_index == 1)
|
if (_index == 1)
|
||||||
{
|
{
|
||||||
_prevMa1 = _prevJma = Input.Value;
|
_upperBand = _lowerBand = price;
|
||||||
return Input.Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double hprice = _values.Max();
|
double del1 = price - _upperBand;
|
||||||
double lprice = _values.Min();
|
double del2 = price - _lowerBand;
|
||||||
|
|
||||||
double del1 = hprice - _upperBand;
|
|
||||||
double del2 = lprice - _lowerBand;
|
|
||||||
double volty = Math.Max(Math.Abs(del1), Math.Abs(del2));
|
double volty = Math.Max(Math.Abs(del1), Math.Abs(del2));
|
||||||
|
|
||||||
_voltyShort.Add(volty, Input.IsNew);
|
_vsumBuff.Add(volty, Input.IsNew);
|
||||||
double vsum = _vsumBuff.Newest() + 0.1 * (volty - _voltyShort.Oldest());
|
_vSum += (_vsumBuff[^1] - _vsumBuff[0]) / 10;
|
||||||
_vsumBuff.Add(vsum, Input.IsNew);
|
_avoltyBuff.Add(_vSum, Input.IsNew);
|
||||||
|
double avgvolty = _avoltyBuff.Average();
|
||||||
|
|
||||||
double prevAvolty = _avoltyBuff.Newest();
|
double rvolty = (avgvolty > 0) ? volty / avgvolty : 1;
|
||||||
double avolty = prevAvolty + 2.0 / (Math.Max(4.0 * Period, 30) + 1.0) * (vsum - prevAvolty);
|
rvolty = Math.Min(Math.Max(rvolty, 1.0), Math.Pow(_len1, 1.0 / _pow1));
|
||||||
_avoltyBuff.Add(avolty, Input.IsNew);
|
|
||||||
|
|
||||||
double dVolty = (avolty > 0) ? volty / avolty : 0;
|
double pow2 = Math.Pow(rvolty, _pow1);
|
||||||
dVolty = Math.Min(Math.Max(dVolty, 1.0), Math.Pow(_len1, 1.0 / _pow1));
|
double Kv = Math.Pow(_beta, Math.Sqrt(pow2));
|
||||||
|
|
||||||
double pow2 = Math.Pow(dVolty, _pow1);
|
_upperBand = (del1 >= 0) ? price : price - (Kv * del1);
|
||||||
double len2 = Math.Sqrt(0.5 * (Period - 1)) * _len1;
|
_lowerBand = (del2 <= 0) ? price : price - (Kv * del2);
|
||||||
double _Kv = Math.Pow(len2 / (len2 + 1), Math.Sqrt(pow2));
|
|
||||||
|
|
||||||
_upperBand = (del1 > 0) ? hprice : hprice - (_Kv * del1);
|
|
||||||
_lowerBand = (del2 < 0) ? lprice : lprice - (_Kv * del2);
|
|
||||||
|
|
||||||
double alpha = Math.Pow(_beta, pow2);
|
double alpha = Math.Pow(_beta, pow2);
|
||||||
double ma1 = (1 - alpha) * Input.Value + alpha * _prevMa1;
|
double ma1 = (1 - alpha) * Input.Value + alpha * _prevMa1;
|
||||||
_prevMa1 = ma1;
|
_prevMa1 = ma1;
|
||||||
|
|
||||||
double det0 = (1 - _beta) * (Input.Value - ma1) + _beta * _prevDet0;
|
double det0 = (price - ma1) * (1 - _beta) + _beta * _prevDet0;
|
||||||
_prevDet0 = det0;
|
_prevDet0 = det0;
|
||||||
double ma2 = ma1 + (_phase + 1) * det0;
|
double ma2 = ma1 + _phase * det0;
|
||||||
|
|
||||||
double det1 = ((1 - alpha) * (1 - alpha) * (ma2 - _prevJma)) + (alpha * alpha * _prevDet1);
|
double det1 = ((ma2 - _prevJma) * (1 - alpha) * (1 - alpha) ) + (alpha * alpha * _prevDet1);
|
||||||
_prevDet1 = det1;
|
_prevDet1 = det1;
|
||||||
double jma = _prevJma + det1;
|
double jma = _prevJma + det1;
|
||||||
_prevJma = jma;
|
_prevJma = jma;
|
||||||
|
|
||||||
|
UpperBand = _upperBand;
|
||||||
|
LowerBand = _lowerBand;
|
||||||
|
Volty = volty;
|
||||||
|
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return jma;
|
return jma;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+70
-38
@@ -7,17 +7,25 @@ namespace QuanTAlib;
|
|||||||
public class Jvolty : AbstractBase
|
public class Jvolty : AbstractBase
|
||||||
{
|
{
|
||||||
private readonly int _period;
|
private readonly int _period;
|
||||||
private readonly CircularBuffer _values;
|
private readonly double _phase;
|
||||||
private readonly CircularBuffer _voltyShort;
|
|
||||||
private readonly CircularBuffer _vsumBuff;
|
private readonly CircularBuffer _vsumBuff;
|
||||||
private readonly CircularBuffer _avoltyBuff;
|
private readonly CircularBuffer _avoltyBuff;
|
||||||
|
|
||||||
private double _len1;
|
private double _len1;
|
||||||
private double _pow1;
|
private double _pow1;
|
||||||
private double _upperBand;
|
private readonly double _beta;
|
||||||
private double _lowerBand;
|
private double _upperBand, _lowerBand, _p_upperBand, _p_lowerBand;
|
||||||
private double _p_upperBand;
|
private double _prevMa1, _prevDet0, _prevDet1, _prevJma, _p_prevMa1, _p_prevDet0, _p_prevDet1, _p_prevJma;
|
||||||
private double _p_lowerBand;
|
private double _vSum, _p_vSum;
|
||||||
|
|
||||||
|
|
||||||
|
public double UpperBand { get; set; }
|
||||||
|
public double LowerBand { get; set; }
|
||||||
|
public double Volty { get; set; }
|
||||||
|
public double VSum { get; set; }
|
||||||
|
public double Jma { get; set; }
|
||||||
|
public double AvgVolty { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the Jvolty class with the specified parameters.
|
/// Initializes a new instance of the Jvolty class with the specified parameters.
|
||||||
@@ -28,22 +36,21 @@ public class Jvolty : AbstractBase
|
|||||||
/// <exception cref="ArgumentOutOfRangeException">
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
/// Thrown when period is less than 1.
|
/// Thrown when period is less than 1.
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public Jvolty(int period, int vshort = 10)
|
public Jvolty(int period, int phase = 0)
|
||||||
{
|
{
|
||||||
if (period < 1)
|
if (period < 1)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
||||||
}
|
}
|
||||||
_period = period;
|
_period = period;
|
||||||
int _vlong = 65;
|
_phase = Math.Clamp((phase * 0.01) + 1.5, 0.5, 2.5);
|
||||||
|
|
||||||
_values = new CircularBuffer(period);
|
_vsumBuff = new CircularBuffer(10);
|
||||||
_voltyShort = new CircularBuffer(vshort);
|
_avoltyBuff = new CircularBuffer(65);
|
||||||
_vsumBuff = new CircularBuffer(_vlong);
|
_beta = 0.45 * (period - 1) / (0.45 * (period - 1) + 2);
|
||||||
_avoltyBuff = new CircularBuffer(2);
|
|
||||||
|
|
||||||
WarmupPeriod = period * 2;
|
WarmupPeriod = period * 2;
|
||||||
Name = $"JVOLTY({period},{vshort})";
|
Name = $"JVOLTY({period})";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -53,7 +60,7 @@ public class Jvolty : AbstractBase
|
|||||||
/// <param name="period">The period over which to calculate the Jvolty.</param>
|
/// <param name="period">The period over which to calculate the Jvolty.</param>
|
||||||
/// <param name="phase">The phase parameter for the JMA-style calculation.</param>
|
/// <param name="phase">The phase parameter for the JMA-style calculation.</param>
|
||||||
/// <param name="vshort">The short-term volatility period.</param>
|
/// <param name="vshort">The short-term volatility period.</param>
|
||||||
public Jvolty(object source, int period, int vshort = 10) : this(period, vshort)
|
public Jvolty(object source, int period, int phase = 0) : this(period, phase)
|
||||||
{
|
{
|
||||||
var pubEvent = source.GetType().GetEvent("Pub");
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
@@ -70,8 +77,7 @@ public class Jvolty : AbstractBase
|
|||||||
_len1 = Math.Max((Math.Log(Math.Sqrt(_period - 1)) / Math.Log(2.0)) + 2.0, 0);
|
_len1 = Math.Max((Math.Log(Math.Sqrt(_period - 1)) / Math.Log(2.0)) + 2.0, 0);
|
||||||
_pow1 = Math.Max(_len1 - 2.0, 0.5);
|
_pow1 = Math.Max(_len1 - 2.0, 0.5);
|
||||||
_avoltyBuff.Clear();
|
_avoltyBuff.Clear();
|
||||||
_avoltyBuff.Add(0, true);
|
_vsumBuff.Clear();
|
||||||
_avoltyBuff.Add(0, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -85,11 +91,21 @@ public class Jvolty : AbstractBase
|
|||||||
_index++;
|
_index++;
|
||||||
_p_upperBand = _upperBand;
|
_p_upperBand = _upperBand;
|
||||||
_p_lowerBand = _lowerBand;
|
_p_lowerBand = _lowerBand;
|
||||||
|
_p_vSum = _vSum;
|
||||||
|
_p_prevMa1 = _prevMa1;
|
||||||
|
_p_prevDet0 = _prevDet0;
|
||||||
|
_p_prevDet1 = _prevDet1;
|
||||||
|
_p_prevJma = _prevJma;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_upperBand = _p_upperBand;
|
_upperBand = _p_upperBand;
|
||||||
_lowerBand = _p_lowerBand;
|
_lowerBand = _p_lowerBand;
|
||||||
|
_vSum = _p_vSum;
|
||||||
|
_prevMa1 = _p_prevMa1;
|
||||||
|
_prevDet0 = _p_prevDet0;
|
||||||
|
_prevDet1 = _p_prevDet1;
|
||||||
|
_prevJma = _p_prevJma;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,41 +117,57 @@ public class Jvolty : AbstractBase
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
{
|
{
|
||||||
ManageState(BarInput.IsNew);
|
ManageState(Input.IsNew);
|
||||||
|
|
||||||
_values.Add(BarInput.Close, BarInput.IsNew);
|
|
||||||
|
|
||||||
|
double price = Input.Value;
|
||||||
if (_index == 1)
|
if (_index == 1)
|
||||||
{
|
{
|
||||||
return 0;
|
_upperBand = _lowerBand = price;
|
||||||
}
|
}
|
||||||
|
|
||||||
double hprice = _values.Max();
|
double del1 = price - _upperBand;
|
||||||
double lprice = _values.Min();
|
double del2 = price - _lowerBand;
|
||||||
|
|
||||||
double del1 = hprice - _upperBand;
|
|
||||||
double del2 = lprice - _lowerBand;
|
|
||||||
double volty = Math.Max(Math.Abs(del1), Math.Abs(del2));
|
double volty = Math.Max(Math.Abs(del1), Math.Abs(del2));
|
||||||
|
|
||||||
_voltyShort.Add(volty, BarInput.IsNew);
|
_vsumBuff.Add(volty, Input.IsNew);
|
||||||
double vsum = _vsumBuff.Newest() + 0.1 * (volty - _voltyShort.Oldest());
|
_vSum += (_vsumBuff[^1] - _vsumBuff[0]) / 10;
|
||||||
_vsumBuff.Add(vsum, BarInput.IsNew);
|
_avoltyBuff.Add(_vSum, Input.IsNew);
|
||||||
|
double avgvolty = _avoltyBuff.Average();
|
||||||
|
|
||||||
double prevAvolty = _avoltyBuff.Newest();
|
double rvolty = (avgvolty > 0) ? volty / avgvolty : 1;
|
||||||
double avolty = prevAvolty + 2.0 / (Math.Max(4.0 * _period, 30) + 1.0) * (vsum - prevAvolty);
|
rvolty = Math.Min(Math.Max(rvolty, 1.0), Math.Pow(_len1, 1.0 / _pow1));
|
||||||
_avoltyBuff.Add(avolty, BarInput.IsNew);
|
|
||||||
|
|
||||||
double dVolty = (avolty > 0) ? volty / avolty : 0;
|
double pow2 = Math.Pow(rvolty, _pow1);
|
||||||
dVolty = Math.Min(Math.Max(dVolty, 1.0), Math.Pow(_len1, 1.0 / _pow1));
|
double Kv = Math.Pow(_beta, Math.Sqrt(pow2));
|
||||||
|
|
||||||
double pow2 = Math.Pow(dVolty, _pow1);
|
_upperBand = (del1 >= 0) ? price : price - (Kv * del1);
|
||||||
double len2 = Math.Sqrt(0.5 * (_period - 1)) * _len1;
|
_lowerBand = (del2 <= 0) ? price : price - (Kv * del2);
|
||||||
double Kv = Math.Pow(len2 / (len2 + 1), Math.Sqrt(pow2));
|
|
||||||
|
|
||||||
_upperBand = (del1 > 0) ? hprice : hprice - (Kv * del1);
|
|
||||||
_lowerBand = (del2 < 0) ? lprice : lprice - (Kv * del2);
|
|
||||||
|
double alpha = Math.Pow(_beta, pow2);
|
||||||
|
double ma1 = (1 - alpha) * Input.Value + alpha * _prevMa1;
|
||||||
|
_prevMa1 = ma1;
|
||||||
|
|
||||||
|
double det0 = (price - ma1) * (1 - _beta) + _beta * _prevDet0;
|
||||||
|
_prevDet0 = det0;
|
||||||
|
double ma2 = ma1 + _phase * det0;
|
||||||
|
|
||||||
|
double det1 = ((ma2 - _prevJma) * (1 - alpha) * (1 - alpha) ) + (alpha * alpha * _prevDet1);
|
||||||
|
_prevDet1 = det1;
|
||||||
|
double jma = _prevJma + det1;
|
||||||
|
_prevJma = jma;
|
||||||
|
|
||||||
|
UpperBand = _upperBand;
|
||||||
|
LowerBand = _lowerBand;
|
||||||
|
Volty = volty;
|
||||||
|
VSum = _vSum;
|
||||||
|
AvgVolty = avgvolty;
|
||||||
|
Jma = jma;
|
||||||
|
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return volty;
|
return volty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
## OHLC Input (Open, High, Low, Close)
|
## OHLC Input (Open, High, Low, Close)
|
||||||
|
|
||||||
|
- **Average True Range (ATR) (High, Low, Close)**
|
||||||
- Garman-Klass Volatility
|
- Garman-Klass Volatility
|
||||||
- Rogers-Satchell Volatility
|
- Rogers-Satchell Volatility
|
||||||
- Yang-Zhang Volatility
|
- Yang-Zhang Volatility
|
||||||
- Parkinson Volatility (High, Low)
|
- Parkinson Volatility (High, Low)
|
||||||
- Average True Range (ATR) (High, Low, Close)
|
|
||||||
- Chaikin Volatility (High, Low)
|
- Chaikin Volatility (High, Low)
|
||||||
- Keltner Channels (typically Close, High, Low)
|
- Keltner Channels (typically Close, High, Low)
|
||||||
- High-Low Volatility (High, Low)
|
- High-Low Volatility (High, Low)
|
||||||
|
|||||||
+90
-69
@@ -82,58 +82,77 @@ TSeries MarketJMA = new() { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|||||||
|
|
||||||
#!csharp
|
#!csharp
|
||||||
|
|
||||||
public class Jma1 : AbstractBase
|
public class Jmaxx : AbstractBase
|
||||||
{
|
{
|
||||||
public readonly int Period;
|
private readonly double _period;
|
||||||
private readonly double _phase;
|
private readonly double _phase;
|
||||||
private readonly int _vshort, _vlong;
|
private readonly CircularBuffer _vsumBuff;
|
||||||
private CircularBuffer _voltyShort;
|
private readonly CircularBuffer _avoltyBuff;
|
||||||
private CircularBuffer _vsumBuff;
|
|
||||||
private CircularBuffer _avoltyBuff;
|
|
||||||
|
|
||||||
private double _beta, _len1, _pow1;
|
private double _len1;
|
||||||
private double _upperBand, _lowerBand, _prevMa1, _prevDet0, _prevDet1, _prevJma;
|
private double _pow1;
|
||||||
private double _p_UpperBand, _p_LowerBand, _p_prevMa1, _p_prevDet0, _p_prevDet1, _p_prevJma;
|
private readonly double _beta;
|
||||||
|
private double _upperBand, _lowerBand, _p_upperBand, _p_lowerBand;
|
||||||
|
private double _prevMa1, _prevDet0, _prevDet1, _prevJma, _p_prevMa1, _p_prevDet0, _p_prevDet1, _p_prevJma;
|
||||||
|
private double _vSum, _p_vSum;
|
||||||
|
|
||||||
public Jma1(int period, double phase = 0, int vshort = 10) : base()
|
|
||||||
|
public double UpperBand { get; set; }
|
||||||
|
public double LowerBand { get; set; }
|
||||||
|
public double Volty { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Jma class with the specified parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="period">The period over which to calculate the Jvolty.</param>
|
||||||
|
/// <param name="phase">The phase parameter for the JMA-style calculation.</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// Thrown when period is less than 1.
|
||||||
|
/// </exception>
|
||||||
|
public Jmaxx(int period, int phase = 0)
|
||||||
{
|
{
|
||||||
if (period < 1)
|
if (period < 1)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
|
||||||
}
|
}
|
||||||
Period = period;
|
_period = period;
|
||||||
_vshort = vshort;
|
|
||||||
_vlong = 65;
|
|
||||||
_phase = Math.Clamp((phase * 0.01) + 1.5, 0.5, 2.5);
|
_phase = Math.Clamp((phase * 0.01) + 1.5, 0.5, 2.5);
|
||||||
|
|
||||||
_voltyShort = new CircularBuffer(vshort);
|
_vsumBuff = new CircularBuffer(10);
|
||||||
_vsumBuff = new CircularBuffer(_vlong);
|
_avoltyBuff = new CircularBuffer(65);
|
||||||
_avoltyBuff = new CircularBuffer(2);
|
_beta = 0.45 * (_period - 1) / (0.45 * (_period - 1) + 2);
|
||||||
|
|
||||||
Name = "JMA";
|
WarmupPeriod = (int)_period * 2;
|
||||||
WarmupPeriod = period * 2;
|
Name = $"JMA({period})";
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the Jma instance by setting up the initial state.
|
||||||
|
/// </summary>
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
_upperBand = _lowerBand = _prevMa1 = _prevDet0 = _prevDet1 = _prevJma = 0.0;
|
|
||||||
_p_UpperBand = _p_LowerBand = _p_prevMa1 = _p_prevDet0 = _p_prevDet1 = _p_prevJma = 0.0;
|
|
||||||
_avoltyBuff.Clear();
|
|
||||||
_avoltyBuff.Add(0, true);
|
|
||||||
_avoltyBuff.Add(0, true);
|
|
||||||
base.Init();
|
base.Init();
|
||||||
|
_upperBand = _lowerBand = 0.0;
|
||||||
|
_p_upperBand = _p_lowerBand = 0.0;
|
||||||
|
_len1 = Math.Max((Math.Log(Math.Sqrt(_period - 1)) / Math.Log(2.0)) + 2.0, 0);
|
||||||
|
_pow1 = Math.Max(_len1 - 2.0, 0.5);
|
||||||
|
_avoltyBuff.Clear();
|
||||||
|
_vsumBuff.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Manages the state of the Jma instance based on whether a new value is being processed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isNew">Indicates whether the current input is a new value.</param>
|
||||||
protected override void ManageState(bool isNew)
|
protected override void ManageState(bool isNew)
|
||||||
{
|
{
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
_lastValidValue = Input.Value;
|
|
||||||
_index++;
|
_index++;
|
||||||
// Save current state
|
_p_upperBand = _upperBand;
|
||||||
_p_UpperBand = _upperBand;
|
_p_lowerBand = _lowerBand;
|
||||||
_p_LowerBand = _lowerBand;
|
_p_vSum = _vSum;
|
||||||
_p_prevMa1 = _prevMa1;
|
_p_prevMa1 = _prevMa1;
|
||||||
_p_prevDet0 = _prevDet0;
|
_p_prevDet0 = _prevDet0;
|
||||||
_p_prevDet1 = _prevDet1;
|
_p_prevDet1 = _prevDet1;
|
||||||
@@ -141,66 +160,73 @@ public class Jma1 : AbstractBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Restore previous state
|
_upperBand = _p_upperBand;
|
||||||
_upperBand = _p_UpperBand;
|
_lowerBand = _p_lowerBand;
|
||||||
_lowerBand = _p_LowerBand;
|
_vSum = _p_vSum;
|
||||||
_prevMa1 = _p_prevMa1;
|
_prevMa1 = _p_prevMa1;
|
||||||
_prevDet0 = _p_prevDet0;
|
_prevDet0 = _p_prevDet0;
|
||||||
_prevDet1 = _p_prevDet1;
|
_prevDet1 = _p_prevDet1;
|
||||||
_prevJma = _p_prevJma;
|
_prevJma = _p_prevJma;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs the Jma calculation for the current value.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The calculated Jma value for the current input.
|
||||||
|
/// </returns>
|
||||||
protected override double Calculation()
|
protected override double Calculation()
|
||||||
{
|
{
|
||||||
ManageState(Input.IsNew);
|
ManageState(Input.IsNew);
|
||||||
|
|
||||||
|
double price = Input.Value;
|
||||||
if (_index == 1)
|
if (_index == 1)
|
||||||
{
|
{
|
||||||
_prevMa1 = _prevJma = Input.Value;
|
_upperBand = _lowerBand = price;
|
||||||
return Input.Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double del1 = Input.Value - _upperBand;
|
double del1 = price - _upperBand;
|
||||||
double del2 = Input.Value - _lowerBand;
|
double del2 = price - _lowerBand;
|
||||||
double volty = Math.Max(Math.Abs(del1), Math.Abs(del2));
|
double volty = Math.Max(Math.Abs(del1), Math.Abs(del2));
|
||||||
|
|
||||||
_voltyShort.Add(volty, Input.IsNew);
|
_vsumBuff.Add(volty, Input.IsNew);
|
||||||
double vsum = _vsumBuff.Newest() + 0.1 * (volty - _voltyShort.Oldest());
|
_vSum += (_vsumBuff[^1] - _vsumBuff[0]) / 10;
|
||||||
_vsumBuff.Add(vsum, Input.IsNew);
|
_avoltyBuff.Add(_vSum, Input.IsNew);
|
||||||
|
double avgvolty = _avoltyBuff.Average();
|
||||||
|
|
||||||
double avolty = 0;
|
double rvolty = (avgvolty > 0) ? volty / avgvolty : 1;
|
||||||
for (int i = 0; i < _vsumBuff.Count; i++) { avolty += _vsumBuff[i]; }
|
rvolty = Math.Min(Math.Max(rvolty, 1.0), Math.Pow(_len1, 1.0 / _pow1));
|
||||||
avolty /= _vsumBuff.Count;
|
|
||||||
|
|
||||||
double rVolty = (avolty > 0) ? volty / avolty *20: 0;
|
double pow2 = Math.Pow(rvolty, _pow1);
|
||||||
double _len1 = Math.Max((Math.Log(Math.Sqrt(Period)) / Math.Log(2.0)) + 2.0, 0);
|
double Kv = Math.Pow(_beta, Math.Sqrt(pow2));
|
||||||
double _pow1 = Math.Max(_len1 - 2, 0.5);
|
|
||||||
|
|
||||||
rVolty = Math.Clamp(rVolty, 1.0, Math.Pow(_len1, 1.0 / _pow1));
|
_upperBand = (del1 >= 0) ? price : price - (Kv * del1);
|
||||||
|
_lowerBand = (del2 <= 0) ? price : price - (Kv * del2);
|
||||||
|
|
||||||
double _pow2 = Math.Pow(rVolty, _pow1);
|
|
||||||
double _beta = 0.45 * (Period - 1) / (0.45 * (Period - 1) + 2);
|
|
||||||
double len2 = Math.Sqrt(0.5 * (Period - 1)) * _len1;
|
|
||||||
|
|
||||||
double _Kv = Math.Pow (_beta, Math.Sqrt(_pow2)) *1.5;
|
|
||||||
|
|
||||||
_upperBand = (del1 > 0) ? Input.Value : Input.Value - (_Kv * del1);
|
|
||||||
_lowerBand = (del2 < 0) ? Input.Value : Input.Value - (_Kv * del2);
|
|
||||||
|
|
||||||
double alpha = Math.Pow(_beta, _pow2);
|
|
||||||
double ma1 = alpha * (_prevMa1 - Input.Value) + Input.Value;
|
|
||||||
|
|
||||||
|
double alpha = Math.Pow(_beta, pow2);
|
||||||
|
double ma1 = (1 - alpha) * Input.Value + alpha * _prevMa1;
|
||||||
_prevMa1 = ma1;
|
_prevMa1 = ma1;
|
||||||
|
|
||||||
double det0 = _beta * (_prevDet0 - Input.Value + ma1) + Input.Value - ma1;
|
double det0 = (price - ma1) * (1 - _beta) + _beta * _prevDet0;
|
||||||
_prevDet0 = det0;
|
_prevDet0 = det0;
|
||||||
double ma2 = ma1 + _phase * det0;
|
double ma2 = ma1 + _phase * det0;
|
||||||
|
|
||||||
double det1 = ((1 - alpha) * (1 - alpha) * (ma2 - _prevJma)) + (alpha * alpha * _prevDet1 );
|
double det1 = ((ma2 - _prevJma) * (1 - alpha) * (1 - alpha) ) + (alpha * alpha * _prevDet1);
|
||||||
_prevDet1 = det1;
|
_prevDet1 = det1;
|
||||||
double jma = _prevJma + det1;
|
double jma = _prevJma + det1;
|
||||||
_prevJma = jma;
|
_prevJma = jma;
|
||||||
|
|
||||||
|
UpperBand = _upperBand;
|
||||||
|
LowerBand = _lowerBand;
|
||||||
|
Volty = volty;
|
||||||
|
|
||||||
IsHot = _index >= WarmupPeriod;
|
IsHot = _index >= WarmupPeriod;
|
||||||
return jma;
|
return jma;
|
||||||
}
|
}
|
||||||
@@ -208,22 +234,17 @@ public class Jma1 : AbstractBase
|
|||||||
|
|
||||||
#!csharp
|
#!csharp
|
||||||
|
|
||||||
TSeries ma = Triangle;
|
TSeries ma = Complex;
|
||||||
TSeries re = TriangleJMA;
|
TSeries re = ComplexJMA;
|
||||||
TSeries out1 = new();
|
TSeries out1 = new();
|
||||||
TSeries out2 = new();
|
|
||||||
Jma calc = new(10);
|
Jmaxx calc = new(10);
|
||||||
Jma1 calc1 = new(10);
|
|
||||||
foreach (var value in ma) { out1.Add(calc.Calc(value)); }
|
foreach (var value in ma) { out1.Add(calc.Calc(value)); }
|
||||||
foreach (var value in ma) { out2.Add(calc1.Calc(value)); }
|
|
||||||
Plot plt = new();
|
Plot plt = new();
|
||||||
var sigplot = plt.Add.Signal(ma.v.ToArray()[60..80]);
|
var sigplot = plt.Add.Signal(ma.v.ToArray()[60..80]);
|
||||||
var jmaplot = plt.Add.Signal(re.v.ToArray()[60..80]); sigplot.Color = ScottPlot.Colors.Red; sigplot.LineWidth = 2; jmaplot.LineWidth = 3;
|
var jmaplot = plt.Add.Signal(re.v.ToArray()[60..80]); sigplot.Color = ScottPlot.Colors.Red; sigplot.LineWidth = 2; jmaplot.LineWidth = 3;
|
||||||
//var jma1plot = plt.Add.Signal(out1.v.ToArray()[60..80]); jma1plot.Color = ScottPlot.Colors.Purple; jma1plot.LineWidth = 3;
|
var jma1plot = plt.Add.Signal(out1.v.ToArray()[60..80]); jma1plot.Color = ScottPlot.Colors.Purple; jma1plot.LineWidth = 3;
|
||||||
var jma2plot = plt.Add.Signal(out2.v.ToArray()[60..80]); jma2plot.Color = ScottPlot.Colors.Blue; jma2plot.LineWidth = 3;
|
|
||||||
plt.Display();
|
plt.Display();
|
||||||
|
|
||||||
#!csharp
|
|
||||||
|
|
||||||
#r "nuget: Plotly.net.Interactive"
|
|
||||||
using Plotly.NET.Interactive;
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class JmaIndicator : Indicator, IWatchlistIndicator
|
|||||||
public int Periods { get; set; } = 10;
|
public int Periods { get; set; } = 10;
|
||||||
|
|
||||||
[InputParameter("Phase", sortIndex: 2, -100, 100, 1, 0)]
|
[InputParameter("Phase", sortIndex: 2, -100, 100, 1, 0)]
|
||||||
public double Phase { get; set; } = 0;
|
public int Phase { get; set; } = 0;
|
||||||
|
|
||||||
[InputParameter("Data source", sortIndex: 4, variants: [
|
[InputParameter("Data source", sortIndex: 4, variants: [
|
||||||
"Open", SourceType.Open,
|
"Open", SourceType.Open,
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Drawing;
|
||||||
|
using TradingPlatform.BusinessLayer;
|
||||||
|
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
public class MacdIndicator : Indicator, IWatchlistIndicator
|
||||||
|
{
|
||||||
|
[InputParameter("Slow EMA", sortIndex: 1, 1, 1000, 1, 0)]
|
||||||
|
public int Slow { get; set; } = 26;
|
||||||
|
|
||||||
|
[InputParameter("Fast EMA", sortIndex: 2, 1, 2000, 1, 0)]
|
||||||
|
public int Fast { get; set; } = 12;
|
||||||
|
|
||||||
|
[InputParameter("Signal line", sortIndex: 3, 1, 2000, 1, 0)]
|
||||||
|
public int Signal { get; set; } = 9;
|
||||||
|
|
||||||
|
[InputParameter("Use SMA for warmup period", sortIndex: 2)]
|
||||||
|
public bool UseSMA { get; set; } = false;
|
||||||
|
|
||||||
|
[InputParameter("Data source", sortIndex: 3, variants: [
|
||||||
|
"Open", SourceType.Open,
|
||||||
|
"High", SourceType.High,
|
||||||
|
"Low", SourceType.Low,
|
||||||
|
"Close", SourceType.Close,
|
||||||
|
"HL/2 (Median)", SourceType.HL2,
|
||||||
|
"OC/2 (Midpoint)", SourceType.OC2,
|
||||||
|
"OHL/3 (Mean)", SourceType.OHL3,
|
||||||
|
"HLC/3 (Typical)", SourceType.HLC3,
|
||||||
|
"OHLC/4 (Average)", SourceType.OHLC4,
|
||||||
|
"HLCC/4 (Weighted)", SourceType.HLCC4
|
||||||
|
])]
|
||||||
|
public SourceType Source { get; set; } = SourceType.Close;
|
||||||
|
|
||||||
|
[InputParameter("Show cold values", sortIndex: 21)]
|
||||||
|
public bool ShowColdValues { get; set; } = true;
|
||||||
|
|
||||||
|
private Ema? slow_ma;
|
||||||
|
private Ema? fast_ma;
|
||||||
|
private Ema? signal_ma;
|
||||||
|
protected LineSeries? MainSeries;
|
||||||
|
protected LineSeries? SignalSeries;
|
||||||
|
|
||||||
|
protected string? SourceName;
|
||||||
|
public int MinHistoryDepths => Slow;
|
||||||
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||||
|
|
||||||
|
public override string ShortName => $"MACD {Slow}:{Fast}:{Signal}";
|
||||||
|
|
||||||
|
public MacdIndicator()
|
||||||
|
{
|
||||||
|
OnBackGround = true;
|
||||||
|
SeparateWindow = true;
|
||||||
|
SourceName = Source.ToString();
|
||||||
|
Name = "MACD - Moving Average Convergence Divergence";
|
||||||
|
Description = "MACD";
|
||||||
|
MainSeries = new(name: $"MAIN", color: Color.Yellow, width: 2, style: LineStyle.Solid);
|
||||||
|
SignalSeries = new(name: $"SIGNAL", color: Color.Blue, width: 2, style: LineStyle.Solid);
|
||||||
|
|
||||||
|
AddLineSeries(MainSeries);
|
||||||
|
AddLineSeries(SignalSeries);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInit()
|
||||||
|
{
|
||||||
|
slow_ma = new(Slow, useSma: UseSMA);
|
||||||
|
fast_ma = new(Fast, useSma: UseSMA);
|
||||||
|
signal_ma = new(Signal, useSma: UseSMA);
|
||||||
|
SourceName = Source.ToString();
|
||||||
|
base.OnInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnUpdate(UpdateArgs args)
|
||||||
|
{
|
||||||
|
TValue input = this.GetInputValue(args, Source);
|
||||||
|
slow_ma!.Calc(input);
|
||||||
|
fast_ma!.Calc(input);
|
||||||
|
double main = fast_ma.Value - slow_ma.Value;
|
||||||
|
signal_ma!.Calc(main);
|
||||||
|
|
||||||
|
MainSeries!.SetValue(main);
|
||||||
|
MainSeries!.SetMarker(0, Color.Transparent); //OnPaintChart draws the line, hidden here
|
||||||
|
SignalSeries!.SetValue(signal_ma.Value);
|
||||||
|
SignalSeries!.SetMarker(0, Color.Transparent); //OnPaintChart draws the line, hidden here
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnPaintChart(PaintChartEventArgs args)
|
||||||
|
{
|
||||||
|
base.OnPaintChart(args);
|
||||||
|
this.PaintSmoothCurve(args, MainSeries!, slow_ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
|
||||||
|
this.PaintSmoothCurve(args, SignalSeries!, slow_ma!.WarmupPeriod, showColdValues: ShowColdValues, tension: 0.2);
|
||||||
|
this.DrawText(args, Description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using TradingPlatform.BusinessLayer;
|
||||||
|
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
public class JbandsIndicator : Indicator, IWatchlistIndicator
|
||||||
|
{
|
||||||
|
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
|
||||||
|
public int Periods { get; set; } = 14;
|
||||||
|
|
||||||
|
[InputParameter("Data source", sortIndex: 5, variants: [
|
||||||
|
"Open", SourceType.Open,
|
||||||
|
"High", SourceType.High,
|
||||||
|
"Low", SourceType.Low,
|
||||||
|
"Close", SourceType.Close,
|
||||||
|
"HL/2 (Median)", SourceType.HL2,
|
||||||
|
"OC/2 (Midpoint)", SourceType.OC2,
|
||||||
|
"OHL/3 (Mean)", SourceType.OHL3,
|
||||||
|
"HLC/3 (Typical)", SourceType.HLC3,
|
||||||
|
"OHLC/4 (Average)", SourceType.OHLC4,
|
||||||
|
"HLCC/4 (Weighted)", SourceType.HLCC4
|
||||||
|
])]
|
||||||
|
public SourceType Source { get; set; } = SourceType.Close;
|
||||||
|
|
||||||
|
[InputParameter("vShort", sortIndex: 6, -100, 100, 1, 0)]
|
||||||
|
public int Phase { get; set; } = 10;
|
||||||
|
|
||||||
|
private Jma? jma;
|
||||||
|
protected LineSeries? UbSeries;
|
||||||
|
protected LineSeries? LbSeries;
|
||||||
|
protected string? SourceName;
|
||||||
|
public static int MinHistoryDepths => 2;
|
||||||
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||||
|
|
||||||
|
public JbandsIndicator()
|
||||||
|
{
|
||||||
|
Name = "JBANDS - Mark Jurik's Bands";
|
||||||
|
Description = "Upper and Lower Bands.";
|
||||||
|
SeparateWindow = false;
|
||||||
|
|
||||||
|
UbSeries = new("UB", Color.Blue, 2, LineStyle.Solid);
|
||||||
|
LbSeries = new("LB", Color.Red, 2, LineStyle.Solid);
|
||||||
|
AddLineSeries(UbSeries);
|
||||||
|
AddLineSeries(LbSeries);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInit()
|
||||||
|
{
|
||||||
|
jma = new(Periods, phase: Phase);
|
||||||
|
SourceName = Source.ToString();
|
||||||
|
base.OnInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnUpdate(UpdateArgs args)
|
||||||
|
{
|
||||||
|
TValue input = this.GetInputValue(args, Source);
|
||||||
|
jma!.Calc(input);
|
||||||
|
|
||||||
|
UbSeries!.SetValue(jma.UpperBand);
|
||||||
|
LbSeries!.SetValue(jma.LowerBand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ShortName => $"JBands ({Periods}:{Phase})";
|
||||||
|
}
|
||||||
@@ -6,11 +6,27 @@ namespace QuanTAlib;
|
|||||||
public class JvoltyIndicator : Indicator, IWatchlistIndicator
|
public class JvoltyIndicator : Indicator, IWatchlistIndicator
|
||||||
{
|
{
|
||||||
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
|
[InputParameter("Periods", sortIndex: 1, 1, 2000, 1, 0)]
|
||||||
public int Periods { get; set; } = 20;
|
public int Periods { get; set; } = 14;
|
||||||
|
|
||||||
private Jvolty? jvolty;
|
[InputParameter("Data source", sortIndex: 5, variants: [
|
||||||
|
"Open", SourceType.Open,
|
||||||
|
"High", SourceType.High,
|
||||||
|
"Low", SourceType.Low,
|
||||||
|
"Close", SourceType.Close,
|
||||||
|
"HL/2 (Median)", SourceType.HL2,
|
||||||
|
"OC/2 (Midpoint)", SourceType.OC2,
|
||||||
|
"OHL/3 (Mean)", SourceType.OHL3,
|
||||||
|
"HLC/3 (Typical)", SourceType.HLC3,
|
||||||
|
"OHLC/4 (Average)", SourceType.OHLC4,
|
||||||
|
"HLCC/4 (Weighted)", SourceType.HLCC4
|
||||||
|
])]
|
||||||
|
public SourceType Source { get; set; } = SourceType.Close;
|
||||||
|
|
||||||
|
private Jma? jma;
|
||||||
protected LineSeries? JvoltySeries;
|
protected LineSeries? JvoltySeries;
|
||||||
public static int MinHistoryDepths => 2;
|
public static int MinHistoryDepths => 2;
|
||||||
|
|
||||||
|
|
||||||
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||||
|
|
||||||
public JvoltyIndicator()
|
public JvoltyIndicator()
|
||||||
@@ -25,16 +41,17 @@ public class JvoltyIndicator : Indicator, IWatchlistIndicator
|
|||||||
|
|
||||||
protected override void OnInit()
|
protected override void OnInit()
|
||||||
{
|
{
|
||||||
jvolty = new (Periods);
|
jma = new(Periods);
|
||||||
base.OnInit();
|
base.OnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUpdate(UpdateArgs args)
|
protected override void OnUpdate(UpdateArgs args)
|
||||||
{
|
{
|
||||||
TBar input = IndicatorExtensions.GetInputBar(this, args);
|
TValue input = this.GetInputValue(args, Source);
|
||||||
TValue result = jvolty!.Calc(input);
|
jma!.Calc(input);
|
||||||
|
|
||||||
|
JvoltySeries!.SetValue(jma.Volty);
|
||||||
|
|
||||||
JvoltySeries!.SetValue(result.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ShortName => $"JVOLTY ({Periods})";
|
public override string ShortName => $"JVOLTY ({Periods})";
|
||||||
|
|||||||
Reference in New Issue
Block a user