algooproject / Algo-Project

0 stars 1 forks source link

Implement to observe signal of bull or bear market #33

Open miltonko opened 3 years ago

miltonko commented 3 years ago

Under the situation of Bull or Bear market, this algorithm should pause. It should resume normal when the situation is determined changed.

The algorithm treats any of the following conditions as a signal of bull or bear market within a trading day:

  1. The difference between the current HSI and the HSI exactly 1 hour ago is at least 500 points. Before 10:30am (as the start of the trading hour of SEHK is 9:30am), the HSI exactly 1 hour ago is defined as the last closing HSI. Note that the HSI at 9:30 is the opening HSI. Lunch hour (noon to 13:00 in Hong Kong) is not counted when we trace the HSI exactly 1 hour ago. As an example, when it is 13:20, the HSI exactly 1 hour ago is the HSI at 11:20;
  2. When the difference between the current HSI and the last closing HSI is at least 1000 points.

When the algorithm detects the bull or bear signal, the algorithm stops sending buy orders and cancels open buy orders.

The algorithm then waits for the occurrences of ALL of the following conditions to resume buying:

  1. The algorithm has paused for more than 30 minutes;
  2. The difference between the current HSI and the HSI exactly 1 hour ago is less than 500 points;
  3. The difference between the current HSI and the last closing HSI is less than 500 points.

The determination of bull or bear market is refreshed every day.

The two stop-trading conditions cannot replace each other. On one hand, (2) does not imply (1). Consider the example that the opening HSI is the same as the closing HSI of the last trading day and raises 499 points linearly every hour. (2) is satisfied but not (1). On the other hand, it is trivial that (1) does not imply (2).

Fluctuating market favors our strategy. However, if the HSI goes above 1000 points above the last closing HSI (hence detecting bull and trading is stopped) and then fluctuates with a spread of 500 points, our strategy will not try at all, as it does not resume trading, by not satisfying resume condition (3). This may not be what we intend to do.

miltonko commented 2 years ago
  1. Can the IB algo obtain the HSI as how it does for a stock?
  2. Better to implement the concept of intermission by a config;
  3. The signal class registers call backs of HSI updates, stores info in DB and keeps detecting volatile market;
  4. The IB algo registers call-backs in this signal for pausing trading due to volatile market and for resuming trading.