This directory contains a comprehensive template for building study plugins for VisualHFT. The template includes all necessary components, best practices, and documentation to help developers create robust study plugins from scratch.
- Copy the template - Duplicate this folder and rename it to your study name
- Update namespace - Replace
VisualHFT.Studies.Templatewith your study name (e.g.,VisualHFT.Studies.MyStudy) - Implement calculation logic - Follow the TODO comments in
TemplateStudyPlugin.cs - Customize settings - Update
PlugInSettings.csto match your study's configuration needs - Modify the UI - Adjust
PluginSettingsView.xamlfor your specific settings - Build and test - Compile and place the DLL in VisualHFT's plugins folder
- StudySDK_Guidelines.md - Comprehensive development guide for study plugins
SDK-StudyTemplate/
├── TemplateStudyPlugin.cs # Main plugin class derived from BasePluginStudy
├── Study.Template.csproj # Project configuration
├── ViewModels/ # MVVM ViewModels
│ ├── PluginSettingsViewModel.cs # Settings UI logic with validation
│ └── TemplateStudyViewModel.cs # Optional: Custom UI view model
├── Model/ # Data models
│ └── PlugInSettings.cs # Configuration settings for the study
├── UserControls/ # WPF UI
│ ├── PluginSettingsView.xaml # Settings UI definition
│ ├── PluginSettingsView.xaml.cs # Code-behind
│ ├── TemplateStudyView.xaml # Optional: Custom visualization UI
│ └── TemplateStudyView.xaml.cs # Optional: Custom visualization code-behind
├── StudySDK_Guidelines.md # Development guide
└── README.md # This file
✅ Complete Study Architecture - Full implementation with proper inheritance from BasePluginStudy
✅ Market Data Processing - Built-in hooks for processing order book data
✅ Calculation Framework - Structure for implementing custom study calculations
✅ Alert System - Built-in alert triggering with configurable thresholds
✅ MVVM Settings UI - WPF user control with validation and data binding
✅ Optional Custom UI - Template for creating custom visualizations (charts, indicators)
✅ Thread-Safe Operations - Proper locking mechanisms for concurrent access
✅ Error Handling - Comprehensive logging and error management
✅ Resource Management - Proper disposal pattern implementation
Study plugins in VisualHFT are designed to analyze market data and generate insights, indicators, or alerts. Unlike market connectors that fetch data, study plugins:
- Receive market data through the base class infrastructure
- Perform calculations on the received data
- Emit results through the
OnCalculatedevent - Trigger alerts when conditions are met through
OnAlertTriggered - Provide configuration through a settings UI
The BasePluginStudy class provides:
- Data Subscription: Automatic subscription to market data based on settings
- Queue Management: Thread-safe queue for incoming market data
- Calculation Hooks: Override
Calculate()method to implement your logic - Event Infrastructure: Built-in events for results and alerts
- Settings Management: Load/save/initialize settings framework
- Initialization: Constructor runs, settings are loaded
- Start:
StartAsync()called, data subscription begins - Processing: Market data triggers
Calculate()method - Results:
OnCalculatedevent emits study results - Alerts:
OnAlertTriggeredevent fires on alert conditions - Stop:
StopAsync()called, subscription ends - Dispose: Resources cleaned up
protected override void Calculate(List<BookItem> data)
{
// Your calculation logic here
// Example: Moving average, volatility, correlation, etc.
var result = YourCalculation(data);
// Emit result
var studyModel = new BaseStudyModel
{
Timestamp = DateTime.UtcNow,
Value = result,
Symbol = _settings.Symbol,
Provider = _settings.Provider.ProviderID
};
OnCalculated?.Invoke(this, studyModel);
}Edit PlugInSettings.cs to add your study-specific parameters:
public class PlugInSettings : ISetting
{
// Standard settings
public string Symbol { get; set; }
public Provider Provider { get; set; }
public AggregationLevel AggregationLevel { get; set; }
// Your custom settings
public int LookbackPeriod { get; set; } = 20;
public double Threshold { get; set; } = 0.5;
public bool EnableSmoothing { get; set; } = true;
}Modify PluginSettingsView.xaml to include controls for your settings:
<!-- Add your custom controls -->
<Label Content="Lookback Period"/>
<TextBox Text="{Binding LookbackPeriod, UpdateSourceTrigger=PropertyChanged}" />
<Label Content="Threshold"/>
<TextBox Text="{Binding Threshold, UpdateSourceTrigger=PropertyChanged}" />If your study needs custom visualization:
// In your plugin class
private TemplateStudyView _customView;
public override void Initialize()
{
_customView = new TemplateStudyView();
// Register with VisualHFT framework
}
// Update the view when calculations complete
private void UpdateVisualization(double value)
{
_customView?.UpdateValue(value, DateTime.UtcNow);
}private void CheckAlertCondition(double value)
{
if (value > _settings.Threshold)
{
OnAlertTriggered?.Invoke(this, (decimal)value);
}
}- Thread Safety: Always use locks when accessing shared state
- Performance: Minimize allocations in the
Calculate()method - Validation: Validate all settings before starting
- Logging: Log important events and errors
- Disposal: Properly dispose of resources in
Dispose()
- Technical Indicators: RSI, MACD, Bollinger Bands
- Statistical Analysis: Volatility, Correlation, Regression
- Order Book Analysis: Imbalance, Depth, Spread Analysis
- Volume Analysis: VWAP, Volume Profile, Flow Analysis
- Custom Algorithms: Proprietary calculations and signals
- Unit Tests: Test calculation logic with sample data
- Integration Tests: Test with live market data
- UI Tests: Verify settings validation and persistence
- Performance Tests: Monitor CPU/memory usage
- Build the project in Release mode
- Copy the DLL to VisualHFT's Plugins folder
- Restart VisualHFT
- Configure your study in the Settings dialog
- Add to a dashboard to see results
- Check the VisualHFT documentation for more details
- Review existing study plugins in
VisualHFT.Plugins/Studies.*for examples - Use the debug log to troubleshoot issues