Class Strategy
- Namespace
- StockSharp.Algo.Strategies
- Assembly
- StockSharp.Algo.dll
The base class for all trade strategies.
public class Strategy : BaseLogReceiver, IPersistable, INotifyPropertyChangedEx, INotifyPropertyChanged, IMarketRuleContainer, ILogReceiver, ILogSource, IDisposable, ICloneable<Strategy>, ICloneable, IMarketDataProvider, ISubscriptionProvider, ISecurityProvider, ISecurityMessageProvider, ITransactionProvider, IPositionProvider, IPortfolioProvider, IScheduledTask
- Inheritance
-
Strategy
- Implements
-
IPersistableINotifyPropertyChangedExICloneable<Strategy>
- Derived
- Inherited Members
- Extension Methods
Constructors
Strategy()
Initializes a new instance of the Strategy.
public Strategy()
Properties
CancelOrdersWhenStopping
To cancel active orders at stop. Is On by default.
[Browsable(false)]
public bool CancelOrdersWhenStopping { get; set; }
Property Value
ChildStrategies
Subsidiary trade strategies.
[Browsable(false)]
public IStrategyChildStrategyList ChildStrategies { get; }
Property Value
CommentMode
[Display(ResourceType = typeof(LocalizedStrings), Name = "Comment", Description = "OrderComment", GroupName = "General", Order = 10)]
public StrategyCommentModes CommentMode { get; set; }
Property Value
Remarks
By default is Disabled.
CommentOrders
[Browsable(false)]
[Obsolete("Use CommentMode property.")]
public bool CommentOrders { get; set; }
Property Value
Remarks
It is disabled by default.
Commission
Total commission.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Commission", Description = "TotalCommissionDesc", GroupName = "Statistics", Order = 101)]
[Browsable(false)]
public decimal? Commission { get; }
Property Value
Connector
Connection to the trading system.
[Browsable(false)]
public virtual Connector Connector { get; set; }
Property Value
CurrentRegisterCount
Current number of order changes.
[Browsable(false)]
[Obsolete("Use RiskOrderFreqRule rule.")]
public int CurrentRegisterCount { get; }
Property Value
CurrentTime
Current time, which will be passed to the Time.
public override DateTimeOffset CurrentTime { get; }
Property Value
DisposeOnStop
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.
[Browsable(false)]
public bool DisposeOnStop { get; set; }
Property Value
Remarks
The mode is used only for one-time strategies, i.e. for those strategies, which will not be started again (for example, quoting). It is disabled by default.
Environment
Strategy environment parameters.
[Browsable(false)]
public SettingsStorage Environment { get; }
Property Value
- SettingsStorage
ErrorCount
The current number of errors.
[Browsable(false)]
[Obsolete("Use RiskErrorRule rule.")]
public int ErrorCount { get; }
Property Value
ErrorState
The state of an error.
[Browsable(false)]
public LogLevels ErrorState { get; }
Property Value
HistoryCalculated
Calculated from code version of HistorySize.
protected virtual TimeSpan? HistoryCalculated { get; }
Property Value
HistorySize
History to initialize the strategy on Live trading.
[Display(ResourceType = typeof(LocalizedStrings), GroupName = "Settings", Name = "DaysHistory", Description = "DaysHistoryDesc", Order = 20)]
public TimeSpan? HistorySize { get; set; }
Property Value
Id
Strategy ID.
public override Guid Id { get; set; }
Property Value
Indicators
All indicators used in strategy. Uses in default implementation of IsFormed.
[Browsable(false)]
public INotifyList<IIndicator> Indicators { get; }
Property Value
- INotifyList<IIndicator>
IsBacktesting
Determines Connector is HistoryEmulationConnector.
public bool IsBacktesting { get; }
Property Value
IsFormed
Strategy fully formed.
[Browsable(false)]
public virtual bool IsFormed { get; }
Property Value
Remarks
Default implementation used Indicators collection to check all IsFormed are true.
IsOnline
True means that strategy is started and all of its subscriptions are in online state and all child strategies are online.
[Browsable(false)]
public bool IsOnline { get; }
Property Value
IsOnlineStateIncludesChildren
If true, the strategy can only be IsOnline if all of its ChildStrategies are online as well.
[Browsable(false)]
public bool IsOnlineStateIncludesChildren { get; set; }
Property Value
IsRootStrategy
Whether this is a root strategy.
protected bool IsRootStrategy { get; }
Property Value
IsRulesSuspended
Is rules execution suspended.
[Browsable(false)]
public bool IsRulesSuspended { get; }
Property Value
Remarks
Rules suspension is performed through the method SuspendRules().
KeepStatistics
Keep trading statistics (orders, trades, profit etc.) after restart.
[Browsable(false)]
public bool KeepStatistics { get; set; }
Property Value
LastError
The last error that caused the strategy to stop.
[Browsable(false)]
public Exception LastError { get; }
Property Value
Latency
Total latency.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Latency", Description = "TotalLatency", GroupName = "Statistics", Order = 102)]
[Browsable(false)]
public TimeSpan? Latency { get; }
Property Value
LogLevel
The logging level for the source.
[Display(ResourceType = typeof(LocalizedStrings), Name = "LogLevel", Description = "LogLevelDot", GroupName = "Logging")]
public override LogLevels LogLevel { get; set; }
Property Value
MaxErrorCount
The maximal number of errors, which strategy shall receive prior to stop operation.
[Browsable(false)]
[Obsolete("Use RiskErrorRule rule.")]
public int MaxErrorCount { get; set; }
Property Value
Remarks
The default value is 1.
MaxOrderRegisterErrorCount
The maximum number of order registration errors above which the algorithm will be stopped.
[Browsable(false)]
[Obsolete("Use RiskOrderErrorRule rule.")]
public int MaxOrderRegisterErrorCount { get; set; }
Property Value
Remarks
The default value is 10.
MaxRegisterCount
The maximum number of orders above which the algorithm will be stopped.
[Browsable(false)]
[Obsolete("Use RiskOrderFreqRule rule.")]
public int MaxRegisterCount { get; set; }
Property Value
Remarks
The default value is MaxValue.
MyTrades
Trades, matched during the strategy operation.
[Browsable(false)]
public IEnumerable<MyTrade> MyTrades { get; }
Property Value
Name
Strategy name.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Name", Description = "StrategyName", GroupName = "General", Order = 0)]
public override string Name { get; set; }
Property Value
NameGenerator
The generator of strategy name.
[Browsable(false)]
public StrategyNameGenerator NameGenerator { get; }
Property Value
OrderBookSources
All possible IOrderBookMessage sources that can be received via OrderBookDrawing.
public virtual IEnumerable<IOrderBookSource> OrderBookSources { get; }
Property Value
OrderFails
Orders with errors, registered within the strategy.
[Browsable(false)]
[Obsolete("Subscribe on OrderRegisterFailed event.")]
public IEnumerable<OrderFail> OrderFails { get; }
Property Value
OrderRegisterErrorCount
Current number of order registration errors.
[Browsable(false)]
[Obsolete("Use RiskOrderErrorRule rule.")]
public int OrderRegisterErrorCount { get; }
Property Value
Orders
Orders, registered within the strategy framework.
[Browsable(false)]
public IEnumerable<Order> Orders { get; }
Property Value
OrdersKeepTime
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.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Orders", Description = "OrdersKeepTime", GroupName = "General", Order = 9)]
public TimeSpan OrdersKeepTime { get; set; }
Property Value
Parameters
Strategy parameters.
[Browsable(false)]
public StrategyParameterDictionary Parameters { get; }
Property Value
PnL
The aggregate value of profit-loss without accounting commission Commission.
[Display(ResourceType = typeof(LocalizedStrings), Name = "PnL", Description = "TotalPnL", GroupName = "Statistics", Order = 100)]
[Browsable(false)]
public decimal PnL { get; }
Property Value
PnLManager
The profit-loss manager. It accounts trades of this strategy, as well as of its subsidiary strategies ChildStrategies.
[Browsable(false)]
public IPnLManager PnLManager { get; set; }
Property Value
Portfolio
Portfolio.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Portfolio", Description = "StrategyPortfolio", GroupName = "General", Order = 1)]
public virtual Portfolio Portfolio { get; set; }
Property Value
PortfolioProvider
[Browsable(false)]
public IPortfolioProvider PortfolioProvider { get; set; }
Property Value
Position
The position aggregate value.
[Browsable(false)]
public decimal Position { get; set; }
Property Value
Positions
Get all positions.
[Browsable(false)]
public IEnumerable<Position> Positions { get; }
Property Value
ProcessState
The operation state.
[Browsable(false)]
public virtual ProcessStates ProcessState { get; }
Property Value
RegisterInterval
The order registration interval above which the new order would not be registered.
[Browsable(false)]
[Obsolete("Use RiskOrderFreqRule rule.")]
public TimeSpan RegisterInterval { get; set; }
Property Value
Remarks
By default, the interval is disabled and it is equal to Zero.
RestoreChildOrders
Restore orders last time was registered by child strategies.
[Browsable(false)]
public bool RestoreChildOrders { get; set; }
Property Value
RiskManager
The risks control manager.
[Browsable(false)]
public IRiskManager RiskManager { get; set; }
Property Value
RiskRules
The risk rules.
[Display(ResourceType = typeof(LocalizedStrings), GroupName = "Settings", Name = "Risks", Description = "RiskSettings", Order = 300)]
public IEnumerable<IRiskRule> RiskRules { get; set; }
Property Value
RootStrategy
Root strategy.
protected Strategy RootStrategy { get; }
Property Value
Rules
Registered rules.
[Browsable(false)]
public IMarketRuleList Rules { get; }
Property Value
Security
Security.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Security", Description = "StrategySecurity", GroupName = "General", Order = 2)]
public virtual Security Security { get; set; }
Property Value
Slippage
Total slippage.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Slippage", Description = "TotalSlippage", GroupName = "Statistics", Order = 99)]
[Browsable(false)]
public decimal? Slippage { get; }
Property Value
StartedTime
Strategy start time.
[Display(ResourceType = typeof(LocalizedStrings), Name = "StartTime", Description = "StrategyStartTime", GroupName = "Statistics", Order = 105)]
[Browsable(false)]
public DateTimeOffset StartedTime { get; }
Property Value
StatisticManager
The statistics manager.
[Browsable(false)]
public IStatisticManager StatisticManager { get; protected set; }
Property Value
StopOnChildStrategyErrors
Stop strategy when child strategies causes errors.
[Browsable(false)]
public bool StopOnChildStrategyErrors { get; set; }
Property Value
Remarks
It is disabled by default.
StopOrders
Stop-orders, registered within the strategy framework.
[Browsable(false)]
[Obsolete("Use Orders property.")]
public IEnumerable<Order> StopOrders { get; }
Property Value
TotalWorkingTime
The total time of strategy operation less time periods, when strategy was stopped.
[Browsable(false)]
public TimeSpan TotalWorkingTime { get; }
Property Value
TradingMode
Allow trading.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Trading", Description = "AllowTrading", GroupName = "General", Order = 10)]
public StrategyTradingModes TradingMode { get; set; }
Property Value
UnrealizedPnLInterval
The interval for unrealized profit recalculation. The default value is 1 minute.
[Browsable(false)]
public TimeSpan UnrealizedPnLInterval { get; set; }
Property Value
UnsubscribeOnStop
Unsubscribe all active subscription while strategy become stopping.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Unsubscribe", Description = "UnsubscribeOnStop", GroupName = "General", Order = 11)]
public bool UnsubscribeOnStop { get; set; }
Property Value
Volume
Operational volume.
[Display(ResourceType = typeof(LocalizedStrings), Name = "Volume", Description = "StrategyVolume", GroupName = "General", Order = 4)]
public virtual decimal Volume { get; set; }
Property Value
WaitAllTrades
Stop strategy only after getting all trades by registered orders.
[Browsable(false)]
public bool WaitAllTrades { get; set; }
Property Value
Remarks
It is disabled by default.
WaitRulesOnStop
[Browsable(false)]
public bool WaitRulesOnStop { get; set; }
Property Value
WorkingTime
Working schedule.
[Display(ResourceType = typeof(LocalizedStrings), Name = "WorkingTime", Description = "WorkingHours", GroupName = "General", Order = 15)]
public WorkingTime WorkingTime { get; set; }
Property Value
Methods
ApplyCommand(CommandMessage)
Apply incoming command.
public virtual void ApplyCommand(CommandMessage cmdMsg)
Parameters
cmdMsg
CommandMessageThe message contains information about command to change state.
AttachOrder(Order, IEnumerable<MyTrade>)
To add the active order to the strategy and process trades by the order.
[Obsolete("CanAttach method must be overrided.")]
public virtual void AttachOrder(Order order, IEnumerable<MyTrade> myTrades)
Parameters
order
OrderOrder.
myTrades
IEnumerable<MyTrade>Trades for order.
Remarks
It is used to restore a state of the strategy, when it is necessary to subscribe for getting data on orders, registered earlier.
BuyLimit(decimal, decimal?)
To create the initialized order object for buy.
public Order BuyLimit(decimal price, decimal? volume = null)
Parameters
price
decimalPrice.
volume
decimal?The volume. If null value is passed, then Volume value is used.
Returns
- Order
The initialized order object.
Remarks
The order is not registered, only the object is created.
BuyMarket(decimal?)
To create initialized object of buy order at market price.
public Order BuyMarket(decimal? volume = null)
Parameters
Returns
- Order
The initialized order object.
Remarks
The order is not registered, only the object is created.
CanAttach(Order)
Determines the specified order can be owned by the strategy.
protected virtual bool CanAttach(Order order)
Parameters
order
OrderOrder.
Returns
- bool
Check result.
CanTrade(DateTimeOffset, bool, out string)
Check if can trade.
protected virtual bool CanTrade(DateTimeOffset time, bool reducePosition, out string noTradeReason)
Parameters
time
DateTimeOffsetreducePosition
boolnoTradeReason
string
Returns
CancelActiveOrders()
To cancel all active orders (to stop and regular).
public void CancelActiveOrders()
CancelOrder(Order)
Cancel the order.
public void CancelOrder(Order order)
Parameters
order
OrderThe order which should be canceled.
Clone()
Create a copy of Strategy.
public virtual Strategy Clone()
Returns
- Strategy
Copy.
ClosePosition(Security, Portfolio)
To close open position by market (to register the order of the type Market).
public Order ClosePosition(Security security = null, Portfolio portfolio = null)
Parameters
security
SecuritySecurity. If not passed the value from Security will be obtain.
portfolio
PortfolioPortfolio. If not passed the value from Portfolio will be obtain.
Returns
- Order
The initialized order object.
Remarks
The market order is not operable on all exchanges.
CreateChartArea()
Create chart area.
protected IChartArea CreateChartArea()
Returns
DisposeManaged()
Release resources.
protected override void DisposeManaged()
DrawCandles(IChartArea, Subscription)
Draw candles on chart.
protected IChartCandleElement DrawCandles(IChartArea area, Subscription subscription)
Parameters
area
IChartAreasubscription
Subscription
Returns
DrawCandles<T>(IChartArea, SubscriptionHandler<T>)
Draw candles on chart.
protected IChartCandleElement DrawCandles<T>(IChartArea area, Strategy.SubscriptionHandler<T> subscription)
Parameters
area
IChartAreasubscription
Strategy.SubscriptionHandler<T>
Returns
Type Parameters
T
DrawIndicator(IChartArea, IIndicator, Color?, Color?)
Draw indicator on chart.
protected IChartIndicatorElement DrawIndicator(IChartArea area, IIndicator indicator, Color? color = null, Color? additionalColor = null)
Parameters
area
IChartAreaindicator
IIndicatorcolor
Color?additionalColor
Color?
Returns
DrawOrderBook(Subscription, IOrderBookSource, IOrderBookMessage)
Draw IOrderBookMessage.
public void DrawOrderBook(Subscription subscription, IOrderBookSource source, IOrderBookMessage book)
Parameters
subscription
Subscriptionsource
IOrderBookSourcebook
IOrderBookMessage
DrawOrderBookOrder(Subscription, IOrderBookSource, Order)
Draw order book order.
public void DrawOrderBookOrder(Subscription subscription, IOrderBookSource source, Order order)
Parameters
subscription
Subscriptionsource
IOrderBookSourceorder
OrderOrder.
DrawOrderBookOrderFail(Subscription, IOrderBookSource, OrderFail)
Draw order book order fail.
public void DrawOrderBookOrderFail(Subscription subscription, IOrderBookSource source, OrderFail fail)
Parameters
subscription
Subscriptionsource
IOrderBookSourcefail
OrderFailOrder fail.
DrawOrders(IChartArea)
Draw orders on chart.
protected IChartOrderElement DrawOrders(IChartArea area)
Parameters
area
IChartArea
Returns
DrawOwnTrades(IChartArea)
Draw trades on chart.
protected IChartTradeElement DrawOwnTrades(IChartArea area)
Parameters
area
IChartArea
Returns
EditOrder(Order, Order)
Edit the order.
public void EditOrder(Order order, Order changes)
Parameters
GetLevel1Fields(Security)
To get a set of available fields Level1Fields, for which there is a market data for the instrument.
public IEnumerable<Level1Fields> GetLevel1Fields(Security security)
Parameters
security
SecuritySecurity.
Returns
- IEnumerable<Level1Fields>
Possible fields.
GetPositionValue(Security, Portfolio)
Get position.
public decimal? GetPositionValue(Security security, Portfolio portfolio)
Parameters
Returns
- decimal?
Position.
GetSecurityValue(Security, Level1Fields)
To get the value of market data for the instrument.
public object GetSecurityValue(Security security, Level1Fields field)
Parameters
security
SecuritySecurity.
field
Level1FieldsMarket-data field.
Returns
GetWorkingPortfolios()
Get all portfolios required for strategy.
public virtual IEnumerable<Portfolio> GetWorkingPortfolios()
Returns
- IEnumerable<Portfolio>
Portfolios.
GetWorkingSecurities()
Get all securities required for strategy.
public virtual IEnumerable<Security> GetWorkingSecurities()
Returns
- IEnumerable<Security>
Securities.
InitStartValues()
Init.
protected void InitStartValues()
IsOrderEditable(Order)
Determines the specified order can be edited by EditOrder(Order, Order).
public bool? IsOrderEditable(Order order)
Parameters
order
OrderOrder.
Returns
IsOrderReplaceable(Order)
Determines the specified order can be replaced by ReRegisterOrder(Order, Order).
public bool? IsOrderReplaceable(Order order)
Parameters
order
OrderOrder.
Returns
Load(SettingsStorage)
Load settings.
public override void Load(SettingsStorage storage)
Parameters
storage
SettingsStorageSettings storage.
Lookup(SecurityLookupMessage)
Lookup securities by criteria criteria
.
public IEnumerable<Security> Lookup(SecurityLookupMessage criteria)
Parameters
criteria
SecurityLookupMessageMessage security lookup for specified criteria.
Returns
- IEnumerable<Security>
Found instruments.
LookupById(SecurityId)
To get the instrument by the identifier.
public Security LookupById(SecurityId id)
Parameters
id
SecurityIdSecurity ID.
Returns
OnError(Strategy, Exception)
Processing of error, occurred as result of strategy operation.
protected virtual void OnError(Strategy strategy, Exception error)
Parameters
OnNewMyTrade(MyTrade)
The method, called at occurrence of new strategy trade.
protected virtual void OnNewMyTrade(MyTrade trade)
Parameters
trade
MyTradeNew trade of a strategy.
OnOrderCanceling(Order)
To call the event OrderCanceling.
protected virtual void OnOrderCanceling(Order order)
Parameters
order
OrderOrder.
OnOrderChanged(Order)
The method, called at strategy order change.
protected virtual void OnOrderChanged(Order order)
Parameters
order
OrderThe changed order.
OnOrderReRegistering(Order, Order)
To call the event OrderReRegistering.
protected virtual void OnOrderReRegistering(Order oldOrder, Order newOrder)
Parameters
OnOrderRegisterFailed(OrderFail, bool)
The method, called at strategy order registration error.
protected virtual void OnOrderRegisterFailed(OrderFail fail, bool calcRisk)
Parameters
OnOrderRegistered(Order)
To call the event OrderRegistered.
protected virtual void OnOrderRegistered(Order order)
Parameters
order
OrderOrder.
OnOrderRegistering(Order)
To call the event OrderRegistering.
protected virtual void OnOrderRegistering(Order order)
Parameters
order
OrderOrder.
OnReseted()
It is called from the Reset() method.
protected virtual void OnReseted()
OnStarted()
The method is called when the Start() method has been called and the ProcessState state has been taken the Started value.
[Obsolete("Use overload with time param.")]
protected virtual void OnStarted()
OnStarted(DateTimeOffset)
The method is called when the Start() method has been called and the ProcessState state has been taken the Started value.
protected virtual void OnStarted(DateTimeOffset time)
Parameters
time
DateTimeOffset
OnStopped()
The method is called when the ProcessState process state has been taken the Stopped value.
protected virtual void OnStopped()
OnStopping()
The method is called when the ProcessState process state has been taken the Stopping value.
protected virtual void OnStopping()
ProcessCancelActiveOrders()
To cancel all active orders (to stop and regular).
protected virtual void ProcessCancelActiveOrders()
ProcessNewOrders(IEnumerable<Order>)
To process orders, received for the connection Connector, and find among them those, belonging to the strategy.
protected virtual IEnumerable<Order> ProcessNewOrders(IEnumerable<Order> newOrders)
Parameters
newOrders
IEnumerable<Order>New orders.
Returns
- IEnumerable<Order>
Orders, belonging to the strategy.
RaiseLog(LogMessage)
To call the event Log.
protected override void RaiseLog(LogMessage message)
Parameters
message
LogMessageA debug message.
RaiseParametersChanged(string)
To call events ParametersChanged and PropertyChanged.
public void RaiseParametersChanged(string name = null)
Parameters
name
stringParameter name.
RaiseProcessStateChanged(Strategy)
To call the event ProcessStateChanged.
protected void RaiseProcessStateChanged(Strategy strategy)
Parameters
strategy
StrategyStrategy.
ReRegisterOrder(Order, Order)
Reregister the order.
public void ReRegisterOrder(Order oldOrder, Order newOrder)
Parameters
RegisterOrder(Order)
Register new order.
public void RegisterOrder(Order order)
Parameters
order
OrderRegistration details.
Reset()
To re-initialize the trade algorithm. It is called after initialization of the strategy object and loading stored parameters.
public void Reset()
SafeGetConnector()
To get the strategy getting Connector. If it is not initialized, the exception will be discarded.
public IConnector SafeGetConnector()
Returns
- IConnector
Connector.
Save(SettingsStorage)
Save settings.
public override void Save(SettingsStorage storage)
Parameters
storage
SettingsStorageSettings storage.
Save(SettingsStorage, bool, bool, bool, bool)
Save settings.
public void Save(SettingsStorage storage, bool saveStatistics, bool saveSystemParameters, bool saveSecurity, bool savePortfolio)
Parameters
storage
SettingsStorageEcng.Serialization.SettingsStorage
saveStatistics
boolsaveSystemParameters
boolSave system parameters.
saveSecurity
boolSave Security.
savePortfolio
boolSave Portfolio.
SellLimit(decimal, decimal?)
To create the initialized order object for sell.
public Order SellLimit(decimal price, decimal? volume = null)
Parameters
price
decimalPrice.
volume
decimal?The volume. If null value is passed, then Volume value is used.
Returns
- Order
The initialized order object.
Remarks
The order is not registered, only the object is created.
SellMarket(decimal?)
To create the initialized order object of sell order at market price.
public Order SellMarket(decimal? volume = null)
Parameters
Returns
- Order
The initialized order object.
Remarks
The order is not registered, only the object is created.
SetPositionValue(Security, Portfolio, decimal)
Set position.
public void SetPositionValue(Security security, Portfolio portfolio, decimal value)
Parameters
Start()
To start the trade algorithm.
public virtual void Start()
StartProtection(Unit, Unit, bool, TimeSpan, TimeSpan, bool)
Start position protection.
protected void StartProtection(Unit takeProfit, Unit stopLoss, bool isStopTrailing = false, TimeSpan takeTimeout = default, TimeSpan stopTimeout = default, bool useMarketOrders = false)
Parameters
takeProfit
UnitTake offset.
stopLoss
UnitStop offset.
isStopTrailing
boolWhether to use a trailing technique.
takeTimeout
TimeSpanTime limit. If protection has not worked by this time, the position will be closed on the market.
stopTimeout
TimeSpanTime limit. If protection has not worked by this time, the position will be closed on the market.
useMarketOrders
boolWhether to use market orders.
Stop()
To stop the trade algorithm.
public virtual void Stop()
Stop(Exception)
To stop the trade algorithm by error reason.
public void Stop(Exception error)
Parameters
error
ExceptionError.
Subscribe(Subscription)
Subscribe.
public void Subscribe(Subscription subscription)
Parameters
subscription
SubscriptionSubscription.
SubscribeCandles(Subscription)
Subscribe to candles.
protected Strategy.SubscriptionHandler<ICandleMessage> SubscribeCandles(Subscription subscription)
Parameters
subscription
Subscription
Returns
SubscribeCandles(DataType, bool, Security)
Subscribe to candles.
protected Strategy.SubscriptionHandler<ICandleMessage> SubscribeCandles(DataType dt, bool isFinishedOnly = true, Security security = null)
Parameters
dt
DataTypeisFinishedOnly
boolsecurity
SecuritySecurity. If security is not passed, then Security value is used.
Returns
SubscribeCandles(TimeSpan, bool, Security)
Subscribe to candles.
protected Strategy.SubscriptionHandler<ICandleMessage> SubscribeCandles(TimeSpan tf, bool isFinishedOnly = true, Security security = null)
Parameters
tf
TimeSpanTime-frame.
isFinishedOnly
boolsecurity
SecuritySecurity. If security is not passed, then Security value is used.
Returns
SubscribeLevel1(Security)
Subscribe to Level1.
protected Strategy.SubscriptionHandler<Level1ChangeMessage> SubscribeLevel1(Security security = null)
Parameters
Returns
SubscribeLevel1(Subscription)
Subscribe to Level1.
protected Strategy.SubscriptionHandler<Level1ChangeMessage> SubscribeLevel1(Subscription subscription)
Parameters
subscription
Subscription
Returns
SubscribeOrderBook(Security)
Subscribe to MarketDepth.
protected Strategy.SubscriptionHandler<IOrderBookMessage> SubscribeOrderBook(Security security = null)
Parameters
Returns
SubscribeOrderBook(Subscription)
Subscribe to MarketDepth.
protected Strategy.SubscriptionHandler<IOrderBookMessage> SubscribeOrderBook(Subscription subscription)
Parameters
subscription
Subscription
Returns
SubscribeTicks(Security)
Subscribe to Ticks.
protected Strategy.SubscriptionHandler<ITickTradeMessage> SubscribeTicks(Security security = null)
Parameters
Returns
SubscribeTicks(Subscription)
Subscribe to Ticks.
protected Strategy.SubscriptionHandler<ITickTradeMessage> SubscribeTicks(Subscription subscription)
Parameters
subscription
Subscription
Returns
TryAddMyTrade(MyTrade)
Try add own trade.
public bool TryAddMyTrade(MyTrade trade)
Parameters
Returns
- bool
Operation result.
UnSubscribe(Subscription)
Unsubscribe.
public void UnSubscribe(Subscription subscription)
Parameters
subscription
SubscriptionSubscription.
Events
BoardReceived
Board received.
public event Action<Subscription, ExchangeBoard> BoardReceived
Event Type
CandleReceived
Candle received.
public event Action<Subscription, ICandleMessage> CandleReceived
Event Type
CommissionChanged
Commission change event.
public event Action CommissionChanged
Event Type
ConnectorChanged
The event of strategy connection change.
public event Action ConnectorChanged
Event Type
Error
The event of error occurrence in the strategy.
public event Action<Strategy, Exception> Error
Event Type
IsOnlineChanged
The event of strategy online state change.
public event Action<Strategy> IsOnlineChanged
Event Type
LatencyChanged
Latency change event.
public event Action LatencyChanged
Event Type
Level1Received
Level1 received.
public event Action<Subscription, Level1ChangeMessage> Level1Received
Event Type
LookupBoardsResult
Lookup result BoardLookupMessage received.
public event Action<BoardLookupMessage, IEnumerable<ExchangeBoard>, Exception> LookupBoardsResult
Event Type
LookupBoardsResult2
Lookup result BoardLookupMessage received.
public event Action<BoardLookupMessage, IEnumerable<ExchangeBoard>, IEnumerable<ExchangeBoard>, Exception> LookupBoardsResult2
Event Type
LookupSecuritiesResult
Lookup result SecurityLookupMessage received.
public event Action<SecurityLookupMessage, IEnumerable<Security>, Exception> LookupSecuritiesResult
Event Type
LookupSecuritiesResult2
Lookup result SecurityLookupMessage received.
public event Action<SecurityLookupMessage, IEnumerable<Security>, IEnumerable<Security>, Exception> LookupSecuritiesResult2
Event Type
LookupTimeFramesResult
Lookup result TimeFrameLookupMessage received.
public event Action<TimeFrameLookupMessage, IEnumerable<TimeSpan>, Exception> LookupTimeFramesResult
Event Type
LookupTimeFramesResult2
Lookup result TimeFrameLookupMessage received.
public event Action<TimeFrameLookupMessage, IEnumerable<TimeSpan>, IEnumerable<TimeSpan>, Exception> LookupTimeFramesResult2
Event Type
MarketDataSubscriptionFailed
Error subscription market-data.
[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, Exception> MarketDataSubscriptionFailed
Event Type
MarketDataSubscriptionFailed2
Error subscription market-data.
[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, SubscriptionResponseMessage> MarketDataSubscriptionFailed2
Event Type
MarketDataSubscriptionFinished
Subscription market-data finished.
[Obsolete("Use SubscriptionStopped event.")]
public event Action<Security, SubscriptionFinishedMessage> MarketDataSubscriptionFinished
Event Type
MarketDataSubscriptionOnline
Subscription is online.
[Obsolete("Use SubscriptionOnline event.")]
public event Action<Security, MarketDataMessage> MarketDataSubscriptionOnline
Event Type
MarketDataSubscriptionSucceeded
Successful subscription market-data.
[Obsolete("Use SubscriptionStarted event.")]
public event Action<Security, MarketDataMessage> MarketDataSubscriptionSucceeded
Event Type
MarketDataUnSubscriptionFailed
Error unsubscription market-data.
[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, Exception> MarketDataUnSubscriptionFailed
Event Type
MarketDataUnSubscriptionFailed2
Error unsubscription market-data.
[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, SubscriptionResponseMessage> MarketDataUnSubscriptionFailed2
Event Type
MarketDataUnSubscriptionSucceeded
Successful unsubscription market-data.
[Obsolete("Use SubscriptionStopped event.")]
public event Action<Security, MarketDataMessage> MarketDataUnSubscriptionSucceeded
Event Type
MarketDataUnexpectedCancelled
Market-data subscription unexpected cancelled.
[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, Exception> MarketDataUnexpectedCancelled
Event Type
MarketDepthChanged
Order book changed.
[Obsolete("Use OrderBookReceived event.")]
public event Action<MarketDepth> MarketDepthChanged
Event Type
MarketDepthReceived
Order book received.
[Obsolete("Use OrderBookReceived event.")]
public event Action<Subscription, MarketDepth> MarketDepthReceived
Event Type
NewMarketDepth
Order book received.
[Obsolete("Use OrderBookReceived event.")]
public event Action<MarketDepth> NewMarketDepth
Event Type
NewMyTrade
Own trade received.
public event Action<MyTrade> NewMyTrade
Event Type
NewNews
News received.
[Obsolete("Use NewsReceived event.")]
public event Action<News> NewNews
Event Type
NewOrderLogItem
Order log received.
[Obsolete("Use OrderLogItemReceived event.")]
public event Action<OrderLogItem> NewOrderLogItem
Event Type
NewSecurity
Security received.
[Obsolete("Use SecurityReceived event.")]
public event Action<Security> NewSecurity
Event Type
NewTrade
Tick trade received.
[Obsolete("Use TickTradeReceived event.")]
public event Action<Trade> NewTrade
Event Type
NewsChanged
News updated (news body received Story).
[Obsolete("Use NewsReceived event.")]
public event Action<News> NewsChanged
Event Type
NewsReceived
News received.
public event Action<Subscription, News> NewsReceived
Event Type
OrderBookDrawing
public event Action<Subscription, IOrderBookSource, IOrderBookMessage> OrderBookDrawing
Event Type
OrderBookDrawingOrder
public event Action<Subscription, IOrderBookSource, Order> OrderBookDrawingOrder
Event Type
OrderBookDrawingOrderFail
public event Action<Subscription, IOrderBookSource, OrderFail> OrderBookDrawingOrderFail
Event Type
OrderBookReceived
Order book received.
public event Action<Subscription, IOrderBookMessage> OrderBookReceived
Event Type
OrderCancelFailReceived
Order cancellation error event.
public event Action<Subscription, OrderFail> OrderCancelFailReceived
Event Type
OrderCancelFailed
Order cancellation error event.
public event Action<OrderFail> OrderCancelFailed
Event Type
OrderCanceling
The event of sending order for cancelling.
public event Action<Order> OrderCanceling
Event Type
OrderChanged
Order changed (cancelled, matched).
public event Action<Order> OrderChanged
Event Type
OrderEditFailReceived
Order edition error event.
public event Action<Subscription, OrderFail> OrderEditFailReceived
Event Type
OrderEditFailed
EditOrder(Order, Order) error result event.
public event Action<long, OrderFail> OrderEditFailed
Event Type
OrderEdited
EditOrder(Order, Order) success result event.
public event Action<long, Order> OrderEdited
Event Type
OrderLogItemReceived
Order log received.
[Obsolete("Use OrderLogReceived event.")]
public event Action<Subscription, OrderLogItem> OrderLogItemReceived
Event Type
OrderLogReceived
Tick trade received.
public event Action<Subscription, IOrderLogMessage> OrderLogReceived
Event Type
OrderReRegistering
The event of sending order for re-registration.
public event Action<Order, Order> OrderReRegistering
Event Type
OrderReceived
Order received.
public event Action<Subscription, Order> OrderReceived
Event Type
OrderRegisterFailReceived
Order registration error event.
public event Action<Subscription, OrderFail> OrderRegisterFailReceived
Event Type
OrderRegisterFailed
Order registration error event.
public event Action<OrderFail> OrderRegisterFailed
Event Type
OrderRegistered
The event of order successful registration.
public event Action<Order> OrderRegistered
Event Type
OrderRegistering
The event of sending order for registration.
public event Action<Order> OrderRegistering
Event Type
OwnTradeReceived
Own trade received.
public event Action<Subscription, MyTrade> OwnTradeReceived
Event Type
ParametersChanged
Parameters change event.
public event Action ParametersChanged
Event Type
PnLChanged
PnL change event.
public event Action PnLChanged
Event Type
PnLReceived
PnL change event.
[Obsolete("Use PnLReceived2 event.")]
public event Action<Subscription> PnLReceived
Event Type
PnLReceived2
PnL change event.
public event Action<Subscription, Portfolio, DateTimeOffset, decimal, decimal?, decimal?> PnLReceived2
Event Type
PortfolioReceived
Portfolio received.
public event Action<Subscription, Portfolio> PortfolioReceived
Event Type
PositionChanged
Position change event.
public event Action PositionChanged
Event Type
PositionReceived
Position received.
public event Action<Subscription, Position> PositionReceived
Event Type
ProcessStateChanged
ProcessState change event.
public event Action<Strategy> ProcessStateChanged
Event Type
PropertyChanged
public event PropertyChangedEventHandler PropertyChanged
Event Type
Reseted
The event of the strategy re-initialization.
public event Action Reseted
Event Type
SecurityChanged
Security changed.
[Obsolete("Use SecurityReceived event.")]
public event Action<Security> SecurityChanged
Event Type
SecurityReceived
Security received.
public event Action<Subscription, Security> SecurityReceived
Event Type
SlippageChanged
Slippage change event.
public event Action SlippageChanged
Event Type
StopOrderCancelFailed
Stop-order cancellation error event.
[Obsolete("Use OrderCancelFailed event.")]
public event Action<OrderFail> StopOrderCancelFailed
Event Type
StopOrderCanceling
The event of sending stop-order for cancelling.
[Obsolete("Use OrderCanceling event.")]
public event Action<Order> StopOrderCanceling
Event Type
StopOrderChanged
Stop order state change event.
[Obsolete("Use OrderChanged event.")]
public event Action<Order> StopOrderChanged
Event Type
StopOrderReRegistering
The event of sending stop-order for re-registration.
[Obsolete("Use OrderReRegistering event.")]
public event Action<Order, Order> StopOrderReRegistering
Event Type
StopOrderRegisterFailed
Stop-order registration error event.
[Obsolete("Use OrderRegisterFailed event.")]
public event Action<OrderFail> StopOrderRegisterFailed
Event Type
StopOrderRegistered
The event of stop-order successful registration.
[Obsolete("Use OrderRegistered event.")]
public event Action<Order> StopOrderRegistered
Event Type
StopOrderRegistering
The event of sending stop-order for registration.
[Obsolete("Use OrderRegistering event.")]
public event Action<Order> StopOrderRegistering
Event Type
SubscriptionFailed
Subscription is failed.
public event Action<Subscription, Exception, bool> SubscriptionFailed
Event Type
SubscriptionOnline
Subscription is online.
public event Action<Subscription> SubscriptionOnline
Event Type
SubscriptionReceived
Message received.
public event Action<Subscription, object> SubscriptionReceived
Event Type
SubscriptionStarted
Subscription is started.
public event Action<Subscription> SubscriptionStarted
Event Type
SubscriptionStopped
Subscription is stopped.
public event Action<Subscription, Exception> SubscriptionStopped
Event Type
TickTradeReceived
Tick trade received.
public event Action<Subscription, ITickTradeMessage> TickTradeReceived
Event Type
ValuesChanged
Security changed.
public event Action<Security, IEnumerable<KeyValuePair<Level1Fields, object>>, DateTimeOffset, DateTimeOffset> ValuesChanged