-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddonShellWindow.xaml.cs
More file actions
216 lines (193 loc) · 7.88 KB
/
AddonShellWindow.xaml.cs
File metadata and controls
216 lines (193 loc) · 7.88 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#region
using NinjaTrader;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Xml.Linq;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Automation;
using System.Xml.Serialization;
using NinjaTrader.Core;
using NinjaTrader.Gui;
using System.Windows.Markup;
using IInstrumentProvider = NinjaTrader.Gui.Tools.IInstrumentProvider;
#endregion
namespace NinjaTrader.NinjaScript.AddOns
{
/// <summary>
/// Interaction logic for xaml
/// </summary>
public partial class AddonShellWindow : NTTabPage
{
#region Variables
TextBoxWriter writer;
private string orderType;
private NinjaTrader.Cbi.Instrument instrument = Instrument.GetInstrument("ES 03-20");
private MarketData marketData;
#endregion
public AddonShellWindow()
{
// the content of the page will go here.
InitializeComponent();
// Set Console output to textbox
writer = new TextBoxWriter(this.output);
Console.SetOut(writer);
Console.SetError(writer);
// Initialize market data
marketData = new MarketData(instrument);
marketData.Update += OnMarketData;
}
// Cleanup() is called when the script is ending, this is to remove used resources or event handlers.
// Called by TabControl when tab is being removed or window is closed
public override void Cleanup()
{
// a call to base.Cleanup() will loop through the visual tree looking for all ICleanable children
// i.e., AccountSelector, AtmStrategySelector, InstrumentSelector, IntervalSelector, TifSelector,
// as well as unregister any link control events
base.Cleanup();
}
// This returns the default Tab Header text.
protected override string GetHeaderPart(string variable)
{
return "Addon Tab";
}
// These are used for when the workspace is Restoring or Saving.
// NTTabPage member. Required for restoring elements from workspace
protected override void Restore(XElement element)
{
if (element == null)
return;
}
// NTTabPage member. Required for storing elements to workspace
protected override void Save(XElement element)
{
if (element == null)
return;
}
private void radioButton_Checked(object sender, RoutedEventArgs e)
{
orderType = (sender as RadioButton).Name;
}
// This method is fired on market data events
private void OnMarketData(object sender, MarketDataEventArgs e)
{
// Do something with market data events
}
private void order_Click(object sender, RoutedEventArgs e)
{
if (instrumentSelector.Instrument == null)
{
Console.WriteLine("Select an Instrument");
return;
}
string Btn = (sender as Button).Name;
Order entryOrder;
OrderAction orderAction = OrderAction.Buy;
OrderType type = OrderType.Market;
double price = 0;
if (Btn == "buy")
{
orderAction = OrderAction.Buy;
}
else if (Btn == "sell")
{
orderAction = OrderAction.Sell;
}
else if (Btn == "close")
{
return;
}
else
{
return;
}
if (orderType == "bid")
{
marketData = new MarketData(instrumentSelector.Instrument);
type = OrderType.Limit;
price = marketData.Bid.Price;
}
else if (orderType == "ask")
{
marketData = new MarketData(instrumentSelector.Instrument);
type = OrderType.Limit;
price = marketData.Ask.Price;
}
else if (orderType == "mkt")
{
type = OrderType.Market;
price = 0;
}
else
{
type = OrderType.Market;
price = 0;
}
entryOrder = accountSelector.SelectedAccount.CreateOrder(
instrumentSelector.Instrument, // Order instrument
orderAction, // Possible values:
// OrderAction.Buy
// OrderAction.BuyToCover
// OrderAction.Sell
// OrderAction.SellShort
type, // Possible values:
// OrderType.Limit
// OrderType.Market
// OrderType.MIT
// OrderType.StopMarket
// OrderType.StopLimit
OrderEntry.Automated, // Possible values:
// OrderEntry.Automated
// OrderEntry.Manual
// Allows setting the tag for orders submitted manually or via automated trading logic
TimeInForce.Day, // Possible values:
// TimeInForce.Day
// TimeInForce.Gtc
// TimeInForce.Gtd
// TimeInForce.Ioc
// TimeInForce.Opg
qudSelector.Value, // Order quantity
0, // Order limit price. Use "0" should this parameter be irrelevant for the OrderType being submitted.
price, // Order stop price.Use "0" should this parameter be irrelevant for the OrderType being submitted.
string.Empty, // A string representing the OCO ID used to link OCO orders together
string.Empty, // A string representing the name of the order. Max 50 characters.
NinjaTrader.Core.Globals.MaxDate,// A DateTime value to be used with TimeInForce.Gtd - for all other cases you can pass in Core.Globals.MaxDate
null // Custom order if it is being used
);
accountSelector.SelectedAccount.Submit(new[] { entryOrder });
Console.WriteLine("Order Type: "+orderType+" Action: "+orderAction+" Price: "+Convert.ToString(price));
}
private void action_Click(object sender, RoutedEventArgs e)
{
string Btn = (sender as Button).Name;
if (Btn=="start")
{
Console.WriteLine("Insert here your addon start actions");
}
if (Btn == "stop")
{
Console.WriteLine("Insert here your addon stop actions");
}
if (Btn == "clearconsole")
{
this.output.Text = "";
}
}
}
}