Table of Contents

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
IPersistable
INotifyPropertyChangedEx
ICloneable<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

bool

ChildStrategies

Subsidiary trade strategies.

[Browsable(false)]
public IStrategyChildStrategyList ChildStrategies { get; }

Property Value

IStrategyChildStrategyList

CommentMode

Set Comment by Name or Id.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Comment", Description = "OrderComment", GroupName = "General", Order = 10)]
public StrategyCommentModes CommentMode { get; set; }

Property Value

StrategyCommentModes

Remarks

By default is Disabled.

CommentOrders

To add to Comment the name of the strategy Name, registering the order.

[Browsable(false)]
[Obsolete("Use CommentMode property.")]
public bool CommentOrders { get; set; }

Property Value

bool

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

decimal?

Connector

Connection to the trading system.

[Browsable(false)]
public virtual Connector Connector { get; set; }

Property Value

Connector

CurrentRegisterCount

Current number of order changes.

[Browsable(false)]
[Obsolete("Use RiskOrderFreqRule rule.")]
public int CurrentRegisterCount { get; }

Property Value

int

CurrentTime

Current time, which will be passed to the Time.

public override DateTimeOffset CurrentTime { get; }

Property Value

DateTimeOffset

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

bool

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

int

ErrorState

The state of an error.

[Browsable(false)]
public LogLevels ErrorState { get; }

Property Value

LogLevels

HistoryCalculated

Calculated from code version of HistorySize.

protected virtual TimeSpan? HistoryCalculated { get; }

Property Value

TimeSpan?

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

TimeSpan?

Id

Strategy ID.

public override Guid Id { get; set; }

Property Value

Guid

Indicators

All indicators used in strategy. Uses in default implementation of IsFormed.

[Browsable(false)]
public INotifyList<IIndicator> Indicators { get; }

Property Value

INotifyList<IIndicator>

IsBacktesting

public bool IsBacktesting { get; }

Property Value

bool

IsFormed

Strategy fully formed.

[Browsable(false)]
public virtual bool IsFormed { get; }

Property Value

bool

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

bool

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

bool

IsRootStrategy

Whether this is a root strategy.

protected bool IsRootStrategy { get; }

Property Value

bool

IsRulesSuspended

Is rules execution suspended.

[Browsable(false)]
public bool IsRulesSuspended { get; }

Property Value

bool

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

bool

LastError

The last error that caused the strategy to stop.

[Browsable(false)]
public Exception LastError { get; }

Property Value

Exception

Latency

Total latency.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Latency", Description = "TotalLatency", GroupName = "Statistics", Order = 102)]
[Browsable(false)]
public TimeSpan? Latency { get; }

Property Value

TimeSpan?

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

LogLevels

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

int

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

int

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

int

Remarks

The default value is MaxValue.

MyTrades

Trades, matched during the strategy operation.

[Browsable(false)]
public IEnumerable<MyTrade> MyTrades { get; }

Property Value

IEnumerable<MyTrade>

Name

Strategy name.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Name", Description = "StrategyName", GroupName = "General", Order = 0)]
public override string Name { get; set; }

Property Value

string

NameGenerator

The generator of strategy name.

[Browsable(false)]
public StrategyNameGenerator NameGenerator { get; }

Property Value

StrategyNameGenerator

OrderBookSources

All possible IOrderBookMessage sources that can be received via OrderBookDrawing.

public virtual IEnumerable<IOrderBookSource> OrderBookSources { get; }

Property Value

IEnumerable<IOrderBookSource>

OrderFails

Orders with errors, registered within the strategy.

[Browsable(false)]
[Obsolete("Subscribe on OrderRegisterFailed event.")]
public IEnumerable<OrderFail> OrderFails { get; }

Property Value

IEnumerable<OrderFail>

OrderRegisterErrorCount

Current number of order registration errors.

[Browsable(false)]
[Obsolete("Use RiskOrderErrorRule rule.")]
public int OrderRegisterErrorCount { get; }

Property Value

int

Orders

Orders, registered within the strategy framework.

[Browsable(false)]
public IEnumerable<Order> Orders { get; }

Property Value

IEnumerable<Order>

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

TimeSpan

Parameters

Strategy parameters.

[Browsable(false)]
public StrategyParameterDictionary Parameters { get; }

Property Value

StrategyParameterDictionary

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

decimal

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

