mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-17 18:18:04 +00:00
Refactor code formatting and improve consistency across various test files
- Removed unnecessary blank lines in multiple test files to enhance readability. - Ensured consistent spacing and formatting in the `Trima`, `Usf`, `Vidya`, `Wma`, and `Atr` test classes. - Updated comments for clarity and consistency in the `Atr` and `Adl` classes. - Adjusted project files for better structure and maintainability.
This commit is contained in:
+6
-6
@@ -33,7 +33,7 @@ Every indicator exposes the following core properties and methods:
|
||||
|
||||
## 2. Mode A: Batch (Stateless)
|
||||
|
||||
**Purpose:** Backtesting, Data Analysis, Optimization
|
||||
**Purpose:** Backtesting, Data Analysis, Optimization
|
||||
**Method:** `static Batch`
|
||||
|
||||
Batch mode provides stateless, SIMD-accelerated processing of historical arrays. It is optimized for maximum throughput and zero heap allocation.
|
||||
@@ -67,7 +67,7 @@ TSeries sma = Sma.Batch(history, 14);
|
||||
|
||||
## 3. Mode B: Streaming (Stateful)
|
||||
|
||||
**Purpose:** Live Trading, Event Processing
|
||||
**Purpose:** Live Trading, Event Processing
|
||||
**Method:** `Update`
|
||||
|
||||
Streaming mode handles real-time data ingestion using O(1) complexity per update. It maintains internal state (circular buffers, running sums) to process ticks with minimal latency.
|
||||
@@ -109,7 +109,7 @@ var sma = new Sma(source, 14);
|
||||
var ema = new Ema(sma, 5);
|
||||
|
||||
// Updates flow automatically
|
||||
source.Add(new TValue(time, price));
|
||||
source.Add(new TValue(time, price));
|
||||
// sma updates, then ema updates automatically
|
||||
```
|
||||
|
||||
@@ -117,7 +117,7 @@ source.Add(new TValue(time, price));
|
||||
|
||||
## 4. Mode C: Priming (The Bridge)
|
||||
|
||||
**Purpose:** Switching from Batch to Streaming
|
||||
**Purpose:** Switching from Batch to Streaming
|
||||
**Method:** `Prime`
|
||||
|
||||
Priming mode hydrates a streaming instance using the minimal required tail of historical data. It calculates the intersection of *History Available* and *State Required*, allowing an indicator to become "Hot" without processing the entire history.
|
||||
@@ -132,7 +132,7 @@ double[] history = ...; // e.g., 100,000 bars
|
||||
|
||||
// Efficiently processes only the last 'period' bars needed to fill the buffer
|
||||
// O(Warmup) initialization instead of O(History)
|
||||
indicator.Prime(history);
|
||||
indicator.Prime(history);
|
||||
|
||||
// Indicator is now "Hot" and ready for the next live tick
|
||||
Console.WriteLine(indicator.IsHot); // true
|
||||
@@ -193,7 +193,7 @@ The initial portion of the output contains "cold" values.
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
H[Historical Data]
|
||||
H[Historical Data]
|
||||
L[Live Data]
|
||||
|
||||
subgraph "Mode A: Batch"
|
||||
|
||||
+4
-4
@@ -36,7 +36,7 @@ public class MySmaIndicator : Indicator
|
||||
{
|
||||
// Get price from Quantower
|
||||
double price = ClosePrice;
|
||||
|
||||
|
||||
// Update QuanTAlib
|
||||
// Note: Quantower handles bar updates, so a check is performed to determine whether this is a new bar or an update
|
||||
bool isNew = args.Reason == UpdateReason.NewBar;
|
||||
@@ -73,10 +73,10 @@ protected override void OnBarUpdate()
|
||||
{
|
||||
// NinjaTrader calls OnBarUpdate for every tick (if Calculate = OnEachTick)
|
||||
// or once per bar (if Calculate = OnBarClose)
|
||||
|
||||
|
||||
bool isNew = IsFirstTickOfBar; // Logic depends on Calculate mode
|
||||
var result = _sma.Update(new TValue(Time[0], Close[0]), isNew);
|
||||
|
||||
|
||||
Value[0] = result.Value;
|
||||
}
|
||||
```
|
||||
@@ -104,7 +104,7 @@ public class MyAlgorithm : QCAlgorithm
|
||||
{
|
||||
var bar = data.Bars["SPY"];
|
||||
var result = _mySma.Update(new TValue(bar.EndTime, (double)bar.Close));
|
||||
|
||||
|
||||
if (_mySma.IsHot)
|
||||
{
|
||||
Plot("Indicators", "SMA", result.Value);
|
||||
|
||||
Reference in New Issue
Block a user