Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
TSAFunctorsGeo.h
1 
2 /* ===================================================================
3 *
4 * T R A D I N G S Y S T E M A P I ™
5 * Copyright © 1999 - 2014 by Peter Ritter ( TradingSystemAPI.com )
6 * A L L R I G H T S R E S E R V E D
7 *
8 * Consult your license regarding permissions and restrictions.
9 * You may obtain a copy of the License at:
10 * http://www.TradingSystemAPI.com/licenses/LICENSE-TSAPI-3.0.html
11 *
12 * ====================================================================
13 */
14 
15 #ifndef TSA_FUNCTOR_GEO__INCLUDED
16 #define TSA_FUNCTOR_GEO__INCLUDED
17 
18 #include "TSASeriesTemplate.h"
19 #include "TSAString.h"
20 #include "TSAFunctorParent.h"
21 
22 namespace tsa {
23 
24  //namespace functor {
25 
27 
29  class swing_finder : public functor::parent<double>
30  {
31  public:
33  struct point {
35  date_time timestamp;
37  bool is_high;
39  double price;
41  size_t bar;
43  size_t strategy_bar_idx;
45  point(void);
47  point(const variant&);
48  //IU
49  operator variant(void);
51  void operator=(const point& other);
53  void print(std::ostream&)const;
54  };
55  basic_series<point> m_swing_points;
56  private:
57  bool m_swing_value_is_in_percent = false;
58  double m_swing_size_pct;
59  double m_min_swing_size;
60  bool m_swing_info_init = false;
61  size_t m_num_swings_to_track = 100;
62  bool m_first_bar_processed = false;
63  double m_initial_low_price;
64  double m_initial_high_price;
65  bool m_initial_point_found = false;
66  double m_potential_point_price;
67  size_t m_potential_point_bar_id;
68  date_time m_potential_point_timestamp;
69  bool m_potential_point_is_high = false;
70  size_t m_strategy_bar_count = 0;
71 
72  public:
74  swing_finder(void);
76  swing_finder(double swing_size_pct, size_t num_swings_to_track);
78  void num_swings_to_track(size_t);
80  void swing_value_percent(double);
82  void swing_value(double);
84  void init(double swing_size_pct, size_t num_swings_to_track);
86  void min_swing_size(double min_swing_size);
88  void min_swing_size_pct(double min_swing_size_pct);
90  size_t swing_count(void)const;
91  public:
93  swing_finder::point at(size_t);
95  swing_finder::point operator[](size_t);
96  public:
98  void update(double bar_high,
99  double bar_low,
100  size_t strategy_bar_count,
101  const date_time& bar_timestamp
102  );
104  void operator()(double bar_high,
105  double bar_low,
106  size_t strategy_bar_count,
107  const date_time& bar_timestamp
108  );
110  void print_swings(std::ostream& s)const;
111  };
112 
113  std::ostream& operator<<(std::ostream& s, const swing_finder::point&);
114 
115 
117 
118 
119 } // tsa
120 #endif
Namespace for the &#39;Trading System API&#39; library.
Definition: original1.TSA3Core.cpp:20
variant objects can represent values of different types.
Definition: TSAVariant.h:140
Definition: TSAFunctorsGeo.h:33
Class representing a gregorian-date and time-of-day combination. The time component has microsecond r...
Definition: TSATime.h:428
Swing finder.
Definition: TSAFunctorsGeo.h:29