IPnLManager

Portfolio

Portfolio.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Portfolio", Description = "StrategyPortfolio", GroupName = "General", Order = 1)]
public virtual Portfolio Portfolio { get; set; }

Property Value

Portfolio

PortfolioProvider

[Browsable(false)]
public IPortfolioProvider PortfolioProvider { get; set; }

Property Value

IPortfolioProvider

Position

The position aggregate value.

[Browsable(false)]
public decimal Position { get; set; }

Property Value

decimal

Positions

Get all positions.

[Browsable(false)]
public IEnumerable<Position> Positions { get; }

Property Value

IEnumerable<Position>

ProcessState

The operation state.

[Browsable(false)]
public virtual ProcessStates ProcessState { get; }

Property Value

ProcessStates

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

TimeSpan

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

bool

RiskManager

The risks control manager.

[Browsable(false)]
public IRiskManager RiskManager { get; set; }

Property Value

IRiskManager

RiskRules

The risk rules.

[Display(ResourceType = typeof(LocalizedStrings), GroupName = "Settings", Name = "Risks", Description = "RiskSettings", Order = 300)]
public IEnumerable<IRiskRule> RiskRules { get; set; }

Property Value

IEnumerable<IRiskRule>

RootStrategy

Root strategy.

protected Strategy RootStrategy { get; }

Property Value

Strategy

Rules

Registered rules.

[Browsable(false)]
public IMarketRuleList Rules { get; }

Property Value

IMarketRuleList

Security

Security.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Security", Description = "StrategySecurity", GroupName = "General", Order = 2)]
public virtual Security Security { get; set; }

Property Value

Security

Slippage

Total slippage.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Slippage", Description = "TotalSlippage", GroupName = "Statistics", Order = 99)]
[Browsable(false)]
public decimal? Slippage { get; }

Property Value

decimal?

StartedTime

Strategy start time.

[Display(ResourceType = typeof(LocalizedStrings), Name = "StartTime", Description = "StrategyStartTime", GroupName = "Statistics", Order = 105)]
[Browsable(false)]
public DateTimeOffset StartedTime { get; }

Property Value

DateTimeOffset

StatisticManager

The statistics manager.

[Browsable(false)]
public IStatisticManager StatisticManager { get; protected set; }

Property Value

IStatisticManager

StopOnChildStrategyErrors

Stop strategy when child strategies causes errors.

[Browsable(false)]
public bool StopOnChildStrategyErrors { get; set; }

Property Value

bool

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

IEnumerable<Order>

TotalWorkingTime

The total time of strategy operation less time periods, when strategy was stopped.

[Browsable(false)]
public TimeSpan TotalWorkingTime { get; }

Property Value

TimeSpan

TradingMode

Allow trading.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Trading", Description = "AllowTrading", GroupName = "General", Order = 10)]
public StrategyTradingModes TradingMode { get; set; }

Property Value

StrategyTradingModes

UnrealizedPnLInterval

The interval for unrealized profit recalculation. The default value is 1 minute.

[Browsable(false)]
public TimeSpan UnrealizedPnLInterval { get; set; }

Property Value

TimeSpan

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

bool

Volume

Operational volume.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Volume", Description = "StrategyVolume", GroupName = "General", Order = 4)]
public virtual decimal Volume { get; set; }

Property Value

decimal

WaitAllTrades

Stop strategy only after getting all trades by registered orders.

[Browsable(false)]
public bool WaitAllTrades { get; set; }

Property Value

bool

Remarks

It is disabled by default.

WaitRulesOnStop

Wait Rules to finish before strategy become into Stopped state.

[Browsable(false)]
public bool WaitRulesOnStop { get; set; }

Property Value

bool

WorkingTime

Working schedule.

[Display(ResourceType = typeof(LocalizedStrings), Name = "WorkingTime", Description = "WorkingHours", GroupName = "General", Order = 15)]
public WorkingTime WorkingTime { get; set; }

Property Value

WorkingTime

Methods

ApplyCommand(CommandMessage)

Apply incoming command.

public virtual void ApplyCommand(CommandMessage cmdMsg)

Parameters

cmdMsg CommandMessage

The 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 Order

Order.

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 decimal

Price.

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

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.

CanAttach(Order)

Determines the specified order can be owned by the strategy.

protected virtual bool CanAttach(Order order)

Parameters

order Order

