Table of Contents

Class AutoProtectiveStrategy

Namespace
StockSharp.Algo.Strategies.Protective
Assembly
StockSharp.Algo.dll

The strategy of the automatic position protection.

[Obsolete("Use ProtectiveController class.")]
public class AutoProtectiveStrategy : Strategy, IPersistable, INotifyPropertyChangedEx, INotifyPropertyChanged, IMarketRuleContainer, ILogReceiver, ILogSource, IDisposable, ICloneable<Strategy>, ICloneable, IMarketDataProvider, ISubscriptionProvider, ISecurityProvider, ISecurityMessageProvider, ITransactionProvider, IPositionProvider, IPortfolioProvider, IScheduledTask
Inheritance
AutoProtectiveStrategy
Implements
IPersistable
INotifyPropertyChangedEx
ICloneable<Strategy>
Inherited Members
Extension Methods

Remarks

New trades come in strategy via ProcessNewMyTrade(MyTrade). They are automatically protected by TakeProfitStopLossStrategy. Also, AutoProtectiveStrategy turns over stops in case of position flipping.

Constructors

AutoProtectiveStrategy()

Initializes a new instance of the AutoProtectiveStrategy.

public AutoProtectiveStrategy()

Properties

IsTrailingStopLoss

Whether to use a trailing technique for StopLossStrategy. The default is off.

public bool IsTrailingStopLoss { get; set; }

Property Value

bool

IsTrailingTakeProfit

Whether to use a trailing technique for TakeProfitStrategy. The default is off.

public bool IsTrailingTakeProfit { get; set; }

Property Value

bool

this[Security]

To get or set the initial position for the instrument.

public decimal this[Security security] { get; set; }

Parameters

security Security

Security.

Property Value

decimal

Position.

MyTradesStrategy

The strategy which new trades are automatically passed to ProcessNewMyTrade(MyTrade).

public Strategy MyTradesStrategy { get; set; }

Property Value

Strategy

StopLossLevel

The protective level for the stop loss. The default level is 0, which means the disabled.

public Unit StopLossLevel { get; set; }

Property Value

Unit

StopLossTimeOut

Time limit for StopLossStrategy. If protection has not worked by this time, the position will be closed on the market. The default is off.

public TimeSpan StopLossTimeOut { get; set; }

Property Value

TimeSpan

TakeProfitLevel

The protective level for the take profit. The default level is 0, which means the disabled.

public Unit TakeProfitLevel { get; set; }

Property Value

Unit

TakeProfitTimeOut

Time limit for TakeProfitStrategy. If protection has not worked by this time, the position will be closed on the market. The default is off.

public TimeSpan TakeProfitTimeOut { get; set; }

Property Value

TimeSpan

UseMarketOrders

Whether to use market orders.

public bool UseMarketOrders { get; set; }

Property Value

bool

Methods

OnStarted(DateTimeOffset)

The method is called when the Start() method has been called and the ProcessState state has been taken the Started value.

protected override void OnStarted(DateTimeOffset time)

Parameters

time DateTimeOffset

ProcessNewMyTrade(MyTrade)

To process trade to correct the protective strategies volume.

public void ProcessNewMyTrade(MyTrade trade)

Parameters

trade MyTrade

Trade.

Protect(MyTrade, decimal)

Protect position.

protected virtual Strategy Protect(MyTrade trade, decimal volume)

Parameters

trade MyTrade

The protected trade.

volume decimal

Volume to be protected is specified by the value.

Returns

Strategy

Protective strategy.

Protect(decimal)

To protect the position that has been updated via this[Security].

protected virtual IProtectiveStrategy Protect(decimal position)

Parameters

position decimal

Position.

Returns

IProtectiveStrategy

The protective strategy. If null will be returned then the position protection is ignored.

Sort(IEnumerable<IGrouping<Tuple<Sides, decimal>, IProtectiveStrategy>>)

To sort protective strategies to define the worst and the best ones by market prices (when position is partially closed the worst ones are cancelled firstly).

protected virtual IEnumerable<IGrouping<Tuple<Sides, decimal>, IProtectiveStrategy>> Sort(IEnumerable<IGrouping<Tuple<Sides, decimal>, IProtectiveStrategy>> strategies)

Parameters

strategies IEnumerable<IGrouping<Tuple<Sides, decimal>, IProtectiveStrategy>>

Protective strategies in unsorted order.

Returns

IEnumerable<IGrouping<Tuple<Sides, decimal>, IProtectiveStrategy>>

Protective strategies in sorted order.