Diagram.Core provides the fundamental building blocks for StockSharp's visual strategy designer. It contains the classes that allow trading algorithms to be represented as diagrams and executed as regular strategies.
- Diagram Elements and Sockets — base types such as
DiagramElementandDiagramSocketdefine nodes and their connection points. Elements can emit and receive values to build complex trading logic. - Composite Elements —
CompositionDiagramElementmanages nested diagrams and exposes parameters and sockets of child elements. - Strategy Integration —
DiagramStrategyruns a diagram as a regularStrategy, enabling optimization and backtesting. - Undo/Redo Support — interfaces like
IUndoManagerprovide transaction based change tracking. - External Code — the
DiagramExternalAttributeallows methods to be exposed as diagram elements. A small helper script (python/designer_extensions.py) makes this available in Python.
- Reference StockSharp.Diagram.Core from your project (via the StockSharp NuGet feed or by adding the project to your solution).
- Create diagram elements by deriving from
DiagramElementand define sockets and parameters. - Combine elements inside a
CompositionDiagramElementor execute them throughDiagramStrategy.
Example of exposing a Python function as an external element:
import clr
clr.AddReference("StockSharp.Diagram.Core")
from StockSharp.Diagram import DiagramExternalAttribute
# Decorator to mark methods as external diagram elements
def diagram_external(func):
func.__dict__['__diagram_external__'] = DiagramExternalAttribute()
return funcThe above decorator adds the DiagramExternalAttribute to Python functions so they can be used in the Designer.