Order.

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 DateTimeOffset
reducePosition bool
noTradeReason string

Returns

bool

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 Order

The 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 Security

Security. If not passed the value from Security will be obtain.

portfolio Portfolio

Portfolio. 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

IChartArea

IChartArea

DisposeManaged()

Release resources.

protected override void DisposeManaged()

DrawCandles(IChartArea, Subscription)

Draw candles on chart.

protected IChartCandleElement DrawCandles(IChartArea area, Subscription subscription)

Parameters

area IChartArea

IChartArea

subscription Subscription

Subscription

Returns

IChartCandleElement

IChartCandleElement

DrawCandles<T>(IChartArea, SubscriptionHandler<T>)

Draw candles on chart.

protected IChartCandleElement DrawCandles<T>(IChartArea area, Strategy.SubscriptionHandler<T> subscription)

Parameters

area IChartArea

IChartArea

subscription Strategy.SubscriptionHandler<T>

Strategy.SubscriptionHandler<T>

Returns

IChartCandleElement

IChartCandleElement

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 IChartArea

IChartArea

indicator IIndicator

IIndicator

color Color?

Color

additionalColor Color?

AdditionalColor

Returns

IChartIndicatorElement

IChartIndicatorElement

DrawOrderBook(Subscription, IOrderBookSource, IOrderBookMessage)

public void DrawOrderBook(Subscription subscription, IOrderBookSource source, IOrderBookMessage book)

Parameters

subscription Subscription

Subscription

source IOrderBookSource

IOrderBookSource

book IOrderBookMessage

IOrderBookMessage

DrawOrderBookOrder(Subscription, IOrderBookSource, Order)

Draw order book order.

public void DrawOrderBookOrder(Subscription subscription, IOrderBookSource source, Order order)

Parameters

subscription Subscription

Subscription

source IOrderBookSource

IOrderBookSource

order Order

Order.

DrawOrderBookOrderFail(Subscription, IOrderBookSource, OrderFail)

Draw order book order fail.

public void DrawOrderBookOrderFail(Subscription subscription, IOrderBookSource source, OrderFail fail)

Parameters

subscription Subscription

Subscription

source IOrderBookSource

IOrderBookSource

fail OrderFail

Order fail.

DrawOrders(IChartArea)

Draw orders on chart.

protected IChartOrderElement DrawOrders(IChartArea area)

Parameters

area IChartArea

IChartArea

Returns

IChartOrderElement

IChartOrderElement

DrawOwnTrades(IChartArea)

Draw trades on chart.

protected IChartTradeElement DrawOwnTrades(IChartArea area)

Parameters

area IChartArea

IChartArea

Returns

IChartTradeElement

IChartTradeElement

EditOrder(Order, Order)

Edit the order.

public void EditOrder(Order order, Order changes)

Parameters

order Order

Order.

changes Order

Order changes.

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 Security

Security.

Returns

IEnumerable<Level1Fields>

Possible fields.

GetPositionValue(Security, Portfolio)

Get position.

public decimal? GetPositionValue(Security security, Portfolio portfolio)

Parameters

security Security

Security.

portfolio Portfolio

Portfolio.

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 Security

Security.

field Level1Fields

Market-data field.

Returns

object

The field value. If no data, the null will be returned.

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 Order

Order.

Returns

bool?

true if the order is editable, false order cannot be changed, null means no information.

IsOrderReplaceable(Order)

Determines the specified order can be replaced by ReRegisterOrder(Order, Order).

public bool? IsOrderReplaceable(Order order)

Parameters

order Order

Order.

Returns

bool?

true if the order is replaceable, false order cannot be replaced, null means no information.

Load(SettingsStorage)

Load settings.

public override void Load(SettingsStorage storage)

Parameters

storage SettingsStorage

Settings storage.

Lookup(SecurityLookupMessage)

Lookup securities by criteria criteria.

public IEnumerable<Security> Lookup(SecurityLookupMessage criteria)

Parameters

criteria SecurityLookupMessage

Message 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 SecurityId

Security ID.

Returns

Security

The got instrument. If there is no instrument by given criteria, null is returned.

OnError(Strategy, Exception)

Processing of error, occurred as result of strategy operation.

protected virtual void OnError(Strategy strategy, Exception error)

Parameters

strategy Strategy

Strategy.

error Exception

Error.

OnNewMyTrade(MyTrade)

