Click or drag to resize

Strategy Class

The base class for all trade strategies.
Inheritance Hierarchy

Namespace:  StockSharp.Algo.Strategies
Assembly:  StockSharp.Algo (in StockSharp.Algo.dll) Version: 4.3.27.2 (4.3.27.2)
Syntax
C#
public class Strategy : BaseLogReceiver, INotifyPropertyChangedEx, 
	INotifyPropertyChanged, IMarketRuleContainer, ILogReceiver, ILogSource, IDisposable, 
	ICloneable<Strategy>, ICloneable, IMarketDataProvider, ISecurityProvider

The Strategy type exposes the following members.

Constructors
  NameDescription
Public methodStrategy
Initializes a new instance of the Strategy.
Top
Properties
  NameDescription
Public propertyCancelOrdersWhenStopping
To cancel active orders at stop. Is On by default.
Public propertyChildStrategies
Subsidiary trade strategies.
Public propertyCommentOrders
To add to Comment the name of the strategy Name, registering the order.
Public propertyCommission
Total commission.
Public propertyConnector
Connection to the trading system.
Public propertyCurrentTime
Current time, which will be passed to the Time.
(Overrides BaseLogSourceCurrentTime.)
Public propertyDisposeOnStop
Automatically to clear resources, used by the strategy, when it stops (state ProcessState becomes equal to Stopped) and delete it from the parent strategy through ChildStrategies.
Public propertyEnvironment
Strategy environment parameters.
Public propertyErrorCount
The current number of errors.
Public propertyErrorState
The state of an error.
Public propertyId
The unique identifier of the source.
(Overrides BaseLogSourceId.)
Public propertyIsDisposed (Inherited from Disposable.)
Public propertyIsRoot
Whether the source is the root (even if Parent is not equal to ).
(Inherited from BaseLogSource.)
Public propertyIsRulesSuspended
Is rules execution suspended.
Public propertyLatency
Total latency.
Public propertyLogLevel
The logging level. The default is set to Inherit.
(Overrides BaseLogSourceLogLevel.)
Public propertyMaxErrorCount
The maximal number of errors, which strategy shall receive prior to stop operation.
Public propertyMyTrades
Trades, matched during the strategy operation.
Public propertyName
Strategy name.
(Overrides BaseLogSourceName.)
Public propertyNameGenerator
The generator of strategy name.
Public propertyOrderFails
Orders with errors, registered within the strategy.
Public propertyOrders
Orders, registered within the strategy framework.
Public propertyOrdersKeepTime
The time for storing Orders and StopOrders orders in memory. By default it equals to 2 days. If value is set in Zero, orders will not be deleted.
Public propertyParameters
Strategy parameters.
Public propertyParent
Parent.
(Inherited from BaseLogSource.)
Public propertyPnL
The aggregate value of profit-loss without accounting commission Commission.
Public propertyPnLManager
The profit-loss manager. It accounts trades of this strategy, as well as of its subsidiary strategies ChildStrategies.
Public propertyPortfolio
Portfolio.
Public propertyPosition
The position aggregate value.
Public propertyPositionManager
The position manager. It accounts trades of this strategy, as well as of its subsidiary strategies ChildStrategies.
Public propertyProcessState
The operation state.
Public propertyRiskManager
The risks control manager.
Public propertyRules
Registered rules.
Public propertySecurity
Security.
Public propertySlippage
Total slippage.
Public propertyStartedTime
Strategy start time.
Public propertyStatisticManager
The statistics manager.
Public propertyStopOrders
Stop-orders, registered within the strategy framework.
Public propertyTotalWorkingTime
The total time of strategy operation less time periods, when strategy was stopped.
Public propertyUnrealizedPnLInterval
The interval for unrealized profit recalculation. The default value is 1 minute.
Public propertyVolume
Operational volume.
Public propertyWaitAllTrades
Stop strategy only after getting all trades by registered orders.
Top
Methods
  NameDescription
