PositionClosedEventArgs
Summary
Provides data for the position closing event.
Signature
| public class PositionClosedEventArgs
|
Namespace
cAlgo.API
Examples
| protected override void OnStart()
{
Positions.Closed += PositionsClosed;
}
private void PositionsOnClosed(PositionClosedEventArgs args)
{
var position = args.Position;
Print("Position closed with {0} profit", position.GrossProfit);
}
|
See Also
Properties
Position
Summary
Gets the position being closed.
Signature
| public Position Position {get;}
|
Return Value
Position
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | protected override void OnStart()
{
ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "myLabel");
Positions.Closed += PositionsClosed;
}
private void PositionsClosed(PositionClosedEventArgs args)
{
var position = args.Position;
if(position.Label == "myLabel")
{
var tradeType = position.TradeType;
var symbol = MarketData.GetSymbol(position.SymbolCode);
var volume = position.Volume;
var label = position.Label;
if(position.GrossProfit > 0)
ExecuteMarketOrder(tradeType, symbol, volume, label);
else
{
var oppositeTrade = tradeType == TradeType.Buy
? TradeType.Sell
: TradeType.Buy;
ExecuteMarketOrder(oppositeTrade, symbol, volume, label);
}
}
}
|
Reason
Summary
Gets the reason of the position being closed.
Signature
| public PositionCloseReason Reason {get;}
|
Return Value
PositionCloseReason