The method, called at occurrence of new strategy trade.

protected virtual void OnNewMyTrade(MyTrade trade)

Parameters

trade MyTrade

New trade of a strategy.

OnOrderCanceling(Order)

To call the event OrderCanceling.

protected virtual void OnOrderCanceling(Order order)

Parameters

order Order

Order.

OnOrderChanged(Order)

The method, called at strategy order change.

protected virtual void OnOrderChanged(Order order)

Parameters

order Order

The changed order.

OnOrderReRegistering(Order, Order)

To call the event OrderReRegistering.

protected virtual void OnOrderReRegistering(Order oldOrder, Order newOrder)

Parameters

oldOrder Order

Cancelling order.

newOrder Order

New order to register.

OnOrderRegisterFailed(OrderFail, bool)

The method, called at strategy order registration error.

protected virtual void OnOrderRegisterFailed(OrderFail fail, bool calcRisk)

Parameters

fail OrderFail

Error registering order.

calcRisk bool

Invoke risk manager.

OnOrderRegistered(Order)

To call the event OrderRegistered.

protected virtual void OnOrderRegistered(Order order)

Parameters

order Order

Order.

OnOrderRegistering(Order)

To call the event OrderRegistering.

protected virtual void OnOrderRegistering(Order order)

Parameters

order Order

Order.

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 LogMessage

A debug message.

RaiseParametersChanged(string)

To call events ParametersChanged and PropertyChanged.

public void RaiseParametersChanged(string name = null)

Parameters

name string

Parameter name.

RaiseProcessStateChanged(Strategy)

To call the event ProcessStateChanged.

protected void RaiseProcessStateChanged(Strategy strategy)

Parameters

strategy Strategy

Strategy.

ReRegisterOrder(Order, Order)

Reregister the order.

public void ReRegisterOrder(Order oldOrder, Order newOrder)

Parameters

oldOrder Order

Cancelling order.

newOrder Order

New order to register.

RegisterOrder(Order)

Register new order.

public void RegisterOrder(Order order)

Parameters

order Order

Registration 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 SettingsStorage

Settings storage.

Save(SettingsStorage, bool, bool, bool, bool)

Save settings.

public void Save(SettingsStorage storage, bool saveStatistics, bool saveSystemParameters, bool saveSecurity, bool savePortfolio)

Parameters

storage SettingsStorage

Ecng.Serialization.SettingsStorage

saveStatistics bool

KeepStatistics

saveSystemParameters bool

Save system parameters.

saveSecurity bool

Save Security.

savePortfolio bool

Save Portfolio.

SellLimit(decimal, decimal?)

To create the initialized order object for sell.

public Order SellLimit(decimal price, decimal? volume = null)

Parameters

price decimal

Price.

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

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.

SetPositionValue(Security, Portfolio, decimal)

Set position.

public void SetPositionValue(Security security, Portfolio portfolio, decimal value)

Parameters

security Security

Security.

portfolio Portfolio

Portfolio.

value decimal

Position.

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 Unit

Take offset.

stopLoss Unit

Stop offset.

isStopTrailing bool

Whether to use a trailing technique.

takeTimeout TimeSpan

Time limit. If protection has not worked by this time, the position will be closed on the market.

stopTimeout TimeSpan

Time limit. If protection has not worked by this time, the position will be closed on the market.

useMarketOrders bool

Whether 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 Exception

Error.

Subscribe(Subscription)

Subscribe.

public void Subscribe(Subscription subscription)

Parameters

subscription Subscription

Subscription.

SubscribeCandles(Subscription)

Subscribe to candles.

protected Strategy.SubscriptionHandler<ICandleMessage> SubscribeCandles(Subscription subscription)

Parameters

subscription Subscription

Subscription

Returns

Strategy.SubscriptionHandler<ICandleMessage>

Strategy.SubscriptionHandler<T>

SubscribeCandles(DataType, bool, Security)

Subscribe to candles.

protected Strategy.SubscriptionHandler<ICandleMessage> SubscribeCandles(DataType dt, bool isFinishedOnly = true, Security security = null)

Parameters

dt DataType

DataType

isFinishedOnly bool

IsFinishedOnly

security Security

Security. If security is not passed, then Security value is used.

Returns

Strategy.SubscriptionHandler<ICandleMessage>

Strategy.SubscriptionHandler<T>