Protected methodAssignOrderStrategyId
To set the strategy identifier for the order.
Public methodAttachOrder
To add the active order to the strategy and process trades by the order.
Public methodCancelActiveOrders
To cancel all active orders (to stop and regular).
Public methodCancelOrder
Cancel order.
Public methodClone
Create a copy of Strategy.
Public methodDispose (Inherited from Disposable.)
Protected methodDisposeManaged
Release resources.
(Overrides Disposable.DisposeManaged.)
Protected methodDisposeNative (Inherited from Disposable.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize (Inherited from Disposable.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetLevel1Fields
To get a set of available fields Level1Fields, for which there is a market data for the instrument.
Public methodGetMarketDepth
To get the quotes order book.
Public methodGetSecurityValue
To get the value of market data for the instrument.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodLoad
Load settings.
(Overrides BaseLogSourceLoad(SettingsStorage).)
Public methodLookup
Lookup securities by criteria criteria.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnError
Processing of error, occurred as result of strategy operation.
Protected methodOnNewMyTrade
The method, called at occurrence of new strategy trade.
Protected methodOnOrderCanceling
To call the event OrderRegistered.
Protected methodOnOrderChanged
The method, called at strategy order change.
Protected methodOnOrderRegistered
To call the event OrderRegistered.
Protected methodOnOrderRegisterFailed
The method, called at strategy order registration error.
Protected methodOnOrderRegistering
To call the event OrderRegistering.
Protected methodOnOrderReRegistering
To call the event OrderReRegistering.
Protected methodOnPositionChanged
The method, called at strategy position change.
Protected methodOnReseted
Protected methodOnStarted
The method is called when the Start method has been called and the ProcessState state has been taken the Started value.
Protected methodOnStopOrderCanceling
To call the event StopOrderRegistered.
Protected methodOnStopOrderChanged
The method, called at strategy stop order change.
Protected methodOnStopOrderRegistered
To call the event StopOrderRegistered.
Protected methodOnStopOrderRegisterFailed
The method, called at strategy stop order registration error.
Protected methodOnStopOrderRegistering
To call the event StopOrderRegistering.
Protected methodOnStopOrderReRegistering
To call the event StopOrderReRegistering.
Protected methodOnStopOrdersChanged
The method, called at strategy stop orders change.
Protected methodOnStopped
The method is called when the ProcessState process state has been taken the Stopped value.
Protected methodOnStopping
The method is called when the ProcessState process state has been taken the Stopping value.
Protected methodProcessCancelActiveOrders
To cancel all active orders (to stop and regular).
Protected methodProcessNewOrders
To process orders, received for the connection Connector, and find among them those, belonging to the strategy.
Protected methodRaiseLog
To call the event Log.
(Overrides BaseLogSourceRaiseLog(LogMessage).)
Protected methodRaiseParametersChanged
To call events ParametersChanged and PropertyChanged.
Protected methodRaiseProcessStateChanged
To call the event ProcessStateChanged.
Public methodRegisterOrder
To register the order and automatically add to start mechanism of profit-loss and slippage.
Public methodReRegisterOrder
To re-register the order and automatically add to start mechanism of profit-loss and slippage.
Public methodReset
To re-initialize the trade algorithm. It is called after initialization of the strategy object and loading stored parameters.
Public methodSafeGetConnector
To get the strategy getting Connector. If it is not initialized, the exception will be discarded.
Public methodSave
Save settings.
(Overrides BaseLogSourceSave(SettingsStorage).)
Public methodStart
To start the trade algorithm.
Public methodStop
To stop the trade algorithm.
Protected methodThrowIfDisposed (Inherited from Disposable.)
Public methodToString
Returns a string that represents the current object.
(Inherited from BaseLogSource.)
Top
Events
  NameDescription
Public eventCommissionChanged
Commission change event.
Public eventConnectorChanged
The event of strategy connection change.
Public eventError
The event of error occurrence in the strategy.
Public eventLatencyChanged
Latency change event.
Public eventLog
New debug message event.
(Inherited from BaseLogSource.)
Public eventNewMyTrade
The event of new trade occurrence.
Public eventOrderCancelFailed
The event of order cancelling order.
Public eventOrderCanceling
The event of sending order for cancelling.
Public eventOrderChanged
The event of order change.
Public eventOrderRegistered
The event of order successful registration.
Public eventOrderRegisterFailed
The event of order registration error.
Public eventOrderRegistering
The event of sending order for registration.
Public eventOrderReRegistering
The event of sending order for re-registration.
Public eventParametersChanged
Parameters change event.
Public eventPnLChanged
PnL change event.
Public eventPortfolioChanged
The event of strategy portfolio change.
Public eventPositionChanged
Position change event.
Public eventPositionChanged2
The event of strategy position change.
Public eventProcessStateChanged
ProcessState change event.
Public eventPropertyChanged
The event of strategy parameters change.
Public eventReseted
The event of the strategy re-initialization.
Public eventSecurityChanged
The event of strategy instrument change.
Public eventSlippageChanged
Slippage change event.
Public eventStopOrderCancelFailed
The event of stop-order cancelling order.
Public eventStopOrderCanceling
The event of sending stop-order for cancelling.
Public eventStopOrderChanged
The event of stop-order change.
Public eventStopOrderRegistered
The event of stop-order successful registration.
Public eventStopOrderRegisterFailed
The event of stop-order registration error.
Public eventStopOrderRegistering
The event of sending stop-order for registration.
Public eventStopOrderReRegistering
The event of sending stop-order for re-registration.
Public eventValuesChanged
Security changed.
Top
Extension Methods
  NameDescription
Public Extension MethodActiveRule
To activate the rule.
(Defined by MarketRuleHelper.)
Public Extension MethodAddDebugLog
To record a debug message to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddErrorLog(FuncString)Overloaded.
To record an error to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddErrorLog(Exception)Overloaded.
To record an error to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddErrorLog(Exception, String)Overloaded.
To record an error to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddErrorLog(String, Object)Overloaded.
To record an error to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddInfoLog(FuncString)Overloaded.
To record a message to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddInfoLog(String, Object)Overloaded.
To record a message to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddLog
To record a message to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddOrderErrorLog
Write order error to the log.
(Defined by TraderHelper.)
Public Extension MethodAddOrderInfoLog
Write order info to the log.
(Defined by TraderHelper.)
Public Extension MethodAddRuleLog
To write the message from the rule.
(Defined by MarketRuleHelper.)
Public Extension MethodAddVerboseLog
To record a verbose message to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddWarningLog(FuncString)Overloaded.
To record a warning to the log.
(Defined by LoggingHelper.)
Public Extension MethodAddWarningLog(String, Object)Overloaded.
To record a warning to the log.
(Defined by LoggingHelper.)
Public Extension MethodBuyAtLimit
To create the initialized order object for buy.
(Defined by StrategyHelper.)
Public Extension MethodBuyAtMarket
To create initialized object of buy order at market price.
(Defined by StrategyHelper.)
Public Extension MethodClosePosition
To close open position by market (to register the order of the type Market).
(Defined by StrategyHelper.)
Public Extension MethodClosePositionByQuoting
To close the open position via quoting.
(Defined by Extensions.)
Public Extension MethodCreateOrder
To create the initialized order object.
(Defined by StrategyHelper.)
Public Extension MethodGetAllSecurity
Find AllSecurity instance in the specified provider.
(Defined by TraderHelper.)
Public Extension MethodGetCandleManager
To get the candle manager, associated with the passed strategy.
(Defined by StrategyHelper.)
Public Extension MethodGetChart
To get the chart associated with the passed strategy.
(Defined by ChartHelper.)
Public Extension MethodGetIsEmulation
To get the strategy start-up mode (paper trading or real).
(Defined by StrategyHelper.)
Public Extension MethodGetIsInitialization
To get the strategy operation mode (initialization or trade).
(Defined by StrategyHelper.)
Public Extension MethodGetLogLevel
Get LogLevel for the source. If the value is equal to Inherit, then parental source level is taken.
(Defined by LoggingHelper.)
Public Extension MethodGetSecurityValueT(Level1Fields)Overloaded.
To get market data value for the strategy instrument.
(Defined by StrategyHelper.)
Public Extension MethodGetSecurityValueT(Security, Level1Fields)Overloaded.
To get the value of market data for the instrument.
(Defined by TraderHelper.)
Public Extension MethodGetSecurityValues
To get all market data values for the instrument.
(Defined by TraderHelper.)
Public Extension MethodLoadState
To restore the strategy state.
(Defined by StrategyHelper.)
Public Extension MethodLookupAll
Get all available instruments.
(Defined by TraderHelper.)
Public Extension MethodLookupByCode
To get the instrument by the instrument code.
(Defined by TraderHelper.)
Public Extension MethodLookupById(String)Overloaded.
To get the instrument by the identifier.
(Defined by TraderHelper.)
Public Extension MethodLookupById(SecurityId)Overloaded.
To get the instrument by the identifier.
(Defined by TraderHelper.)
Public Extension MethodLookupByNativeId
To get the instrument by the system identifier.
(Defined by TraderHelper.)
Public Extension MethodOpenPositionByQuoting
To open the position via quoting.
(Defined by Extensions.)
Public Extension MethodParamT (Defined by StrategyParamHelper.)
Public Extension MethodSellAtLimit
To create the initialized order object for sell.
(Defined by StrategyHelper.)
Public Extension MethodSellAtMarket
To create the initialized order object of sell order at market price.
(Defined by StrategyHelper.)
Public Extension MethodSetCandleManager
To set the candle manager for the strategy.
(Defined by StrategyHelper.)
Public Extension MethodSetChart
To set a chart for the strategy.
(Defined by ChartHelper.)
Public Extension MethodSetIsEmulation
To get the strategy start-up mode (paper trading or real).
(Defined by StrategyHelper.)
Public Extension MethodSetIsInitialization
To set the strategy operation mode (initialization or trade).
(Defined by StrategyHelper.)
Public Extension MethodSuspendRules
To process rules in suspended mode (for example, create several rules and start them up simultaneously). After completion of method operation all rules, attached to the container resume their activity.
(Defined by MarketRuleHelper.)
Public Extension MethodTryRemoveRule
To delete a rule. If a rule is executed at the time when this method is called, it will not be deleted.
(Defined by MarketRuleHelper.)
Public Extension MethodTryRemoveWithExclusive
To delete the rule and all opposite rules. If the rule is executed at the time when this method is called, it will not be deleted.
(Defined by MarketRuleHelper.)
Public Extension MethodWhenError
To create a rule for event of strategy error (transition of state ErrorState into Error).
(Defined by StrategyHelper.)
Public Extension MethodWhenNewMyTrade
To create a rule for the event of occurrence new strategy trade.
(Defined by StrategyHelper.)
Public Extension MethodWhenOrderChanged
To create a rule for event of change of any strategy order.
(Defined by StrategyHelper.)
Public Extension MethodWhenOrderRegistered
To create a rule for event of occurrence of new strategy order.
(Defined by StrategyHelper.)
Public Extension MethodWhenPnLChanged
To create a rule for event of profit change.
(Defined by StrategyHelper.)
Public Extension MethodWhenPnLLess
To create a rule for event of profit reduction below the specified level.
(Defined by StrategyHelper.)
Public Extension MethodWhenPnLMore
To create a rule for event of profit increase above the specified level.
(Defined by StrategyHelper.)
Public Extension MethodWhenPositionChanged
To create a rule for the event of strategy position change.
(Defined by StrategyHelper.)
Public Extension MethodWhenPositionLess
To create a rule for event of position event reduction below the specified level.
(Defined by StrategyHelper.)
Public Extension MethodWhenPositionMore
To create a rule for event of position event increase above the specified level.
(Defined by StrategyHelper.)
Public Extension MethodWhenStarted
To create a rule for event of start of strategy operation.
(Defined by StrategyHelper.)
Public Extension MethodWhenStopped
To create a rule for event full stop of strategy operation.
(Defined by StrategyHelper.)
Public Extension MethodWhenStopping
To create a rule for event of beginning of the strategy operation stop.
(Defined by StrategyHelper.)
Public Extension MethodWhenWarning
To create a rule for event of strategy warning (transition of state ErrorState into Warning).
(Defined by StrategyHelper.)
Top
See Also
Inheritance Hierarchy
SystemObject
  Disposable
    StockSharp.LoggingBaseLogSource
      StockSharp.LoggingBaseLogReceiver
        StockSharp.Algo.StrategiesStrategy
          StockSharp.Algo.Strategies.AnalyticsBaseAnalyticsStrategy
          StockSharp.Algo.StrategiesBasketStrategy
          StockSharp.Algo.Strategies.DerivativesHedgeStrategy
          StockSharp.Algo.Strategies.ProtectiveAutoProtectiveStrategy
          StockSharp.Algo.Strategies.ProtectiveTakeProfitStopLossStrategy
          StockSharp.Algo.Strategies.QuotingQuotingStrategy
          StockSharp.Algo.StrategiesTimeFrameStrategy
          StockSharp.Xaml.DiagramDiagramStrategy