mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08:05 +00:00
Adr, Ap, Atrp, Atrs, Vp, Vwap, Vwma
This commit is contained in:
+6
-6
@@ -1,24 +1,24 @@
|
|||||||
* [Home](/)
|
* [Home](/)
|
||||||
|
|
||||||
* [Available Indicators](indicators/indicators.md)
|
* [List of Indicators](indicators/indicators.md)
|
||||||
|
|
||||||
* Introduction
|
* 🚧 Introduction
|
||||||
* [Overview]()
|
* [Overview]()
|
||||||
* [Features]()
|
* [Features]()
|
||||||
* [Historical vs Real-time analysis](essays/realtime.md)
|
* [Historical vs Real-time analysis](essays/realtime.md)
|
||||||
|
|
||||||
* Core Concepts
|
* 🚧 Core Concepts
|
||||||
* [Time Series Data Handling]()
|
* [Time Series Data Handling]()
|
||||||
* [Calculation classes]()
|
* [Calculation classes]()
|
||||||
* [Presentation Classes]()
|
* [Presentation Classes]()
|
||||||
|
|
||||||
* QuanTAlib C# Library
|
* 🚧 QuanTAlib C# Library
|
||||||
* [Installation]()
|
* [Installation]()
|
||||||
* [Quick Start Guide]()
|
* [Quick Start Guide]()
|
||||||
* [Usage Examples]()
|
* [Usage Examples]()
|
||||||
* [Tests and Validation]()
|
* [Tests and Validation]()
|
||||||
|
|
||||||
* Quantower Charts
|
* 🚧 Quantower Charts
|
||||||
* [Installation]()
|
* [Installation]()
|
||||||
* [Quick Start Guide]()
|
* [Quick Start Guide]()
|
||||||
* [Using VS Code for QuanTower coding](setup/vscode.md)
|
* [Using VS Code for QuanTower coding](setup/vscode.md)
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
* [Creating Custom Indicators]()
|
* [Creating Custom Indicators]()
|
||||||
* [Inspecting Quantower Internals]()
|
* [Inspecting Quantower Internals]()
|
||||||
|
|
||||||
* [Available Indicators](indicators/indicators.md)
|
* [🚧 Available Indicators](indicators/indicators.md)
|
||||||
* Momentum
|
* Momentum
|
||||||
* [ADX - Average Directional Index](indicators/momentum/adx/description.md)
|
* [ADX - Average Directional Index](indicators/momentum/adx/description.md)
|
||||||
* [ADXR - Average Directional Index Rating](indicators/momentum/adxr/description.md)
|
* [ADXR - Average Directional Index Rating](indicators/momentum/adxr/description.md)
|
||||||
|
|||||||
+96
-13
@@ -3,57 +3,140 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>QuanTAlib Documentation</title>
|
<title>QuanTAlib Documentation</title>
|
||||||
|
|
||||||
|
<!-- Basic meta tags -->
|
||||||
<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="Documentation for QuanTAlib, a quantitative technical analysis library">
|
<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/katex@0.16.7/dist/katex.min.css" integrity="sha384-3UiQGuEI4TTMaFmGIZumfRPtfKQ3trwQE2JgosJxCnGmQpL/lJdjpcHkaaFwHlcI" crossorigin="anonymous">
|
|
||||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/themes/vue.css" />
|
<!-- Stylesheets -->
|
||||||
|
<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="//cdn.jsdelivr.net/npm/docsify/themes/vue.css">
|
||||||
|
<style>
|
||||||
|
/* Target strong elements within tables */
|
||||||
|
table strong {
|
||||||
|
font-size: 120%;
|
||||||
|
display: inline-block; /* This helps with vertical alignment */
|
||||||
|
padding: 4px 0; /* Add some vertical padding for better spacing */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optional: If you want to target just the section headers more specifically */
|
||||||
|
table tr:first-child strong,
|
||||||
|
table tr strong:first-child {
|
||||||
|
font-size: 120%;
|
||||||
|
color: #42b983; /* Optional: matches Docsify's default theme color */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hide github corner */
|
||||||
|
.github-corner {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
.github-corner svg {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|
||||||
|
<!-- Docsify Configuration -->
|
||||||
<script>
|
<script>
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
|
// Basic settings
|
||||||
name: 'QuanTAlib',
|
name: 'QuanTAlib',
|
||||||
repo: 'https://github.com/mihakralj/quantalib',
|
|
||||||
homepage: 'readme.md',
|
homepage: 'readme.md',
|
||||||
|
noCorner: true,
|
||||||
|
|
||||||
|
// Navigation settings
|
||||||
loadSidebar: true,
|
loadSidebar: true,
|
||||||
auto2top: true,
|
auto2top: true,
|
||||||
mergeNavbar: true,
|
mergeNavbar: true,
|
||||||
sidebarDisplayLevel: 0,
|
sidebarDisplayLevel: 0,
|
||||||
|
|
||||||
|
// Performance settings
|
||||||
maxAge: 86400000,
|
maxAge: 86400000,
|
||||||
paths: 'auto',
|
paths: 'auto',
|
||||||
|
|
||||||
|
// Search settings
|
||||||
placeholder: 'Type to search',
|
placeholder: 'Type to search',
|
||||||
noData: 'No Results!',
|
noData: 'No Results!',
|
||||||
depth: 6,
|
depth: 6,
|
||||||
hideOtherSidebarContent: false,
|
hideOtherSidebarContent: false,
|
||||||
|
|
||||||
|
// Theme settings
|
||||||
themeable: {
|
themeable: {
|
||||||
readyTransition: true,
|
readyTransition: true,
|
||||||
responsiveTables: true
|
responsiveTables: true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Math settings
|
||||||
latex: {
|
latex: {
|
||||||
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
||||||
displayMath: [['$$', '$$']]
|
displayMath: [['$$', '$$']]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Markdown settings
|
||||||
|
markdown: {
|
||||||
|
smartypants: true,
|
||||||
|
renderer: {
|
||||||
|
table: function(header, body) {
|
||||||
|
if (header) return '<table class="docTable"><thead>' + header + '</thead><tbody>' + body + '</tbody></table>'
|
||||||
|
return '<table class="docTable"><tbody>' + body + '</tbody></table>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Content settings
|
||||||
executeScript: true,
|
executeScript: true,
|
||||||
externalLinkTarget: '_blank',
|
externalLinkTarget: '_blank',
|
||||||
cornerExternalLinkTarget: '_blank',
|
cornerExternalLinkTarget: '_blank',
|
||||||
relativePath: false,
|
relativePath: false,
|
||||||
|
|
||||||
|
// Table of Contents settings
|
||||||
toc: {
|
toc: {
|
||||||
scope: '.markdown-section',
|
scope: '.markdown-section',
|
||||||
headings: 'h1, h2, h3, h4, h5, h6',
|
headings: 'h1, h2, h3, h4, h5, h6',
|
||||||
title: 'Table of Contents'
|
title: 'Table of Contents'
|
||||||
},
|
},
|
||||||
|
|
||||||
plugins: []
|
plugins: []
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<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-themeable@0/dist/js/docsify-themeable.min.js" integrity="sha384-ibjVZCUwWPrRrNc9BNkbbJvtYmTh8GYDNQgj+2jQVNDudOFgSQWs+Es6JhdoTIvf" crossorigin="anonymous"></script>
|
<!-- Core Docsify -->
|
||||||
<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/docsify@4/lib/docsify.min.js"
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js" integrity="sha384-LthJPBJ4RGco78kBY+EmKz5rmISZ5vrtAu3+l2ALQ2mrZHOe6Wyf6knyKjeC4cL6" crossorigin="anonymous"></script>
|
integrity="sha384-KaHhgnx/OTLoJ4J33SSJsF4x1pk4I7q3s5ZOfIDHJYl6IG7Oyn2vNDsHiWJe46fD"
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify-copy-code/dist/docsify-copy-code.min.js" integrity="sha384-Vu4LjJ210wltbg1I3zl1f5n8qLSDr9GE7ij2JfiMbV64UCFP2RgFtG8W2Gh6Khwe" crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify-pagination/dist/docsify-pagination.min.js" integrity="sha384-uFEp18/1vv2dYlO64J2lOcnbhirAQZPtruqAZZ7PZYoXenm5c+tIs3AqSMjVMRe8" crossorigin="anonymous"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/zoom-image.min.js" integrity="sha384-fYBaBAsdPMjWt1AuA+txMoztHnl+zLgObSvwddIabbfUp+36gf/vNOKx88f37zix" crossorigin="anonymous"></script>
|
<!-- Added marked.js for better markdown parsing -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/docsify-tabs/dist/docsify-tabs.min.js" integrity="sha384-QA3IVKzXq6xcKR8yQJHgDbI1FcJiQ137Cuetl1VWzUxJ6BQ7ew0MMq5fg2HbFK1o" crossorigin="anonymous"></script>
|
<script src="//cdn.jsdelivr.net/npm/marked/marked.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>
|
|
||||||
|
<!-- Plugins -->
|
||||||
|
<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-sidebar-collapse/dist/docsify-sidebar-collapse.min.js"
|
||||||
|
integrity="sha384-lMHOyuqf3B/T/BgfYxUKprN0bdRf8KhVTE11w76Tvtze86XHVSDYzxqNGDGgIi9I"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"
|
||||||
|
integrity="sha384-LthJPBJ4RGco78kBY+EmKz5rmISZ5vrtAu3+l2ALQ2mrZHOe6Wyf6knyKjeC4cL6"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify-copy-code/dist/docsify-copy-code.min.js"
|
||||||
|
integrity="sha384-Vu4LjJ210wltbg1I3zl1f5n8qLSDr9GE7ij2JfiMbV64UCFP2RgFtG8W2Gh6Khwe"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify-pagination/dist/docsify-pagination.min.js"
|
||||||
|
integrity="sha384-uFEp18/1vv2dYlO64J2lOcnbhirAQZPtruqAZZ7PZYoXenm5c+tIs3AqSMjVMRe8"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/zoom-image.min.js"
|
||||||
|
integrity="sha384-fYBaBAsdPMjWt1AuA+txMoztHnl+zLgObSvwddIabbfUp+36gf/vNOKx88f37zix"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/docsify-tabs/dist/docsify-tabs.min.js"
|
||||||
|
integrity="sha384-QA3IVKzXq6xcKR8yQJHgDbI1FcJiQ137Cuetl1VWzUxJ6BQ7ew0MMq5fg2HbFK1o"
|
||||||
|
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>
|
||||||
@@ -1,30 +1,27 @@
|
|||||||
# Indicators in QuanTAlib
|
# Indicators in QuanTAlib
|
||||||
|
|
||||||
\* = Returns multiple values
|
| **Category** | **Status** | **Completion** |
|
||||||
|
|--------------|:----------:|:--------------:|
|
||||||
|
| Basic Transforms | 6 of 6 | 100% |
|
||||||
|
| Averages & Trends | 33 of 33 | 100% |
|
||||||
|
| Momentum | 17 of 17 | 100% |
|
||||||
|
| Oscillators | 12 of 29 | 41% |
|
||||||
|
| Volatility | 15 of 35 | 43% |
|
||||||
|
| Volume | 19 of 19 | 100% |
|
||||||
|
| Numerical Analysis | 13 of 20 | 65% |
|
||||||
|
| Errors | 16 of 16 | 100% |
|
||||||
|
| **Total** | **131 of 175** | **75%** |
|
||||||
|
|
||||||
**Implementation Status:**
|
|Technical Indicator Name| Class Name|
|
||||||
- Basic Transforms: 6 of 6 complete
|
|-----------|:----------:|
|
||||||
- Averages & Trends: 33 of 33 complete
|
|**BASIC TRANSFORMS**||
|
||||||
- Momentum: 17 of 17 complete
|
|
||||||
- Oscillators: 11 of 29 complete
|
|
||||||
- Volatility: 11 of 35 complete
|
|
||||||
- Volume: 15 of 19 complete
|
|
||||||
- Numerical Analysis: 13 of 20 complete
|
|
||||||
- Errors: 16 of 16 complete
|
|
||||||
- Total: 122 of 175 indicators implemented (70%)
|
|
||||||
|
|
||||||
|
|
||||||
|**BASIC TRANSFORMS**|**Class Name**|
|
|
||||||
|---|:--:|
|
|
||||||
|OC2 - Midpoint price|`.OC2`|
|
|OC2 - Midpoint price|`.OC2`|
|
||||||
|HL2 - Median Price|`.HL2`|
|
|HL2 - Median Price|`.HL2`|
|
||||||
|HLC3 - Typical Price|`.HLC3`|
|
|HLC3 - Typical Price|`.HLC3`|
|
||||||
|OHL3 - Mean Price|`.OHL3`|
|
|OHL3 - Mean Price|`.OHL3`|
|
||||||
|OHLC4 - Average Price|`.OHLC4`|
|
|OHLC4 - Average Price|`.OHLC4`|
|
||||||
|HLCC4 - Weighted Price|`.HLCC4`|
|
|HLCC4 - Weighted Price|`.HLCC4`|
|
||||||
|
|**AVERAGES & TRENDS**||
|
||||||
|**AVERAGES & TRENDS**|**Class Name**|
|
|
||||||
|--|:--:|
|
|
||||||
|AFIRMA - Adaptive FIR Moving Average|`Afirma`|
|
|AFIRMA - Adaptive FIR Moving Average|`Afirma`|
|
||||||
|ALMA - Arnaud Legoux Moving Average|`Alma`|
|
|ALMA - Arnaud Legoux Moving Average|`Alma`|
|
||||||
|DEMA - Double Exponential Moving Average|`Dema`|
|
|DEMA - Double Exponential Moving Average|`Dema`|
|
||||||
@@ -58,9 +55,7 @@
|
|||||||
|VIDYA - Variable Index Dynamic Average|`Vidya`|
|
|VIDYA - Variable Index Dynamic Average|`Vidya`|
|
||||||
|WMA - Weighted Moving Average|`Wma`|
|
|WMA - Weighted Moving Average|`Wma`|
|
||||||
|ZLEMA - Zero-Lag Exponential Moving Average|`Zlema`|
|
|ZLEMA - Zero-Lag Exponential Moving Average|`Zlema`|
|
||||||
|
|**MOMENTUM INDICATORS**||
|
||||||
|**MOMENTUM INDICATORS**|**Class Name**|
|
|
||||||
|--|:--:|
|
|
||||||
|ADX - Average Directional Movement Index|`Adx`|
|
|ADX - Average Directional Movement Index|`Adx`|
|
||||||
|ADXR - Average Directional Movement Index Rating|`Adxr`|
|
|ADXR - Average Directional Movement Index Rating|`Adxr`|
|
||||||
|APO - Absolute Price Oscillator|`Apo`|
|
|APO - Absolute Price Oscillator|`Apo`|
|
||||||
@@ -78,79 +73,73 @@
|
|||||||
|TRIX - 1-day ROC of TEMA|`Trix`|
|
|TRIX - 1-day ROC of TEMA|`Trix`|
|
||||||
|VEL - Jurik Signal Velocity|`Vel`|
|
|VEL - Jurik Signal Velocity|`Vel`|
|
||||||
|VORTEX* - Vortex Indicator (VI+, VI-)|`Vortex`|
|
|VORTEX* - Vortex Indicator (VI+, VI-)|`Vortex`|
|
||||||
|
|**OSCILLATORS**||
|
||||||
|**OSCILLATORS**|**Class Name**|
|
|
||||||
|--|:--:|
|
|
||||||
|AC - Acceleration Oscillator|`Ac`|
|
|AC - Acceleration Oscillator|`Ac`|
|
||||||
|AO - Awesome Oscillator|`Ao`|
|
|AO - Awesome Oscillator|`Ao`|
|
||||||
|AROON* - Aroon oscillator (Up, Down)|`Aroon`|
|
|AROON* - Aroon oscillator (Up, Down)|`Aroon`|
|
||||||
|🚧 BOP - Balance of Power|`Bop`|
|
|BOP - Balance of Power|`Bop`|
|
||||||
|CCI - Commodity Channel Index|`Cci`|
|
|CCI - Commodity Channel Index|`Cci`|
|
||||||
|CFO - Chande Forcast Oscillator|`Cfo`|
|
|CFO - Chande Forcast Oscillator|`Cfo`|
|
||||||
|CMO - Chande Momentum Oscillator|`Cmo`|
|
|CMO - Chande Momentum Oscillator|`Cmo`|
|
||||||
|CHOP - Choppiness Index|`Chop`|
|
|CHOP - Choppiness Index|`Chop`|
|
||||||
|COG - Ehler's Center of Gravity|`Cog`|
|
|COG - Ehler's Center of Gravity|`Cog`|
|
||||||
|🚧 COPPOCK - Coppock Curve|`Coppock`|
|
|🚧 COPPOCK - Coppock Curve|`Coppock`|
|
||||||
|🚧 CRSI - Connor RSI|`Crsi`|
|
|🚧 CRSI - Connor RSI|`Crsi`|
|
||||||
|🚧 CTI - Ehler's Correlation Trend Indicator|`Cti`|
|
|🚧 CTI - Ehler's Correlation Trend Indicator|`Cti`|
|
||||||
|🚧 DOSC - Derivative Oscillator|`Dosc`|
|
|🚧 DOSC - Derivative Oscillator|`Dosc`|
|
||||||
|🚧 EFI - Elder Ray's Force Index|`Efi`|
|
|🚧 EFI - Elder Ray's Force Index|`Efi`|
|
||||||
|🚧 FISHER - Fisher Transform|`Fisher`|
|
|🚧 FISHER - Fisher Transform|`Fisher`|
|
||||||
|🚧 FOSC - Forecast Oscillator|`Fosc`|
|
|🚧 FOSC - Forecast Oscillator|`Fosc`|
|
||||||
|🚧 GATOR* - Williams Alliator Oscillator (Upper Jaw, Lower Jaw, Teeth)|`Gator`|
|
|🚧 GATOR* - Williams Alliator Oscillator (Upper Jaw, Lower Jaw, Teeth)|`Gator`|
|
||||||
|🚧 KDJ* - KDJ Indicator (K, D, J lines)|`Kdj`|
|
|🚧 KDJ* - KDJ Indicator (K, D, J lines)|`Kdj`|
|
||||||
|🚧 KRI - Kairi Relative Index|`Kri`|
|
|🚧 KRI - Kairi Relative Index|`Kri`|
|
||||||
|RSI - Relative Strength Index|`Rsi`|
|
|RSI - Relative Strength Index|`Rsi`|
|
||||||
|RSX - Jurik Trend Strength Index|`Rsx`|
|
|RSX - Jurik Trend Strength Index|`Rsx`|
|
||||||
|🚧 RVGI* - Relative Vigor Index (RVGI, Signal)|`Rvgi`|
|
|🚧 RVGI* - Relative Vigor Index (RVGI, Signal)|`Rvgi`|
|
||||||
|🚧 SMI - Stochastic Momentum Index|`Smi`|
|
|🚧 SMI - Stochastic Momentum Index|`Smi`|
|
||||||
|🚧 SRSI* - Stochastic RSI (SRSI, Signal)|`Srsi`|
|
|🚧 SRSI* - Stochastic RSI (SRSI, Signal)|`Srsi`|
|
||||||
|🚧 STC - Schaff Trend Cycle|`Stc`|
|
|🚧 STC - Schaff Trend Cycle|`Stc`|
|
||||||
|🚧 STOCH* - Stochastic Oscillator (%K, %D)|`Stoch`|
|
|🚧 STOCH* - Stochastic Oscillator (%K, %D)|`Stoch`|
|
||||||
|🚧 TSI - True Strength Index|`Tsi`|
|
|🚧 TSI - True Strength Index|`Tsi`|
|
||||||
|🚧 UO - Ultimate Oscillator|`Uo`|
|
|🚧 UO - Ultimate Oscillator|`Uo`|
|
||||||
|🚧 WILLR - Larry Williams' %R|`Willr`|
|
|🚧 WILLR - Larry Williams' %R|`Willr`|
|
||||||
|
|**VOLATILITY INDICATORS**||
|
||||||
|**VOLATILITY INDICATORS**|**Class Name**|
|
|ADR - Average Daily Range|`Adr`|
|
||||||
|--|:--:|
|
|AP - Andrew's Pitchfork|`Ap`|
|
||||||
|🚧 ADR - Average Daily Range|`Adr`|
|
|
||||||
|🚧 AP - Andrew's Pitchfork|`Ap`|
|
|
||||||
|ATR - Average True Range|`Atr`|
|
|ATR - Average True Range|`Atr`|
|
||||||
|🚧 ATRP - Average True Range Percent|`Atrp`|
|
|ATRP - Average True Range Percent|`Atrp`|
|
||||||
|🚧 ATRS - ATR Trailing Stop|`Atrs`|
|
|ATRS - ATR Trailing Stop|`Atrs`|
|
||||||
|🚧 BB* - Bollinger Bands® (Upper, Middle, Lower)|`Bb`|
|
|🚧 BB* - Bollinger Bands® (Upper, Middle, Lower)|`Bb`|
|
||||||
|🚧 CCV - Close-to-Close Volatility|`Ccv`|
|
|🚧 CCV - Close-to-Close Volatility|`Ccv`|
|
||||||
|🚧 CE - Chandelier Exit|`Ce`|
|
|🚧 CE - Chandelier Exit|`Ce`|
|
||||||
|🚧 CV - Conditional Volatility (ARCH/GARCH)|`Cv`|
|
|🚧 CV - Conditional Volatility (ARCH/GARCH)|`Cv`|
|
||||||
|🚧 CVI - Chaikin's Volatility|`Cvi`|
|
|🚧 CVI - Chaikin's Volatility|`Cvi`|
|
||||||
|🚧 DC* - Donchian Channels (Upper, Middle, Lower)|`Dc`|
|
|🚧 DC* - Donchian Channels (Upper, Middle, Lower)|`Dc`|
|
||||||
|🚧 EWMA - Exponential Weighted Moving Average Volatility|`Ewma`|
|
|🚧 EWMA - Exponential Weighted Moving Average Volatility|`Ewma`|
|
||||||
|🚧 FCB - Fractal Chaos Bands|`Fcb`|
|
|🚧 FCB - Fractal Chaos Bands|`Fcb`|
|
||||||
|🚧 GKV - Garman-Klass Volatility|`Gkv`|
|
|🚧 GKV - Garman-Klass Volatility|`Gkv`|
|
||||||
|🚧 HLV - High-Low Volatility|`Hlv`|
|
|🚧 HLV - High-Low Volatility|`Hlv`|
|
||||||
|HV - Historical Volatility|`Hv`|
|
|HV - Historical Volatility|`Hv`|
|
||||||
|🚧 ICH* - Ichimoku Cloud (Conversion, Base, Leading Span A, Leading Span B, Lagging Span)|`Ich`|
|
|🚧 ICH* - Ichimoku Cloud (Conversion, Base, Leading Span A, Leading Span B, Lagging Span)|`Ich`|
|
||||||
|JVOLTY - Jurik Volatility|`Jvolty`|
|
|JVOLTY - Jurik Volatility|`Jvolty`|
|
||||||
|🚧 KC* - Keltner Channels (Upper, Middle, Lower)|`Kc`|
|
|🚧 KC* - Keltner Channels (Upper, Middle, Lower)|`Kc`|
|
||||||
|🚧 NATR - Normalized Average True Range|`Natr`|
|
|🚧 NATR - Normalized Average True Range|`Natr`|
|
||||||
|🚧 PCH - Price Channel Indicator|`Pch`|
|
|🚧 PCH - Price Channel Indicator|`Pch`|
|
||||||
|🚧 PSAR* - Parabolic Stop and Reverse (Value, Trend)|`Psar`|
|
|🚧 PSAR* - Parabolic Stop and Reverse (Value, Trend)|`Psar`|
|
||||||
|🚧 PV - Parkinson Volatility|`Pv`|
|
|🚧 PV - Parkinson Volatility|`Pv`|
|
||||||
|🚧 RSV - Rogers-Satchell Volatility|`Rsv`|
|
|🚧 RSV - Rogers-Satchell Volatility|`Rsv`|
|
||||||
|RV - Realized Volatility|`Rv`|
|
|RV - Realized Volatility|`Rv`|
|
||||||
|RVI - Relative Volatility Index|`Rvi`|
|
|RVI - Relative Volatility Index|`Rvi`|
|
||||||
|🚧 STARC* - Starc Bands (Upper, Middle, Lower)|`Starc`|
|
|🚧 STARC* - Starc Bands (Upper, Middle, Lower)|`Starc`|
|
||||||
|🚧 SV - Stochastic Volatility|`Sv`|
|
|🚧 SV - Stochastic Volatility|`Sv`|
|
||||||
|TR - True Range|`Tr`|
|
|TR - True Range|`Tr`|
|
||||||
|UI - Ulcer Index|`Ui`|
|
|UI - Ulcer Index|`Ui`|
|
||||||
|VC* - Volatility Cone (Mean, Upper Bound, Lower Bound)|`Vc`|
|
|VC* - Volatility Cone (Mean, Upper Bound, Lower Bound)|`Vc`|
|
||||||
|VOV - Volatility of Volatility|`Vov`|
|
|VOV - Volatility of Volatility|`Vov`|
|
||||||
|VR - Volatility Ratio|`Vr`|
|
|VR - Volatility Ratio|`Vr`|
|
||||||
|VS* - Volatility Stop (Long Stop, Short Stop)|`Vs`|
|
|VS* - Volatility Stop (Long Stop, Short Stop)|`Vs`|
|
||||||
|🚧 YZV - Yang-Zhang Volatility|`Yzv`|
|
|🚧 YZV - Yang-Zhang Volatility|`Yzv`|
|
||||||
|
|**VOLUME INDICATORS**||
|
||||||
|**VOLUME INDICATORS**|**Class Name**|
|
|
||||||
|--|:--:|
|
|
||||||
|ADL - Chaikin Accumulation Distribution Line|`Adl`|
|
|ADL - Chaikin Accumulation Distribution Line|`Adl`|
|
||||||
|ADOSC - Chaikin Accumulation Distribution Oscillator|`Adosc`|
|
|ADOSC - Chaikin Accumulation Distribution Oscillator|`Adosc`|
|
||||||
|AOBV - Archer On-Balance Volume|`Aobv`|
|
|AOBV - Archer On-Balance Volume|`Aobv`|
|
||||||
@@ -166,36 +155,32 @@
|
|||||||
|PVR - Price Volume Rank|`Pvr`|
|
|PVR - Price Volume Rank|`Pvr`|
|
||||||
|PVT - Price Volume Trend|`Pvt`|
|
|PVT - Price Volume Trend|`Pvt`|
|
||||||
|TVI - Trade Volume Index|`Tvi`|
|
|TVI - Trade Volume Index|`Tvi`|
|
||||||
|🚧 VF - Volume Force|`Vf`|
|
|VF - Volume Force|`Vf`|
|
||||||
|🚧 VP - Volume Profile|`Vp`|
|
|VP - Volume Profile|`Vp`|
|
||||||
|🚧 VWAP - Volume Weighted Average Price|`Vwap`|
|
|VWAP - Volume Weighted Average Price|`Vwap`|
|
||||||
|🚧 VWMA - Volume Weighted Moving Average|`Vwma`|
|
|VWMA - Volume Weighted Moving Average|`Vwma`|
|
||||||
|
|**NUMERICAL ANALYSIS**||
|
||||||
|**NUMERICAL ANALYSIS**|**Class Name**|
|
|🚧 BETA* - Beta coefficient (Beta, R-squared)|`Beta`|
|
||||||
|--|:--:|
|
|🚧 CORR* - Correlation Coefficient (Correlation, P-value)|`Corr`|
|
||||||
|🚧 BETA* - Beta coefficient (Beta, R-squared)|`Beta`|
|
|
||||||
|🚧 CORR* - Correlation Coefficient (Correlation, P-value)|`Corr`|
|
|
||||||
|CURVATURE - Rate of Change in Direction or Slope|`Curvature`|
|
|CURVATURE - Rate of Change in Direction or Slope|`Curvature`|
|
||||||
|ENTROPY - Measure of Uncertainty or Disorder|`Entropy`|
|
|ENTROPY - Measure of Uncertainty or Disorder|`Entropy`|
|
||||||
|🚧 HUBER - Huber Loss|`Huber`|
|
|🚧 HUBER - Huber Loss|`Huber`|
|
||||||
|🚧 HURST - Hurst Exponent|`Hurst`|
|
|🚧 HURST - Hurst Exponent|`Hurst`|
|
||||||
|KURTOSIS - Measure of Tails/Peakedness|`Kurtosis`|
|
|KURTOSIS - Measure of Tails/Peakedness|`Kurtosis`|
|
||||||
|MAX - Maximum with exponential decay|`Max`|
|
|MAX - Maximum with exponential decay|`Max`|
|
||||||
|MEDIAN - Middle value|`Median`|
|
|MEDIAN - Middle value|`Median`|
|
||||||
|MIN - Minimum with exponential decay|`Min`|
|
|MIN - Minimum with exponential decay|`Min`|
|
||||||
|MODE - Most Frequent Value|`Mode`|
|
|MODE - Most Frequent Value|`Mode`|
|
||||||
|PERCENTILE - Rank Order|`Percentile`|
|
|PERCENTILE - Rank Order|`Percentile`|
|
||||||
|🚧 RSQUARED* - Coefficient of Determination (R-squared, Adjusted R-squared)|`Rsquared`|
|
|🚧 RSQUARED* - Coefficient of Determination (R-squared, Adjusted R-squared)|`Rsquared`|
|
||||||
|SKEW - Skewness, asymmetry of distribution|`Skew`|
|
|SKEW - Skewness, asymmetry of distribution|`Skew`|
|
||||||
|SLOPE - Rate of Change, Linear Regression|`Slope`|
|
|SLOPE - Rate of Change, Linear Regression|`Slope`|
|
||||||
|STDDEV - Standard Deviation, Measure of Spread|`Stddev`|
|
|STDDEV - Standard Deviation, Measure of Spread|`Stddev`|
|
||||||
|🚧 THEIL* - Theil's U Statistics (U1, U2)|`Theil`|
|
|🚧 THEIL* - Theil's U Statistics (U1, U2)|`Theil`|
|
||||||
|🚧 TSF* - Time Series Forecast (Forecast, Confidence Interval)|`Tsf`|
|
|🚧 TSF* - Time Series Forecast (Forecast, Confidence Interval)|`Tsf`|
|
||||||
|VARIANCE - Average of Squared Deviations|`Variance`|
|
|VARIANCE - Average of Squared Deviations|`Variance`|
|
||||||
|ZSCORE - Standardized Score|`Zscore`|
|
|ZSCORE - Standardized Score|`Zscore`|
|
||||||
|
|**ERRORS**||
|
||||||
|**ERRORS**|**Class Name**|
|
|
||||||
|--|:--:|
|
|
||||||
|HUBER - Huber Loss|`Huber`|
|
|HUBER - Huber Loss|`Huber`|
|
||||||
|MAE - Mean Absolute Error|`Mae`|
|
|MAE - Mean Absolute Error|`Mae`|
|
||||||
|MAPD - Mean Absolute Percentage Deviation|`Mapd`|
|
|MAPD - Mean Absolute Percentage Deviation|`Mapd`|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Done: 11, Todo: 18
|
|||||||
✔️ AC - Acceleration Oscillator
|
✔️ AC - Acceleration Oscillator
|
||||||
✔️ AO - Awesome Oscillator
|
✔️ AO - Awesome Oscillator
|
||||||
✔️ *AROON - Aroon oscillator (Up, Down)
|
✔️ *AROON - Aroon oscillator (Up, Down)
|
||||||
BOP - Balance of Power
|
✔️ BOP - Balance of Power
|
||||||
✔️ CCI - Commodity Channel Index
|
✔️ CCI - Commodity Channel Index
|
||||||
✔️ CFO - Chande Forcast Oscillator
|
✔️ CFO - Chande Forcast Oscillator
|
||||||
✔️ CMO - Chande Momentum Oscillator
|
✔️ CMO - Chande Momentum Oscillator
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ADR: Average Daily Range
|
||||||
|
/// A volatility indicator that measures the average range of price movement over
|
||||||
|
/// a specified period. It helps identify normal trading ranges and potential
|
||||||
|
/// breakout levels.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The ADR calculation process:
|
||||||
|
/// 1. Calculate daily range (High - Low)
|
||||||
|
/// 2. Apply SMA to daily ranges
|
||||||
|
/// 3. Updates with each new price bar
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Simple volatility measure
|
||||||
|
/// - Period-based average
|
||||||
|
/// - Trend independent
|
||||||
|
/// - Absolute price measure
|
||||||
|
/// - Support/resistance aid
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// Daily Range = High - Low
|
||||||
|
/// ADR = SMA(Daily Range, period)
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Position sizing
|
||||||
|
/// - Volatility analysis
|
||||||
|
/// - Support/resistance levels
|
||||||
|
/// - Breakout identification
|
||||||
|
/// - Risk assessment
|
||||||
|
///
|
||||||
|
/// Note: Simpler alternative to ATR, doesn't consider gaps
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Adr : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly Sma _ma;
|
||||||
|
private const int DefaultPeriod = 14;
|
||||||
|
|
||||||
|
/// <param name="period">The number of periods for ADR calculation (default 14).</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Adr(int period = DefaultPeriod)
|
||||||
|
{
|
||||||
|
if (period < 1)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(period));
|
||||||
|
|
||||||
|
_ma = new(period);
|
||||||
|
WarmupPeriod = period;
|
||||||
|
Name = $"ADR({period})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
/// <param name="period">The number of periods for ADR calculation.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Adr(object source, int period = DefaultPeriod) : this(period)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
// Calculate daily range
|
||||||
|
double range = BarInput.High - BarInput.Low;
|
||||||
|
|
||||||
|
// Apply SMA smoothing
|
||||||
|
return _ma.Calc(range, BarInput.IsNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AP: Andrew's Pitchfork
|
||||||
|
/// A trend channel tool that uses three points to create a channel with a median
|
||||||
|
/// line and two parallel lines. It helps identify potential support and resistance
|
||||||
|
/// levels based on market pivots.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The AP calculation process:
|
||||||
|
/// 1. Use three pivot points (P0, P1, P2)
|
||||||
|
/// 2. Calculate median line from P0 to midpoint of P1-P2
|
||||||
|
/// 3. Draw parallel lines at P1 and P2
|
||||||
|
/// 4. Project all lines forward
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Trend channel tool
|
||||||
|
/// - Support/resistance levels
|
||||||
|
/// - Price projection
|
||||||
|
/// - Market geometry
|
||||||
|
/// - Pivot-based analysis
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// Median Line = Line from P0 to (P1 + P2)/2
|
||||||
|
/// Upper Line = Parallel to median at P1
|
||||||
|
/// Lower Line = Parallel to median at P2
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Trend analysis
|
||||||
|
/// - Support/resistance
|
||||||
|
/// - Price targets
|
||||||
|
/// - Channel trading
|
||||||
|
/// - Market structure
|
||||||
|
///
|
||||||
|
/// Sources:
|
||||||
|
/// Dr. Alan Andrews
|
||||||
|
/// https://www.investopedia.com/terms/a/andrewspitchfork.asp
|
||||||
|
///
|
||||||
|
/// Note: Returns median line value for current price level
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Ap : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly CircularBuffer _highs;
|
||||||
|
private readonly CircularBuffer _lows;
|
||||||
|
private readonly CircularBuffer _closes;
|
||||||
|
private const int DefaultPeriod = 20;
|
||||||
|
|
||||||
|
/// <param name="period">The lookback period for pivot points (default 20).</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 3.</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Ap(int period = DefaultPeriod)
|
||||||
|
{
|
||||||
|
if (period < 3)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(period));
|
||||||
|
|
||||||
|
_highs = new(period);
|
||||||
|
_lows = new(period);
|
||||||
|
_closes = new(period);
|
||||||
|
WarmupPeriod = period;
|
||||||
|
Name = $"AP({period})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
/// <param name="period">The lookback period for pivot points.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Ap(object source, int period = DefaultPeriod) : this(period)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
private static (double x, double y) FindPivot(CircularBuffer highs, CircularBuffer lows, CircularBuffer closes, int offset)
|
||||||
|
{
|
||||||
|
double high = highs[offset];
|
||||||
|
double low = lows[offset];
|
||||||
|
double close = closes[offset];
|
||||||
|
return (offset, (high + low + close) / 3.0); // Simple pivot point calculation
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
// Store price data
|
||||||
|
_highs.Add(BarInput.High, BarInput.IsNew);
|
||||||
|
_lows.Add(BarInput.Low, BarInput.IsNew);
|
||||||
|
_closes.Add(BarInput.Close, BarInput.IsNew);
|
||||||
|
|
||||||
|
if (_index < WarmupPeriod)
|
||||||
|
return BarInput.Close;
|
||||||
|
|
||||||
|
// Find three pivot points
|
||||||
|
var p0 = FindPivot(_highs, _lows, _closes, 2);
|
||||||
|
var p1 = FindPivot(_highs, _lows, _closes, 1);
|
||||||
|
var p2 = FindPivot(_highs, _lows, _closes, 0);
|
||||||
|
|
||||||
|
// Calculate midpoint of P1-P2
|
||||||
|
double midX = (p1.x + p2.x) / 2.0;
|
||||||
|
double midY = (p1.y + p2.y) / 2.0;
|
||||||
|
|
||||||
|
// Calculate slope of median line
|
||||||
|
double slope = (midY - p0.y) / (midX - p0.x);
|
||||||
|
|
||||||
|
// Project median line to current bar
|
||||||
|
double currentX = _index - p0.x;
|
||||||
|
return p0.y + slope * currentX;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ATRP: Average True Range Percent
|
||||||
|
/// A volatility indicator that expresses ATR as a percentage of current price.
|
||||||
|
/// This normalization allows for comparison across different price levels and
|
||||||
|
/// instruments.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The ATRP calculation process:
|
||||||
|
/// 1. Calculate ATR normally
|
||||||
|
/// 2. Divide by current price
|
||||||
|
/// 3. Multiply by 100 for percentage
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Normalized volatility measure
|
||||||
|
/// - Price-independent comparison
|
||||||
|
/// - Percentage output
|
||||||
|
/// - Cross-market analysis
|
||||||
|
/// - Relative volatility measure
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// ATRP = (ATR / Close) * 100
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Cross-market comparison
|
||||||
|
/// - Position sizing
|
||||||
|
/// - Volatility analysis
|
||||||
|
/// - Risk assessment
|
||||||
|
/// - Market comparison
|
||||||
|
///
|
||||||
|
/// Note: More suitable for comparing different instruments than raw ATR
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Atrp : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly Atr _atr;
|
||||||
|
private const int DefaultPeriod = 14;
|
||||||
|
private const double ScalingFactor = 100.0;
|
||||||
|
|
||||||
|
/// <param name="period">The number of periods for ATR calculation (default 14).</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Atrp(int period = DefaultPeriod)
|
||||||
|
{
|
||||||
|
if (period < 1)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(period));
|
||||||
|
|
||||||
|
_atr = new(period);
|
||||||
|
WarmupPeriod = period;
|
||||||
|
Name = $"ATRP({period})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
/// <param name="period">The number of periods for ATR calculation.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Atrp(object source, int period = DefaultPeriod) : this(period)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
// Calculate ATR
|
||||||
|
double atr = _atr.Calc(BarInput);
|
||||||
|
|
||||||
|
// Convert to percentage of price
|
||||||
|
return Math.Abs(BarInput.Close) > double.Epsilon
|
||||||
|
? (atr / BarInput.Close) * ScalingFactor
|
||||||
|
: 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ATRS: ATR Trailing Stop
|
||||||
|
/// A volatility-based trailing stop indicator that uses ATR to dynamically adjust
|
||||||
|
/// stop levels. It helps maintain position while allowing for normal market
|
||||||
|
/// fluctuations.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The ATRS calculation process:
|
||||||
|
/// 1. Calculate ATR
|
||||||
|
/// 2. Multiply ATR by factor
|
||||||
|
/// 3. Apply trailing logic based on trend
|
||||||
|
/// 4. Update stop levels
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Dynamic stop levels
|
||||||
|
/// - Trend-following
|
||||||
|
/// - Volatility-based
|
||||||
|
/// - Position protection
|
||||||
|
/// - Risk management
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// Long Stop = High - (ATR * Factor)
|
||||||
|
/// Short Stop = Low + (ATR * Factor)
|
||||||
|
/// where Factor is multiplier for ATR (default 2.0)
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Stop loss placement
|
||||||
|
/// - Position management
|
||||||
|
/// - Trend following
|
||||||
|
/// - Risk control
|
||||||
|
/// - Exit strategy
|
||||||
|
///
|
||||||
|
/// Note: Returns stop level based on current trend
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Atrs : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly Atr _atr;
|
||||||
|
private double _prevStop;
|
||||||
|
private double _p_prevStop;
|
||||||
|
private bool _isLong;
|
||||||
|
private bool _p_isLong;
|
||||||
|
private const int DefaultPeriod = 14;
|
||||||
|
private const double DefaultFactor = 2.0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current trend direction (true for long, false for short)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsLong => _isLong;
|
||||||
|
|
||||||
|
/// <param name="period">The number of periods for ATR calculation (default 14).</param>
|
||||||
|
/// <param name="factor">The multiplier for ATR (default 2.0).</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1 or factor is less than or equal to 0.</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Atrs(int period = DefaultPeriod, double factor = DefaultFactor)
|
||||||
|
{
|
||||||
|
if (period < 1)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(period));
|
||||||
|
if (factor <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(factor));
|
||||||
|
|
||||||
|
_atr = new(period);
|
||||||
|
Factor = factor;
|
||||||
|
WarmupPeriod = period;
|
||||||
|
Name = $"ATRS({period},{factor:F1})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
/// <param name="period">The number of periods for ATR calculation.</param>
|
||||||
|
/// <param name="factor">The multiplier for ATR.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Atrs(object source, int period = DefaultPeriod, double factor = DefaultFactor) : this(period, factor)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the ATR multiplier factor
|
||||||
|
/// </summary>
|
||||||
|
public double Factor { get; set; }
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
base.Init();
|
||||||
|
_atr.Init();
|
||||||
|
_prevStop = double.NaN;
|
||||||
|
_isLong = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_index++;
|
||||||
|
_p_prevStop = _prevStop;
|
||||||
|
_p_isLong = _isLong;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_prevStop = _p_prevStop;
|
||||||
|
_isLong = _p_isLong;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
// Calculate ATR
|
||||||
|
double atr = _atr.Calc(BarInput);
|
||||||
|
double atrBand = atr * Factor;
|
||||||
|
|
||||||
|
if (_index == 1 || double.IsNaN(_prevStop))
|
||||||
|
{
|
||||||
|
// Initialize stop level
|
||||||
|
_isLong = BarInput.Close > BarInput.Open;
|
||||||
|
_prevStop = _isLong ? BarInput.Low - atrBand : BarInput.High + atrBand;
|
||||||
|
return _prevStop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update stop level based on trend
|
||||||
|
if (_isLong)
|
||||||
|
{
|
||||||
|
double newStop = BarInput.High - atrBand;
|
||||||
|
if (BarInput.Close < _prevStop)
|
||||||
|
{
|
||||||
|
_isLong = false;
|
||||||
|
_prevStop = BarInput.High + atrBand;
|
||||||
|
}
|
||||||
|
else if (newStop > _prevStop)
|
||||||
|
{
|
||||||
|
_prevStop = newStop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double newStop = BarInput.Low + atrBand;
|
||||||
|
if (BarInput.Close > _prevStop)
|
||||||
|
{
|
||||||
|
_isLong = true;
|
||||||
|
_prevStop = BarInput.Low - atrBand;
|
||||||
|
}
|
||||||
|
else if (newStop < _prevStop)
|
||||||
|
{
|
||||||
|
_prevStop = newStop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _prevStop;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
# Volatility indicators
|
# Volatility indicators
|
||||||
Done: 11, Todo: 24
|
Done: 15, Todo: 20
|
||||||
|
|
||||||
ADR - Average Daily Range
|
✔️ ADR - Average Daily Range
|
||||||
AP - Andrew's Pitchfork
|
✔️ AP - Andrew's Pitchfork
|
||||||
✔️ ATR - Average True Range
|
✔️ ATR - Average True Range
|
||||||
ATRP - Average True Range Percent
|
✔️ ATRP - Average True Range Percent
|
||||||
ATRS - ATR Trailing Stop
|
✔️ ATRS - ATR Trailing Stop
|
||||||
*BB - Bollinger Bands® (Upper, Middle, Lower)
|
*BB - Bollinger Bands® (Upper, Middle, Lower)
|
||||||
CCV - Close-to-Close Volatility
|
CCV - Close-to-Close Volatility
|
||||||
CE - Chandelier Exit
|
CE - Chandelier Exit
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// VF: Volume Force
|
||||||
|
/// A volume-based indicator that measures the strength of volume relative to price
|
||||||
|
/// movement. It helps identify whether volume is supporting or contradicting the
|
||||||
|
/// current price trend.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The VF calculation process:
|
||||||
|
/// 1. Calculate price change
|
||||||
|
/// 2. Calculate volume force as volume * price change
|
||||||
|
/// 3. Optionally smooth the result with EMA
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Volume-weighted measure
|
||||||
|
/// - Trend strength indicator
|
||||||
|
/// - No upper/lower bounds
|
||||||
|
/// - Raw and smoothed versions
|
||||||
|
/// - Divergence indicator
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// VF = Volume * (Close - Close[1])
|
||||||
|
/// Smoothed VF = EMA(VF, period)
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Volume analysis
|
||||||
|
/// - Trend confirmation
|
||||||
|
/// - Price/volume divergence
|
||||||
|
/// - Market participation
|
||||||
|
/// - Momentum confirmation
|
||||||
|
///
|
||||||
|
/// Note: Higher values indicate stronger volume force
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Vf : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly Ema _ema;
|
||||||
|
private double _prevClose;
|
||||||
|
private double _p_prevClose;
|
||||||
|
private const int DefaultPeriod = 13;
|
||||||
|
|
||||||
|
/// <param name="period">The smoothing period for EMA calculation (default 13).</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vf(int period = DefaultPeriod)
|
||||||
|
{
|
||||||
|
if (period < 1)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(period));
|
||||||
|
|
||||||
|
_ema = new(period);
|
||||||
|
WarmupPeriod = period + 1;
|
||||||
|
Name = $"VF({period})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
/// <param name="period">The smoothing period for EMA calculation.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vf(object source, int period = DefaultPeriod) : this(period)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
base.Init();
|
||||||
|
_ema.Init();
|
||||||
|
_prevClose = double.NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
{
|
||||||
|
_index++;
|
||||||
|
_p_prevClose = _prevClose;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_prevClose = _p_prevClose;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
if (_index == 1)
|
||||||
|
{
|
||||||
|
_prevClose = BarInput.Close;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate raw volume force
|
||||||
|
double priceChange = BarInput.Close - _prevClose;
|
||||||
|
double volumeForce = BarInput.Volume * priceChange;
|
||||||
|
|
||||||
|
// Update previous close
|
||||||
|
_prevClose = BarInput.Close;
|
||||||
|
|
||||||
|
// Apply EMA smoothing
|
||||||
|
return _ema.Calc(volumeForce, BarInput.IsNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// VP: Volume Profile
|
||||||
|
/// A volume-based indicator that analyzes volume distribution across price levels.
|
||||||
|
/// It helps identify significant price levels where most trading activity occurs.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The VP calculation process:
|
||||||
|
/// 1. Track volume at each price level within a period
|
||||||
|
/// 2. Calculate Point of Control (POC) - price with highest volume
|
||||||
|
/// 3. Calculate Value Area (70% of total volume)
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Price level analysis
|
||||||
|
/// - Volume distribution
|
||||||
|
/// - Support/resistance identification
|
||||||
|
/// - Trading activity concentration
|
||||||
|
/// - Market structure analysis
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// VP = Σ Volume at each price level
|
||||||
|
/// POC = Price level with max volume
|
||||||
|
/// Value Area = Price range containing 70% of volume
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Support/resistance levels
|
||||||
|
/// - Market structure analysis
|
||||||
|
/// - Trading activity patterns
|
||||||
|
/// - Price level significance
|
||||||
|
/// - Volume concentration
|
||||||
|
///
|
||||||
|
/// Note: Returns Point of Control (price level with highest volume)
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Vp : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly CircularBuffer _volumes;
|
||||||
|
private readonly CircularBuffer _prices;
|
||||||
|
private const int DefaultPeriod = 14;
|
||||||
|
|
||||||
|
/// <param name="period">The number of periods to analyze volume distribution (default 14).</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vp(int period = DefaultPeriod)
|
||||||
|
{
|
||||||
|
if (period < 1)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(period));
|
||||||
|
|
||||||
|
_volumes = new(period);
|
||||||
|
_prices = new(period);
|
||||||
|
WarmupPeriod = period;
|
||||||
|
Name = $"VP({period})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
/// <param name="period">The number of periods to analyze volume distribution.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vp(object source, int period = DefaultPeriod) : this(period)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
private static int FindMaxVolumeIndex(CircularBuffer volumes)
|
||||||
|
{
|
||||||
|
int maxIndex = 0;
|
||||||
|
double maxVolume = volumes[0];
|
||||||
|
|
||||||
|
for (int i = 1; i < volumes.Count; i++)
|
||||||
|
{
|
||||||
|
if (volumes[i] > maxVolume)
|
||||||
|
{
|
||||||
|
maxVolume = volumes[i];
|
||||||
|
maxIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
// Store volume and price
|
||||||
|
_volumes.Add(BarInput.Volume, BarInput.IsNew);
|
||||||
|
_prices.Add(BarInput.Close, BarInput.IsNew);
|
||||||
|
|
||||||
|
// Find price level with highest volume (Point of Control)
|
||||||
|
int pocIndex = FindMaxVolumeIndex(_volumes);
|
||||||
|
return _prices[pocIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// VWAP: Volume Weighted Average Price
|
||||||
|
/// A trading benchmark that shows the ratio of the value traded to total volume
|
||||||
|
/// traded over a specific period. VWAP equals the dollar value of all trading
|
||||||
|
/// periods divided by the total trading volume for the current day.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The VWAP calculation process:
|
||||||
|
/// 1. Calculate typical price for each period
|
||||||
|
/// 2. Multiply typical price by volume
|
||||||
|
/// 3. Calculate cumulative values
|
||||||
|
/// 4. Divide cumulative (price * volume) by cumulative volume
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Intraday trading benchmark
|
||||||
|
/// - Volume-weighted measure
|
||||||
|
/// - Institutional trading reference
|
||||||
|
/// - Price momentum indicator
|
||||||
|
/// - Trading efficiency measure
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// VWAP = Σ(Price * Volume) / ΣVolume
|
||||||
|
/// where Price = (High + Low + Close)/3
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Best execution analysis
|
||||||
|
/// - Trading algorithms
|
||||||
|
/// - Price momentum
|
||||||
|
/// - Market impact analysis
|
||||||
|
/// - Order timing
|
||||||
|
///
|
||||||
|
/// Sources:
|
||||||
|
/// https://www.investopedia.com/terms/v/vwap.asp
|
||||||
|
///
|
||||||
|
/// Note: Commonly used by institutional traders
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Vwap : AbstractBase
|
||||||
|
{
|
||||||
|
private double _cumulativeTPV; // Cumulative (Typical Price * Volume)
|
||||||
|
private double _cumulativeVolume;
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vwap()
|
||||||
|
{
|
||||||
|
WarmupPeriod = 1;
|
||||||
|
Name = "VWAP";
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vwap(object source) : this()
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
base.Init();
|
||||||
|
_cumulativeTPV = 0;
|
||||||
|
_cumulativeVolume = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
// Update cumulative values only for new bars
|
||||||
|
if (BarInput.IsNew)
|
||||||
|
{
|
||||||
|
_cumulativeTPV += BarInput.HLC3 * BarInput.Volume;
|
||||||
|
_cumulativeVolume += BarInput.Volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate VWAP
|
||||||
|
return _cumulativeVolume > 0 ? _cumulativeTPV / _cumulativeVolume : BarInput.HLC3;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
namespace QuanTAlib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// VWMA: Volume Weighted Moving Average
|
||||||
|
/// A technical indicator that combines price and volume to show the average price
|
||||||
|
/// weighted by volume over a period. It gives more weight to prices with higher
|
||||||
|
/// volume, making it more responsive to high-volume price movements.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The VWMA calculation process:
|
||||||
|
/// 1. Multiply price by volume for each period
|
||||||
|
/// 2. Sum (price * volume) over the period
|
||||||
|
/// 3. Sum volume over the period
|
||||||
|
/// 4. Divide sums to get weighted average
|
||||||
|
///
|
||||||
|
/// Key characteristics:
|
||||||
|
/// - Volume-sensitive average
|
||||||
|
/// - Trend indicator
|
||||||
|
/// - Support/resistance levels
|
||||||
|
/// - Price momentum
|
||||||
|
/// - Volume emphasis
|
||||||
|
///
|
||||||
|
/// Formula:
|
||||||
|
/// VWMA = Σ(Price * Volume) / ΣVolume
|
||||||
|
/// where sums are taken over the specified period
|
||||||
|
///
|
||||||
|
/// Market Applications:
|
||||||
|
/// - Trend identification
|
||||||
|
/// - Support/resistance levels
|
||||||
|
/// - Volume analysis
|
||||||
|
/// - Price momentum
|
||||||
|
/// - Trading signals
|
||||||
|
///
|
||||||
|
/// Note: More responsive to high-volume price movements
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[SkipLocalsInit]
|
||||||
|
public sealed class Vwma : AbstractBase
|
||||||
|
{
|
||||||
|
private readonly CircularBuffer _priceVolume;
|
||||||
|
private readonly CircularBuffer _volume;
|
||||||
|
private const int DefaultPeriod = 20;
|
||||||
|
|
||||||
|
/// <param name="period">The number of periods for VWMA calculation (default 20).</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when period is less than 1.</exception>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vwma(int period = DefaultPeriod)
|
||||||
|
{
|
||||||
|
if (period < 1)
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(period));
|
||||||
|
|
||||||
|
_priceVolume = new(period);
|
||||||
|
_volume = new(period);
|
||||||
|
WarmupPeriod = period;
|
||||||
|
Name = $"VWMA({period})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <param name="source">The data source object that publishes updates.</param>
|
||||||
|
/// <param name="period">The number of periods for VWMA calculation.</param>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Vwma(object source, int period = DefaultPeriod) : this(period)
|
||||||
|
{
|
||||||
|
var pubEvent = source.GetType().GetEvent("Pub");
|
||||||
|
pubEvent?.AddEventHandler(source, new BarSignal(Sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected override void ManageState(bool isNew)
|
||||||
|
{
|
||||||
|
if (isNew)
|
||||||
|
_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
protected override double Calculation()
|
||||||
|
{
|
||||||
|
ManageState(BarInput.IsNew);
|
||||||
|
|
||||||
|
// Calculate and store price * volume
|
||||||
|
double priceVolume = BarInput.Close * BarInput.Volume;
|
||||||
|
_priceVolume.Add(priceVolume, BarInput.IsNew);
|
||||||
|
_volume.Add(BarInput.Volume, BarInput.IsNew);
|
||||||
|
|
||||||
|
// Calculate sums
|
||||||
|
double sumPriceVolume = _priceVolume.Sum();
|
||||||
|
double sumVolume = _volume.Sum();
|
||||||
|
|
||||||
|
// Calculate VWMA
|
||||||
|
return sumVolume > 0 ? sumPriceVolume / sumVolume : BarInput.Close;
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-5
@@ -1,5 +1,5 @@
|
|||||||
# Volume indicators
|
# Volume indicators
|
||||||
Done: 15, Todo: 3
|
Done: 19, Todo: 0
|
||||||
|
|
||||||
✔️ ADL - Chaikin Accumulation Distribution Line
|
✔️ ADL - Chaikin Accumulation Distribution Line
|
||||||
✔️ ADOSC - Chaikin Accumulation Distribution Oscillator
|
✔️ ADOSC - Chaikin Accumulation Distribution Oscillator
|
||||||
@@ -16,7 +16,7 @@ Done: 15, Todo: 3
|
|||||||
✔️ PVR - Price Volume Rank
|
✔️ PVR - Price Volume Rank
|
||||||
✔️ PVT - Price Volume Trend
|
✔️ PVT - Price Volume Trend
|
||||||
✔️ TVI - Trade Volume Index
|
✔️ TVI - Trade Volume Index
|
||||||
VF - Volume Force
|
✔️ VF - Volume Force
|
||||||
VP - Volume Profile
|
✔️ VP - Volume Profile
|
||||||
VWAP - Volume Weighted Average Price
|
✔️ VWAP - Volume Weighted Average Price
|
||||||
VWMA - Volume Weighted Moving Average
|
✔️ VWMA - Volume Weighted Moving Average
|
||||||
|
|||||||
Reference in New Issue
Block a user