SubscribeCandles(TimeSpan, bool, Security)

Subscribe to candles.

protected Strategy.SubscriptionHandler<ICandleMessage> SubscribeCandles(TimeSpan tf, bool isFinishedOnly = true, Security security = null)

Parameters

tf TimeSpan

Time-frame.

isFinishedOnly bool

IsFinishedOnly

security Security

Security. If security is not passed, then Security value is used.

Returns

Strategy.SubscriptionHandler<ICandleMessage>

Strategy.SubscriptionHandler<T>

SubscribeLevel1(Security)

Subscribe to Level1.

protected Strategy.SubscriptionHandler<Level1ChangeMessage> SubscribeLevel1(Security security = null)

Parameters

security Security

Security. If security is not passed, then Security value is used.

Returns

Strategy.SubscriptionHandler<Level1ChangeMessage>

Strategy.SubscriptionHandler<T>

SubscribeLevel1(Subscription)

Subscribe to Level1.

protected Strategy.SubscriptionHandler<Level1ChangeMessage> SubscribeLevel1(Subscription subscription)

Parameters

subscription Subscription

Subscription

Returns

Strategy.SubscriptionHandler<Level1ChangeMessage>

Strategy.SubscriptionHandler<T>

SubscribeOrderBook(Security)

Subscribe to MarketDepth.

protected Strategy.SubscriptionHandler<IOrderBookMessage> SubscribeOrderBook(Security security = null)

Parameters

security Security

Security. If security is not passed, then Security value is used.

Returns

Strategy.SubscriptionHandler<IOrderBookMessage>

Strategy.SubscriptionHandler<T>

SubscribeOrderBook(Subscription)

Subscribe to MarketDepth.

protected Strategy.SubscriptionHandler<IOrderBookMessage> SubscribeOrderBook(Subscription subscription)

Parameters

subscription Subscription

Subscription

Returns

Strategy.SubscriptionHandler<IOrderBookMessage>

Strategy.SubscriptionHandler<T>

SubscribeTicks(Security)

Subscribe to Ticks.

protected Strategy.SubscriptionHandler<ITickTradeMessage> SubscribeTicks(Security security = null)

Parameters

security Security

Security. If security is not passed, then Security value is used.

Returns

Strategy.SubscriptionHandler<ITickTradeMessage>

Strategy.SubscriptionHandler<T>

SubscribeTicks(Subscription)

Subscribe to Ticks.

protected Strategy.SubscriptionHandler<ITickTradeMessage> SubscribeTicks(Subscription subscription)

Parameters

subscription Subscription

Subscription

Returns

Strategy.SubscriptionHandler<ITickTradeMessage>

Strategy.SubscriptionHandler<T>

TryAddMyTrade(MyTrade)

Try add own trade.

public bool TryAddMyTrade(MyTrade trade)

Parameters

trade MyTrade

MyTrade

Returns

bool

Operation result.

UnSubscribe(Subscription)

Unsubscribe.

public void UnSubscribe(Subscription subscription)

Parameters

subscription Subscription

Subscription.

Events

BoardReceived

Board received.

public event Action<Subscription, ExchangeBoard> BoardReceived

Event Type

Action<Subscription, ExchangeBoard>

CandleReceived

Candle received.

public event Action<Subscription, ICandleMessage> CandleReceived

Event Type

Action<Subscription, ICandleMessage>

CommissionChanged

Commission change event.

public event Action CommissionChanged

Event Type

Action

ConnectorChanged

The event of strategy connection change.

public event Action ConnectorChanged

Event Type

Action

Error

The event of error occurrence in the strategy.

public event Action<Strategy, Exception> Error

Event Type

Action<Strategy, Exception>

IsOnlineChanged

The event of strategy online state change.

public event Action<Strategy> IsOnlineChanged

Event Type

Action<Strategy>

LatencyChanged

Latency change event.

public event Action LatencyChanged

Event Type

Action

Level1Received

Level1 received.

public event Action<Subscription, Level1ChangeMessage> Level1Received

Event Type

Action<Subscription, Level1ChangeMessage>

LookupBoardsResult

Lookup result BoardLookupMessage received.

public event Action<BoardLookupMessage, IEnumerable<ExchangeBoard>, Exception> LookupBoardsResult

Event Type

Action<BoardLookupMessage, IEnumerable<ExchangeBoard>, Exception>

