Class AutoProtectiveStrategy
The strategy of the automatic position protection.
Implements
Inherited Members
Namespace: StockSharp.Algo.Strategies.Protective
Assembly: StockSharp.Algo.Strategies.dll
Syntax
public class AutoProtectiveStrategy : Strategy, IPersistable, INotifyPropertyChangedEx, INotifyPropertyChanged, IMarketRuleContainer, ILogReceiver, ILogSource, ICloneable<Strategy>, ICloneable, IMarketDataProvider, ISubscriptionProvider, ISecurityProvider, ICandleManager, ICandleSource<Candle>, IDisposable, ITransactionProvider, IPositionProvider, IPortfolioProvider, IScheduledTask
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.
Declaration
public AutoProtectiveStrategy()
Properties
IsTrailingStopLoss
Whether to use a trailing technique for StopLossStrategy. The default is off.
Declaration
public bool IsTrailingStopLoss { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
IsTrailingTakeProfit
Whether to use a trailing technique for TakeProfitStrategy. The default is off.
Declaration
public bool IsTrailingTakeProfit { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Item[Security]
To get or set the initial position for the instrument.
Declaration
public Decimal this[Security security] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Security | security | Security. |
Property Value
Type | Description |
---|---|
Decimal | Position. |
MyTradesStrategy
The strategy which new trades are automatically passed to ProcessNewMyTrade(MyTrade).
Declaration
public Strategy MyTradesStrategy { get; set; }
Property Value
Type | Description |
---|---|
Strategy |
StopLossLevel
The protective level for the stop loss. The default level is 0, which means the disabled.
Declaration
public Unit StopLossLevel { get; set; }
Property Value
Type | Description |
---|---|
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.
Declaration
public TimeSpan StopLossTimeOut { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
TakeProfitLevel
The protective level for the take profit. The default level is 0, which means the disabled.
Declaration
public Unit TakeProfitLevel { get; set; }
Property Value
Type | Description |
---|---|
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.
Declaration
public TimeSpan TakeProfitTimeOut { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
UseMarketOrders
Whether to use market orders.
Declaration
public bool UseMarketOrders { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
OnStarted()
The method is called when the Start() method has been called and the ProcessState state has been taken the Started value.
Declaration
protected override void OnStarted()
Overrides
ProcessNewMyTrade(MyTrade)
To process trade to correct the protective strategies volume.
Declaration
public void ProcessNewMyTrade(MyTrade trade)
Parameters
Type | Name | Description |
---|---|---|
MyTrade | trade | Trade. |
Protect(MyTrade, Decimal)
Protect position.
Declaration
protected virtual Strategy Protect(MyTrade trade, Decimal volume)
Parameters
Type | Name | Description |
---|---|---|
MyTrade | trade | The protected trade. |
Decimal | volume | Volume to be protected is specified by the value. |
Returns
Type | Description |
---|---|
Strategy | Protective strategy. |
Protect(Decimal)
To protect the position that has been updated via Item[Security].
Declaration
protected virtual IProtectiveStrategy Protect(Decimal position)
Parameters
Type | Name | Description |
---|---|---|
Decimal | position | Position. |
Returns
Type | Description |
---|---|
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).
Declaration
protected virtual IEnumerable<IGrouping<Tuple<Sides, Decimal>, IProtectiveStrategy>> Sort(IEnumerable<IGrouping<Tuple<Sides, Decimal>, IProtectiveStrategy>> strategies)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IGrouping<Tuple<Sides, Decimal>, IProtectiveStrategy>> | strategies | Protective strategies in unsorted order. |
Returns
Type | Description |
---|---|
IEnumerable<IGrouping<Tuple<Sides, Decimal>, IProtectiveStrategy>> | Protective strategies in sorted order. |