Skip to content

HistoricalTrade

Summary

Represents the historical trade interface.

Signature

1
public abstract interface HistoricalTrade

Namespace

cAlgo.API

Properties

Name Description
ClosingDealId { get; } Gets the unique closing deal identifier.
PositionId { get; } Gets the position unique identifier.
SymbolName { get; } Gets the symbol name.
TradeType { get; } The TradeType of the Opening Deal.
VolumeInUnits { get; } The Volume that was closed by the Closing Deal.
EntryTime { get; } Time of the Opening Deal, or the time of the first Opening deal that was closed.
EntryPrice { get; } The VWAP (Volume Weighted Average Price) of the Opening Deals that are closed.
ClosingTime { get; } Time of the Closing Deal.
ClosingPrice { get; } The execution price of the Closing Deal.
Label { get; } The label.
Comment { get; } The comment
Commissions { get; } Commission owed
Swap { get; } Swap is the overnight interest rate if any, accrued on the position.
NetProfit { get; } Profit and loss including swaps and commissions
GrossProfit { get; } Profit and loss before swaps and commission
Balance { get; } Account balance after the Deal was filled
Pips { get; } Represents the winning or loosing pips
Quantity { get; } The Quantity (in lots) that was closed by the Closing Deal
SymbolCode { get; }
Volume { get; }

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
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
 using cAlgo.API;
 using System.Linq;
 namespace cAlgo
 {
     // A sample indicator that shows how to use HistoricalTrade
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class HistorySample : Indicator
     {
         private Style _textBlocksStyle;
         private StackPanel _stackPanel;
         private Grid _tradesGrid;
         protected override void Initialize()
         {
             _stackPanel = new StackPanel
             {
                 Orientation = Orientation.Vertical,
                 HorizontalAlignment = HorizontalAlignment.Center,
                 VerticalAlignment = VerticalAlignment.Center,
                 BackgroundColor = Color.Gold
             };
             _textBlocksStyle = new Style();
             _textBlocksStyle.Set(ControlProperty.Margin, 5);
             _stackPanel.AddChild(new TextBox
             {
                 Text = "Your Last 10 Trades",
                 FontWeight = FontWeight.ExtraBold,
                 HorizontalAlignment = HorizontalAlignment.Center,
                 Style = _textBlocksStyle
             });
             Chart.AddControl(_stackPanel);
             UpdateLastTradeTextBlock();
             Positions.Closed += args => UpdateLastTradeTextBlock();
         }
         public override void Calculate(int index)
         {
         }
         private void UpdateLastTradeTextBlock()
         {
             if (_tradesGrid != null)
                 _stackPanel.RemoveChild(_tradesGrid);
             _tradesGrid = new Grid(11, 6);
             _tradesGrid.AddChild(new TextBlock
             {
                 Text = "Symbol",
                 Style = _textBlocksStyle
             }, 0, 0);
             _tradesGrid.AddChild(new TextBlock
             {
                 Text = "Direction",
                 Style = _textBlocksStyle
             }, 0, 1);
             _tradesGrid.AddChild(new TextBlock
             {
                 Text = "Volume",
                 Style = _textBlocksStyle
             }, 0, 2);
             _tradesGrid.AddChild(new TextBlock
             {
                 Text = "Open Time",
                 Style = _textBlocksStyle
             }, 0, 3);
             _tradesGrid.AddChild(new TextBlock
             {
                 Text = "Close Time",
                 Style = _textBlocksStyle
             }, 0, 4);
             _tradesGrid.AddChild(new TextBlock
             {
                 Text = "Net Profit",
                 Style = _textBlocksStyle
             }, 0, 5);
             var lastTenTrades = History.OrderByDescending(iTrade => iTrade.ClosingTime).Take(10).ToArray();
             for (int iRowIndex = 1; iRowIndex <= lastTenTrades.Length; iRowIndex++)
             {
                 var trade = lastTenTrades[iRowIndex - 1];
                 _tradesGrid.AddChild(new TextBlock
                 {
                     Text = trade.SymbolName,
                     Style = _textBlocksStyle
                 }, iRowIndex, 0);
                 _tradesGrid.AddChild(new TextBlock
                 {
                     Text = trade.TradeType.ToString(),
                     Style = _textBlocksStyle
                 }, iRowIndex, 1);
                 _tradesGrid.AddChild(new TextBlock
                 {
                     Text = trade.VolumeInUnits.ToString(),
                     Style = _textBlocksStyle
                 }, iRowIndex, 2);
                 _tradesGrid.AddChild(new TextBlock
                 {
                     Text = trade.EntryTime.ToString("g"),
                     Style = _textBlocksStyle
                 }, iRowIndex, 3);
                 _tradesGrid.AddChild(new TextBlock
                 {
                     Text = trade.ClosingTime.ToString("g"),
                     Style = _textBlocksStyle
                 }, iRowIndex, 4);
                 _tradesGrid.AddChild(new TextBlock
                 {
                     Text = trade.NetProfit.ToString(),
                     Style = _textBlocksStyle
                 }, iRowIndex, 5);
             }
             _stackPanel.AddChild(_tradesGrid);
         }
     }
 }

See Also


Last update: June 26, 2022

Comments