LookupBoardsResult2

Lookup result BoardLookupMessage received.

public event Action<BoardLookupMessage, IEnumerable<ExchangeBoard>, IEnumerable<ExchangeBoard>, Exception> LookupBoardsResult2

Event Type

Action<BoardLookupMessage, IEnumerable<ExchangeBoard>, IEnumerable<ExchangeBoard>, Exception>

LookupSecuritiesResult

Lookup result SecurityLookupMessage received.

public event Action<SecurityLookupMessage, IEnumerable<Security>, Exception> LookupSecuritiesResult

Event Type

Action<SecurityLookupMessage, IEnumerable<Security>, Exception>

LookupSecuritiesResult2

Lookup result SecurityLookupMessage received.

public event Action<SecurityLookupMessage, IEnumerable<Security>, IEnumerable<Security>, Exception> LookupSecuritiesResult2

Event Type

Action<SecurityLookupMessage, IEnumerable<Security>, IEnumerable<Security>, Exception>

LookupTimeFramesResult

Lookup result TimeFrameLookupMessage received.

public event Action<TimeFrameLookupMessage, IEnumerable<TimeSpan>, Exception> LookupTimeFramesResult

Event Type

Action<TimeFrameLookupMessage, IEnumerable<TimeSpan>, Exception>

LookupTimeFramesResult2

Lookup result TimeFrameLookupMessage received.

public event Action<TimeFrameLookupMessage, IEnumerable<TimeSpan>, IEnumerable<TimeSpan>, Exception> LookupTimeFramesResult2

Event Type

Action<TimeFrameLookupMessage, IEnumerable<TimeSpan>, IEnumerable<TimeSpan>, Exception>

MarketDataSubscriptionFailed

Error subscription market-data.

