Class StrategyHelper
- Namespace
- StockSharp.Algo.Strategies
- Assembly
- StockSharp.Algo.dll
Extension class for Strategy.
public static class StrategyHelper
- Inheritance
-
StrategyHelper
- Inherited Members
Methods
BuyAtLimit(Strategy, decimal, decimal?)
To create the initialized order object for buy.
[Obsolete("Use Strategy.BuyLimit method.")]
public static Order BuyAtLimit(this Strategy strategy, decimal price, decimal? volume = null)
Parameters
strategy
StrategyStrategy.
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.
BuyAtMarket(Strategy, decimal?)
To create initialized object of buy order at market price.
[Obsolete("Use Strategy.BuyMarket method.")]
public static Order BuyAtMarket(this Strategy strategy, decimal? volume = null)
Parameters
strategy
StrategyStrategy.
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.
Cancel(IMarketRule, Order)
To create an action, cancelling the order.
public static IMarketRule Cancel(this IMarketRule rule, Order order)
Parameters
rule
IMarketRuleRule.
order
OrderThe order to be cancelled.
Returns
- IMarketRule
Rule.
ClosePositionByQuoting(Strategy)
To close the open position via quoting.
public static void ClosePositionByQuoting(this Strategy strategy)
Parameters
strategy
StrategyStrategy.
CreateOrder(Strategy, Sides, decimal, decimal?)
To create the initialized order object.
public static Order CreateOrder(this Strategy strategy, Sides side, decimal price, decimal? volume = null)
Parameters
strategy
StrategyStrategy.
side
SidesOrder side.
price
decimalThe price. If null value is passed, the order is registered at market 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.
GetChart(Strategy)
To get the IChart associated with the passed strategy.
public static IChart GetChart(this Strategy strategy)
Parameters
strategy
StrategyStrategy.
Returns
- IChart
Chart.
GetIsEmulation(Strategy)
To get the strategy start-up mode (paper trading or real).
[Obsolete("Use Strategy.IsBacktesting property.")]
public static bool GetIsEmulation(this Strategy strategy)
Parameters
strategy
StrategyStrategy.
Returns
GetOptionDesk(Strategy)
To get the IOptionDesk.
public static IOptionDesk GetOptionDesk(this Strategy strategy)
Parameters
strategy
StrategyStrategy.
Returns
GetOptionPositionChart(Strategy)
To get the IOptionPositionChart associated with the passed strategy.
public static IOptionPositionChart GetOptionPositionChart(this Strategy strategy)
Parameters
strategy
StrategyStrategy.
Returns
- IOptionPositionChart
Chart.
GetPortfolio(Strategy)
Get Portfolio or throw InvalidOperationException if not present.
public static Portfolio GetPortfolio(this Strategy strategy)
Parameters
strategy
Strategy
Returns
GetSecurity(Strategy)
Get Security or throw InvalidOperationException if not present.
public static Security GetSecurity(this Strategy strategy)
Parameters
strategy
Strategy
Returns
GetSecurityValue<T>(Strategy, Level1Fields)
To get market data value for the strategy instrument.
public static T GetSecurityValue<T>(this Strategy strategy, Level1Fields field)
Parameters
strategy
StrategyStrategy.
field
Level1FieldsMarket-data field.
Returns
- T
The field value. If no data, the null will be returned.
Type Parameters
T
The type of the market data field value.
IsFormedAndOnline(Strategy)
public static bool IsFormedAndOnline(this Strategy strategy)
Parameters
Returns
- bool
Check result.
IsFormedAndOnlineAndAllowTrading(Strategy, StrategyTradingModes)
public static bool IsFormedAndOnlineAndAllowTrading(this Strategy strategy, StrategyTradingModes required = StrategyTradingModes.Full)
Parameters
strategy
Strategyrequired
StrategyTradingModesRequired action.
Returns
- bool
Check result.
OpenPositionByQuoting(Strategy, decimal)
To open the position via quoting.
public static void OpenPositionByQuoting(this Strategy strategy, decimal finishPosition)
Parameters
strategy
StrategyStrategy.
finishPosition
decimalThe position value that should be reached. A negative value means the short position.
Protect(MarketRule<Order, MyTrade>, Unit, Unit)
To create the action protecting orders by strategies TakeProfitStrategy and StopLossStrategy.
[Obsolete("Use ProtectiveController class.")]
public static MarketRule<Order, MyTrade> Protect(this MarketRule<Order, MyTrade> rule, Unit takePriceDelta, Unit stopPriceDelta)
Parameters
rule
MarketRule<Order, MyTrade>The rule for new orders.
takePriceDelta
UnitThe delta from the price of the protected order, by which the protective take profit order is to be registered.
stopPriceDelta
UnitThe delta from the price of the protected order, by which the protective stop loss order is to be registered.
Returns
- MarketRule<Order, MyTrade>
Rule.
Protect(MarketRule<Order, MyTrade>, Func<MyTrade, TakeProfitStrategy>, Func<MyTrade, StopLossStrategy>)
To create the action protecting orders by strategies TakeProfitStrategy and StopLossStrategy.
[Obsolete("Use ProtectiveController class.")]
public static MarketRule<Order, MyTrade> Protect(this MarketRule<Order, MyTrade> rule, Func<MyTrade, TakeProfitStrategy> takeProfit, Func<MyTrade, StopLossStrategy> stopLoss)
Parameters
rule
MarketRule<Order, MyTrade>The rule for new orders.
takeProfit
Func<MyTrade, TakeProfitStrategy>The function that creates the strategy TakeProfitStrategy by the order.
stopLoss
Func<MyTrade, StopLossStrategy>The function that creates the strategy StopLossStrategy by the order.
Returns
- MarketRule<Order, MyTrade>
Rule.
ReRegister(IMarketRule, Order, Order)
To create an action, re-registering the order.
public static IMarketRule ReRegister(this IMarketRule rule, Order oldOrder, Order newOrder)
Parameters
rule
IMarketRuleRule.
oldOrder
OrderThe order to be re-registered.
newOrder
OrderInformation about new order.
Returns
- IMarketRule
Rule.
Register(IMarketRule, Order)
To create an action, registering the order.
public static IMarketRule Register(this IMarketRule rule, Order order)
Parameters
rule
IMarketRuleRule.
order
OrderThe order to be registered.
Returns
- IMarketRule
Rule.
SellAtLimit(Strategy, decimal, decimal?)
To create the initialized order object for sell.
[Obsolete("Use Strategy.SellLimit method.")]
public static Order SellAtLimit(this Strategy strategy, decimal price, decimal? volume = null)
Parameters
strategy
StrategyStrategy.
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.
SellAtMarket(Strategy, decimal?)
To create the initialized order object of sell order at market price.
[Obsolete("Use Strategy.SellMarket method.")]
public static Order SellAtMarket(this Strategy strategy, decimal? volume = null)
Parameters
strategy
StrategyStrategy.
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.
SetChart(Strategy, IChart)
To set a IChart for the strategy.
public static void SetChart(this Strategy strategy, IChart chart)
Parameters
SetIsEmulation(Strategy, IOptionDesk)
To set the IOptionDesk.
public static void SetIsEmulation(this Strategy strategy, IOptionDesk desk)
Parameters
strategy
StrategyStrategy.
desk
IOptionDesk
SetIsEmulation(Strategy, bool)
To set the strategy start-up mode (paper trading or real).
[Obsolete("Use Strategy.IsBacktesting property.")]
public static void SetIsEmulation(this Strategy strategy, bool isEmulation)
Parameters
strategy
StrategyStrategy.
isEmulation
boolIf the paper trading mode is used - true, otherwise - false.
SetOptionPositionChart(Strategy, IOptionPositionChart)
To set a IChart for the strategy.
public static void SetOptionPositionChart(this Strategy strategy, IOptionPositionChart chart)
Parameters
strategy
StrategyStrategy.
chart
IOptionPositionChartChart.
WhenActivated(ProtectiveStrategy)
To create the rule for the event Activated.
[Obsolete("Use ProtectiveController class.")]
public static IMarketRule WhenActivated(this ProtectiveStrategy strategy)
Parameters
strategy
ProtectiveStrategyThe strategy, by which the event will be monitored.
Returns
- IMarketRule
Rule.
WhenError(Strategy, bool)
To create a rule for event of strategy error (transition of state ErrorState into Error).
public static MarketRule<Strategy, Exception> WhenError(this Strategy strategy, bool processChildStrategyErrors = false)
Parameters
strategy
StrategyThe strategy, based on which error will be expected.
processChildStrategyErrors
boolProcess the child strategies errors.
Returns
- MarketRule<Strategy, Exception>
Rule.
WhenNewMyTrade(Strategy)
To create a rule for the event of occurrence new strategy trade.
public static MarketRule<Strategy, MyTrade> WhenNewMyTrade(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which trade occurrence will be traced.
Returns
- MarketRule<Strategy, MyTrade>
Rule.
WhenOrderChanged(Strategy)
To create a rule for event of change of any strategy order.
public static MarketRule<Strategy, Order> WhenOrderChanged(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which orders change will be traced.
Returns
- MarketRule<Strategy, Order>
Rule.
WhenOrderRegistered(Strategy)
To create a rule for event of occurrence of new strategy order.
public static MarketRule<Strategy, Order> WhenOrderRegistered(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which order occurrence will be traced.
Returns
- MarketRule<Strategy, Order>
Rule.
WhenPnLChanged(Strategy)
To create a rule for event of profit change.
public static MarketRule<Strategy, decimal> WhenPnLChanged(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which the profit change will be traced.
Returns
- MarketRule<Strategy, decimal>
Rule.
WhenPnLLess(Strategy, Unit)
To create a rule for event of profit reduction below the specified level.
public static MarketRule<Strategy, decimal> WhenPnLLess(this Strategy strategy, Unit value)
Parameters
strategy
StrategyThe strategy, based on which the profit change will be traced.
value
UnitThe level. If the Type type equals to Limit, specified price is set. Otherwise, shift value is specified.
Returns
- MarketRule<Strategy, decimal>
Rule.
WhenPnLMore(Strategy, Unit)
To create a rule for event of profit increase above the specified level.
public static MarketRule<Strategy, decimal> WhenPnLMore(this Strategy strategy, Unit value)
Parameters
strategy
StrategyThe strategy, based on which the profit change will be traced.
value
UnitThe level. If the Type type equals to Limit, specified price is set. Otherwise, shift value is specified.
Returns
- MarketRule<Strategy, decimal>
Rule.
WhenPositionChanged(Strategy)
To create a rule for the event of strategy position change.
public static MarketRule<Strategy, decimal> WhenPositionChanged(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which position change will be traced.
Returns
- MarketRule<Strategy, decimal>
Rule.
WhenPositionLess(Strategy, Unit)
To create a rule for event of position event reduction below the specified level.
public static MarketRule<Strategy, decimal> WhenPositionLess(this Strategy strategy, Unit value)
Parameters
strategy
StrategyThe strategy, based on which position change will be traced.
value
UnitThe level. If the Type type equals to Limit, specified price is set. Otherwise, shift value is specified.
Returns
- MarketRule<Strategy, decimal>
Rule.
WhenPositionMore(Strategy, Unit)
To create a rule for event of position event increase above the specified level.
public static MarketRule<Strategy, decimal> WhenPositionMore(this Strategy strategy, Unit value)
Parameters
strategy
StrategyThe strategy, based on which position change will be traced.
value
UnitThe level. If the Type type equals to Limit, specified price is set. Otherwise, shift value is specified.
Returns
- MarketRule<Strategy, decimal>
Rule.
WhenStarted(Strategy)
To create a rule for event of start of strategy operation.
public static MarketRule<Strategy, Strategy> WhenStarted(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which the start of strategy operation will be expected.
Returns
- MarketRule<Strategy, Strategy>
Rule.
WhenStopped(Strategy)
To create a rule for event full stop of strategy operation.
public static MarketRule<Strategy, Strategy> WhenStopped(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which the full stop will be expected.
Returns
- MarketRule<Strategy, Strategy>
Rule.
WhenStopping(Strategy)
To create a rule for event of beginning of the strategy operation stop.
public static MarketRule<Strategy, Strategy> WhenStopping(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which the beginning of stop will be determined.
Returns
- MarketRule<Strategy, Strategy>
Rule.
WhenWarning(Strategy)
To create a rule for event of strategy warning (transition of state ErrorState into Warning).
public static MarketRule<Strategy, Strategy> WhenWarning(this Strategy strategy)
Parameters
strategy
StrategyThe strategy, based on which the warning will be expected.
Returns
- MarketRule<Strategy, Strategy>
Rule.