-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhowtoconfig_app_in_source_code.txt
238 lines (191 loc) · 9.99 KB
/
howtoconfig_app_in_source_code.txt
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
Changes to source code to customize app
---------------------------------------
The source file MarketStatus.cpp contains information about the trading times of markets in UK time.
For other parts of the world change the hours to match the trading hours to your local time.
In the USA change the hours to 9, 30, 16, 00 for example.
void IB_PTraderDlg::InitialiseMarketDetails ()
{
// trade hours in UK time
// change 1 to 0 depending on time zone differences between UK and other markets
#if 1
AddMarketDetails (MarketDetails::US, "USD", 14, 30, 21, 00)->SetOnHoliday (false);
AddMarketDetails (MarketDetails::CAD, "CAD", 14, 30, 21, 00)->SetOnHoliday (false);
#else
AddMarketDetails (MarketDetails::US, "USD", 13, 30, 20, 00)->SetOnHoliday (false);
AddMarketDetails (MarketDetails::CAD, "CAD", 13, 30, 20, 00)->SetOnHoliday (false);
#endif
#if 1
AddMarketDetails (MarketDetails::UK, "GBP", 8, 0, 16, 30)->SetOnHoliday (false);
#else
AddMarketDetails (MarketDetails::UK, "GBP", 8, 0, 16, 30)->SetOnHoliday (true);
#endif
AddMarketDetails (MarketDetails::AUD, "AUD", 24, 0, 6, 0)->SetOnHoliday (false);
}
An instance of the MarketDetails class is created for each stock market - USD, CAD, GBP, AUD. This class stores the opening/closing hours and
the current market status.
The MarketStatus enum has 5 possible values:-
PreMarket - market not open
EarlyOpen - this is an initial period after the market has opened. The length of this period is dictated by the constant
const int EARLY_OPEN_TIME_IN_MINS = 5;
in MarketStatus.cpp. When the market is in this period the app will not buy shares (but can sell them). This
feature exists because sometimes TWS can be slow at accepting orders at market open. This feature can
be turned off for individual shares. Just change this constant and rebuild for a shorter early open period
(or set to 0 if you don't want an early period at all).
Open - period after early open to the close time
AfterHours - market has shut
OnHoliday - market closed
IB provides 2 types of account, Live and Paper (a virtual account for experimentation). Because of this features controlling how the
app behaves is split into 2 source files - Settings_Live.cpp and Settings_Paper.cpp
The following methods control the behaviour of particular shares.
void PaperSettings::InitialiseAllowEarlyBuyTickers () // or LiveSettings::InitialiseAllowEarlyBuyTickers ()
{
#if 0
// Allows app to buy SPY on the NYSE exchange when market status is EarlyOpen
_parent->AddAllowEarlyBuyTicker ("SPY", "NYSE");
#endif
}
void PaperSettings::SetShareDayLimits () // or LiveSettings::SetShareDayLimits ()
{
#if 0
// This limits how much money the app spends in a trading day on a particular share. Without
// this specified the app has no limit
_parent->SetShare_Buy_DayLimit ("IBM", "NYSE", 3000); // $3000 for this share
// You can also limit the amount (in value) a share is sold in a day
_parent->SetShare_Sell_DayLimit ("USU", "NYSE", 5000); // sell up $5000 of this share in a day
#endif
}
void PaperSettings::InitialiseCustomSpreads () // or LiveSettings::InitialiseCustomSpreads ()
{
#if 0
// When buying a share the app checks the bid/offer spread to see if it is too wide. By default
// if the spread is more than 1 cent then no buy order is issued.
_parent->AddCustomSpread ("COPX", "ARCA", 0.1); // allow buy order when the spread is up to 10 cents
#endif
}
void PaperSettings::InitialiseInActiveTickers () // or LiveSettings::InitialiseInActiveTickers ()
{
#if 0
// A share (ticker) has 5 possible states:-
//
// Active - can both buy and sell shares
// InActive - no selling or buying of shares
// SellOnly - only sell shares
// BuyOnly - only buy shares
// DISABLED - same as inactive but no price feed is requested and user cannot change the state in the GUI
//
// The user can change the state of any ticker in the GUI when it's in the first 4 states.
// By default all tickers are Active
_parent->AddInActiveTicker ("AAPL", "NASDAQ.NMS", Ticker::Active);
_parent->AddInActiveTicker ("FB", "NASDAQ.NMS", Ticker::InActive);
_parent->AddInActiveTicker ("AMZN", "NASDAQ.NMS", Ticker::SellOnly);
_parent->AddInActiveTicker ("GOOG", "NASDAQ.NMS", Ticker::BuyOnly);
_parent->AddInActiveTicker ("DELL", "NASDAQ.NMS", Ticker::DISABLED);
#endif
}
void PaperSettings::AddGlobalInActiveTickers () // or LiveSettings::AddGlobalInActiveTickers ()
{
#if 0
std::list <std::string> exceps;
exceps.push_back ("USLV");
exceps.push_back ("DSLV");
// This sets the ticker status for all tickers except the ones in the exceps list
_parent->AddGlobalInActiveTickers (exceps, Ticker::SellOnly);
// Note this method is called after InitialiseInActiveTickers and hence overrides any changes
// made there
#endif
}
void PaperSettings::InitialiseTrends () // or LiveSettings::InitialiseTrends ()
{
#if 0
// Normally when the app detects a bid price in excess of the sell point for a share it issues
// a sell order. When a trend is set it waits for the bid price to change N times before issuing a sell order.
// The aim of this is to try and maximize profit if a share is trending upwards
_parent->AddTickerTrend ("SLW", "NYSE", "USD", 3); // wait 3 times
#endif
}
void PaperSettings::SetBuyBelowAverages () // or LiveSettings::SetBuyBelowAverages ()
{
#if 0
// IB stores an average price for a shareholding. Normally the app will ignore this
// when buying a share. If a ticker is configured to OnlyIfBelow the share is only
// bought if the offer price is less the current share average point.
_parent->SetBuyBelowAverage ("USLV", "NASDAQ.NMS", Ticker::OnlyIfBelow);
_parent->SetBuyBelowAverage ("DSLV", "NASDAQ.NMS", Ticker::Always);
// Can set to only below average for tickers with a particular currency
_parent->SetAllBuyBelowAverage ("USD");
_parent->SetAllBuyBelowAverage ("CAD");
_parent->SetAllBuyBelowAverage ("GBP");
#endif
}
void PaperSettings::InitialiseTickersTA () // or LiveSettings::InitialiseTickersTA ()
{
#if 0
// All these technical indicators are calculated using only the current trading day.
// The app will buy if these TI's are oversold on a particular share
_parent->SetTickersTA ("USU", "NYSE", "STK", TechnicalIndicator::RSI_14); // must < 30 to buy
_parent->SetTickersTA ("USU", "NYSE", "STK", TechnicalIndicator::StochRSI14); // < 0.2 to buy
_parent->SetTickersTA ("USU", "NYSE", "STK", TechnicalIndicator::TSI); // < 0 to buy
_parent->SetTickersTA ("USU", "NYSE", "STK", TechnicalIndicator::Stochs14_3_3); // K and D < 20
_parent->SetTickersTA ("USU", "NYSE", "STK", TechnicalIndicator::Williams_45); // <= -80 to buy
// If no TIs are set for a share then the app just buys
// Note for the TIs to operate for a particular share then LivePrices recording must be set for
// it as specified in the method below
#endif
}
void PaperSettings::InitialiseTickersToRecord () // or LiveSettings::InitialiseTickersToRecord ()
{
#if 0
// All changes of the offer price are recorded
// This is needed to be set so a live chart price for the ticker can be displayed
_parent->AddTickerToRecord ("USU", "ARCA", "STK", Ticker::LivePrices);
// You will note a text file is created in the apps working directory for each share/trading day
// These can be deleted at the end of a trading day or periodically.
#endif
}
void PaperSettings::InitialiseLiquidations () // or LiveSettings::InitialiseLiquidations ()
{
#if 0
// With a 3 day settlement of cash on selling it is important to sell as many shares each day as
// possible. Liquidations (when set) will sell any shares that have not hit their sell points but
// are still in profit if they were sold.
// Sell any bought positions of SLW if in profit at 19:50pm (in UK time)
_parent->InitialiseLiquidation ("SLW", "NYSE", "STK", Ticker::InProfit, 1950);
// The 3 possible values are
//
// InProfit - just shares in profit
// JustLosses - just shares that are in loss (if you like losing money)
// AllBuys - all shares whether in profit or loss
#endif
}
void PaperSettings::InitialiseTickersBuysOnOff () // or LiveSettings::InitialiseTickersBuysOnOff ()
{
#if 0
// Let's say the app has these buy points on a share 5 5.1 5.2 5.3 5.4 5.5 5.6
// The below have the following effect:-
//
// All_On - all buy points are available
// All_Off - no buy points are available - app will never make a buy
// Off_Even - buy points are 5.1 5.3 5.5
// Off_Odd - buy points are 5 5.2 5.4 5.6
// One_In_Three - buy points are 5 5.3 5.6
// One_In_Four - buy points are 5 5.4
// By reducing the buy points the available capital can be spread more widely
_parent->SetTickersBuyOnOff ("UNG", "ARCA", Ticker::Off_Even);
_parent->SetTickersBuyOnOff ("SLW", "NYSE", Ticker::Off_Odd);
#endif
}
void PaperSettings::InitialiseGlobalCurrencyBuys () // or LiveSettings::InitialiseGlobalCurrencyBuys ()
{
#if 0
// This limits the value of the shares the app can buy per day on a currency basis
_parent->GetGlobalCurrencyBuy ("CAD")->_maxallowedbuys = 400; // only ca$400 per day
_parent->GetGlobalCurrencyBuy ("USD")->_maxallowedbuys = 15000; // only $15000 per day
#endif
}
In the method TickerListBox::DrawListBoxLine (in TickerListBox.cpp) there are 2 constants:-
const int START_INDEX = -1;
const int END_INDEX = 1;
These control the number of buy points that are displayed for a ticker on the ticker pane.
For these values 3 buy points are displayed (1 before, the current 1, the 1 after).
Change them to increase the number of buy points displayed. eg changing START_INDEX to -3
would mean 3 before, the current 1, 1 after.