[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, Exception> MarketDataSubscriptionFailed

Event Type

Action<Security, MarketDataMessage, Exception>

MarketDataSubscriptionFailed2

Error subscription market-data.

[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, SubscriptionResponseMessage> MarketDataSubscriptionFailed2

Event Type

Action<Security, MarketDataMessage, SubscriptionResponseMessage>

MarketDataSubscriptionFinished

Subscription market-data finished.

[Obsolete("Use SubscriptionStopped event.")]
public event Action<Security, SubscriptionFinishedMessage> MarketDataSubscriptionFinished

Event Type

Action<Security, SubscriptionFinishedMessage>

MarketDataSubscriptionOnline

Subscription is online.

[Obsolete("Use SubscriptionOnline event.")]
public event Action<Security, MarketDataMessage> MarketDataSubscriptionOnline

Event Type

Action<Security, MarketDataMessage>

MarketDataSubscriptionSucceeded

Successful subscription market-data.

[Obsolete("Use SubscriptionStarted event.")]
public event Action<Security, MarketDataMessage> MarketDataSubscriptionSucceeded

Event Type

Action<Security, MarketDataMessage>

MarketDataUnSubscriptionFailed

Error unsubscription market-data.

[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, Exception> MarketDataUnSubscriptionFailed

Event Type

Action<Security, MarketDataMessage, Exception>

MarketDataUnSubscriptionFailed2

Error unsubscription market-data.

[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, SubscriptionResponseMessage> MarketDataUnSubscriptionFailed2

Event Type

Action<Security, MarketDataMessage, SubscriptionResponseMessage>

MarketDataUnSubscriptionSucceeded

Successful unsubscription market-data.

[Obsolete("Use SubscriptionStopped event.")]
public event Action<Security, MarketDataMessage> MarketDataUnSubscriptionSucceeded

Event Type

Action<Security, MarketDataMessage>

MarketDataUnexpectedCancelled

Market-data subscription unexpected cancelled.

[Obsolete("Use SubscriptionFailed event.")]
public event Action<Security, MarketDataMessage, Exception> MarketDataUnexpectedCancelled

Event Type

Action<Security, MarketDataMessage, Exception>

MarketDepthChanged

Order book changed.

[Obsolete("Use OrderBookReceived event.")]
public event Action<MarketDepth> MarketDepthChanged

Event Type

Action<MarketDepth>

MarketDepthReceived

Order book received.

[Obsolete("Use OrderBookReceived event.")]
public event Action<Subscription, MarketDepth> MarketDepthReceived

Event Type

Action<Subscription, MarketDepth>

NewMarketDepth

Order book received.

[Obsolete("Use OrderBookReceived event.")]
public event Action<MarketDepth> NewMarketDepth

Event Type

Action<MarketDepth>

NewMyTrade

Own trade received.

public event Action<MyTrade> NewMyTrade

Event Type

Action<MyTrade>

NewNews

News received.

[Obsolete("Use NewsReceived event.")]
public event Action<News> NewNews

Event Type

Action<News>

NewOrderLogItem

Order log received.

[Obsolete("Use OrderLogItemReceived event.")]
public event Action<OrderLogItem> NewOrderLogItem

Event Type

Action<OrderLogItem>

NewSecurity

Security received.

[Obsolete("Use SecurityReceived event.")]
public event Action<Security> NewSecurity

Event Type

Action<Security>

NewTrade

Tick trade received.

[Obsolete("Use TickTradeReceived event.")]
public event Action<Trade> NewTrade

Event Type

Action<Trade>

NewsChanged

News updated (news body received Story).

[Obsolete("Use NewsReceived event.")]
public event Action<News> NewsChanged

Event Type

Action<News>

NewsReceived

News received.

public event Action<Subscription, News> NewsReceived

Event Type

Action<Subscription, News>

OrderBookDrawing

public event Action<Subscription, IOrderBookSource, IOrderBookMessage> OrderBookDrawing

Event Type

Action<Subscription, IOrderBookSource, IOrderBookMessage>

OrderBookDrawingOrder

public event Action<Subscription, IOrderBookSource, Order> OrderBookDrawingOrder

Event Type

Action<Subscription, IOrderBookSource, Order>

OrderBookDrawingOrderFail

public event Action<Subscription, IOrderBookSource, OrderFail> OrderBookDrawingOrderFail

Event Type

Action<Subscription, IOrderBookSource, OrderFail>

OrderBookReceived

Order book received.

public event Action<Subscription, IOrderBookMessage> OrderBookReceived

Event Type

Action<Subscription, IOrderBookMessage>

OrderCancelFailReceived

Order cancellation error event.

public event Action<Subscription, OrderFail> OrderCancelFailReceived

Event Type

Action<Subscription, OrderFail>

OrderCancelFailed

Order cancellation error event.

public event Action<OrderFail> OrderCancelFailed

Event Type

Action<OrderFail>

OrderCanceling

The event of sending order for cancelling.

public event Action<Order> OrderCanceling

Event Type

Action<Order>

OrderChanged

Order changed (cancelled, matched).

public event Action<Order> OrderChanged

Event Type

Action<Order>

OrderEditFailReceived

Order edition error event.

public event Action<Subscription, OrderFail> OrderEditFailReceived

Event Type

Action<Subscription, OrderFail>

OrderEditFailed

EditOrder(Order, Order) error result event.

public event Action<long, OrderFail> OrderEditFailed

Event Type

Action<long, OrderFail>

OrderEdited

EditOrder(Order, Order) success result event.

public event Action<long, Order> OrderEdited

Event Type

Action<long, Order>

OrderLogItemReceived

Order log received.

[Obsolete("Use OrderLogReceived event.")]
public event Action<Subscription, OrderLogItem> OrderLogItemReceived

Event Type

Action<Subscription, OrderLogItem>

OrderLogReceived

Tick trade received.

public event Action<Subscription, IOrderLogMessage> OrderLogReceived

Event Type

Action<Subscription, IOrderLogMessage>

OrderReRegistering

The event of sending order for re-registration.

public event Action<Order, Order> OrderReRegistering

Event Type

Action<Order, Order>

OrderReceived

Order received.

public event Action<Subscription, Order> OrderReceived

Event Type

Action<Subscription, Order>

OrderRegisterFailReceived

Order registration error event.

public event Action<Subscription, OrderFail> OrderRegisterFailReceived

Event Type

Action<Subscription, OrderFail>

OrderRegisterFailed

Order registration error event.

public event Action<OrderFail> OrderRegisterFailed

Event Type

Action<OrderFail>

OrderRegistered

The event of order successful registration.

public event Action<Order> OrderRegistered

Event Type

Action<Order>

OrderRegistering

The event of sending order for registration.

public event Action<Order> OrderRegistering

Event Type

Action<Order>

OwnTradeReceived

Own trade received.

public event Action<Subscription, MyTrade> OwnTradeReceived

Event Type

Action<Subscription, MyTrade>

ParametersChanged

Parameters change event.

public event Action ParametersChanged

Event Type

Action

PnLChanged

PnL change event.

public event Action PnLChanged

Event Type

Action

PnLReceived

PnL change event.

[Obsolete("Use PnLReceived2 event.")]
public event Action<Subscription> PnLReceived

Event Type

Action<Subscription>

PnLReceived2

PnL change event.

public event Action<Subscription, Portfolio, DateTimeOffset, decimal, decimal?, decimal?> PnLReceived2

Event Type

Action<Subscription, Portfolio, DateTimeOffset, decimal, decimal?, decimal?>

PortfolioReceived

Portfolio received.

public event Action<Subscription, Portfolio> PortfolioReceived

Event Type

Action<Subscription, Portfolio>

PositionChanged

Position change event.

public event Action PositionChanged

Event Type

Action

PositionReceived

Position received.

public event Action<Subscription, Position> PositionReceived

Event Type

Action<Subscription, Position>

ProcessStateChanged

ProcessState change event.

public event Action<Strategy> ProcessStateChanged

Event Type

Action<Strategy>

PropertyChanged

public event PropertyChangedEventHandler PropertyChanged

Event Type

PropertyChangedEventHandler

Reseted

The event of the strategy re-initialization.

public event Action Reseted

Event Type

Action

SecurityChanged

Security changed.

[Obsolete("Use SecurityReceived event.")]
public event Action<Security> SecurityChanged

Event Type

Action<Security>

SecurityReceived

Security received.

public event Action<Subscription, Security> SecurityReceived

Event Type

Action<Subscription, Security>

SlippageChanged

Slippage change event.

public event Action SlippageChanged

Event Type

Action

StopOrderCancelFailed

Stop-order cancellation error event.

[Obsolete("Use OrderCancelFailed event.")]
public event Action<OrderFail> StopOrderCancelFailed

Event Type

Action<OrderFail>

StopOrderCanceling

The event of sending stop-order for cancelling.

[Obsolete("Use OrderCanceling event.")]
public event Action<Order> StopOrderCanceling

Event Type

Action<Order>

StopOrderChanged

Stop order state change event.

[Obsolete("Use OrderChanged event.")]
public event Action<Order> StopOrderChanged

Event Type

Action<Order>

StopOrderReRegistering

The event of sending stop-order for re-registration.

[Obsolete("Use OrderReRegistering event.")]
public event Action<Order, Order> StopOrderReRegistering

Event Type

Action<Order, Order>

StopOrderRegisterFailed

Stop-order registration error event.

[Obsolete("Use OrderRegisterFailed event.")]
public event Action<OrderFail> StopOrderRegisterFailed

Event Type

Action<OrderFail>

StopOrderRegistered

The event of stop-order successful registration.

[Obsolete("Use OrderRegistered event.")]
public event Action<Order> StopOrderRegistered

Event Type

Action<Order>

StopOrderRegistering

The event of sending stop-order for registration.

[Obsolete("Use OrderRegistering event.")]
public event Action<Order> StopOrderRegistering

Event Type

Action<Order>

SubscriptionFailed

Subscription is failed.

public event Action<Subscription, Exception, bool> SubscriptionFailed

Event Type

Action<Subscription, Exception, bool>

SubscriptionOnline

Subscription is online.

public event Action<Subscription> SubscriptionOnline

Event Type

Action<Subscription>

SubscriptionReceived

Message received.

public event Action<Subscription, object> SubscriptionReceived

Event Type

Action<Subscription, object>

SubscriptionStarted

Subscription is started.

public event Action<Subscription> SubscriptionStarted

Event Type

Action<Subscription>

SubscriptionStopped

Subscription is stopped.

public event Action<Subscription, Exception> SubscriptionStopped

Event Type

Action<Subscription, Exception>

TickTradeReceived

Tick trade received.

public event Action<Subscription, ITickTradeMessage> TickTradeReceived

Event Type

Action<Subscription, ITickTradeMessage>

ValuesChanged

Security changed.

public event Action<Security, IEnumerable<KeyValuePair<Level1Fields, object>>, DateTimeOffset, DateTimeOffset> ValuesChanged

Event Type

Action<Security, IEnumerable<KeyValuePair<Level1Fields, object>>, DateTimeOffset, DateTimeOffset>