@@ -46,6 +46,9 @@ def __init__(self, price_data_frame: StockFrame) -> None:
46
46
self ._current_indicators = {}
47
47
self ._indicator_signals = {}
48
48
self ._frame = self ._stock_frame .frame
49
+
50
+ self ._indicators_comp_key = []
51
+ self ._indicators_key = []
49
52
50
53
if self .is_multi_index :
51
54
True
@@ -66,11 +69,10 @@ def get_indicator_signal(self, indicator: Optional[str]= None) -> Dict:
66
69
return self ._indicator_signals [indicator ]
67
70
else :
68
71
return self ._indicator_signals
69
-
70
72
71
73
def set_indicator_signal (self , indicator : str , buy : float , sell : float , condition_buy : Any , condition_sell : Any ,
72
- buy_max : float = None , sell_max : float = None , condition_buy_max : Any = None , condition_sell_max : Any = None ) -> None :
73
- """Return the raw Pandas Dataframe Object .
74
+ buy_max : float = None , sell_max : float = None , condition_buy_max : Any = None , condition_sell_max : Any = None ) -> None :
75
+ """Used to set an indicator where one indicator crosses above or below a certain numerical threshold .
74
76
75
77
Arguments:
76
78
----
@@ -102,7 +104,8 @@ def set_indicator_signal(self, indicator: str, buy: float, sell: float, conditio
102
104
# Add the key if it doesn't exist.
103
105
if indicator not in self ._indicator_signals :
104
106
self ._indicator_signals [indicator ] = {}
105
-
107
+ self ._indicators_key .append (indicator )
108
+
106
109
# Add the signals.
107
110
self ._indicator_signals [indicator ]['buy' ] = buy
108
111
self ._indicator_signals [indicator ]['sell' ] = sell
@@ -115,6 +118,52 @@ def set_indicator_signal(self, indicator: str, buy: float, sell: float, conditio
115
118
self ._indicator_signals [indicator ]['buy_operator_max' ] = condition_buy_max
116
119
self ._indicator_signals [indicator ]['sell_operator_max' ] = condition_sell_max
117
120
121
+ def set_indicator_signal_compare (self , indicator_1 : str , indicator_2 : str , condition_buy : Any , condition_sell : Any ) -> None :
122
+ """Used to set an indicator where one indicator is compared to another indicator.
123
+
124
+ Overview:
125
+ ----
126
+ Some trading strategies depend on comparing one indicator to another indicator.
127
+ For example, the Simple Moving Average crossing above or below the Exponential
128
+ Moving Average. This will be used to help build those strategies that depend
129
+ on this type of structure.
130
+
131
+ Arguments:
132
+ ----
133
+ indicator_1 {str} -- The first indicator key, for example `ema` or `sma`.
134
+
135
+ indicator_2 {str} -- The second indicator key, this is the indicator we will compare to. For example,
136
+ is the `sma` greater than the `ema`.
137
+
138
+ condition_buy {str} -- The operator which is used to evaluate the `buy` condition. For example, `">"` would
139
+ represent greater than or from the `operator` module it would represent `operator.gt`.
140
+
141
+ condition_sell {str} -- The operator which is used to evaluate the `sell` condition. For example, `">"` would
142
+ represent greater than or from the `operator` module it would represent `operator.gt`.
143
+ """
144
+
145
+ # Define the key.
146
+ key = "{ind_1}_comp_{ind_2}" .format (
147
+ ind_1 = indicator_1 ,
148
+ ind_2 = indicator_2
149
+ )
150
+
151
+ # Add the key if it doesn't exist.
152
+ if key not in self ._indicator_signals :
153
+ self ._indicator_signals [key ] = {}
154
+ self ._indicators_comp_key .append (key )
155
+
156
+ # Grab the dictionary.
157
+ indicator_dict = self ._indicator_signals [key ]
158
+
159
+ # Add the signals.
160
+ indicator_dict ['type' ] = 'comparison'
161
+ indicator_dict ['indicator_1' ] = indicator_1
162
+ indicator_dict ['indicator_2' ] = indicator_2
163
+ indicator_dict ['buy_operator' ] = condition_buy
164
+ indicator_dict ['sell_operator' ] = condition_sell
165
+
166
+
118
167
@property
119
168
def price_data_frame (self ) -> pd .DataFrame :
120
169
"""Return the raw Pandas Dataframe Object.
@@ -1010,6 +1059,9 @@ def refresh(self):
1010
1059
1011
1060
# Update the function.
1012
1061
indicator_function (** indicator_argument )
1062
+
1063
+ def grab_comparison_indicator (self ) -> dict :
1064
+ pass
1013
1065
1014
1066
def check_signals (self ) -> Union [pd .DataFrame , None ]:
1015
1067
"""Checks to see if any signals have been generated.
@@ -1020,7 +1072,11 @@ def check_signals(self) -> Union[pd.DataFrame, None]:
1020
1072
is returned otherwise nothing is returned.
1021
1073
"""
1022
1074
1023
- signals_df = self ._stock_frame ._check_signals (indicators = self ._indicator_signals )
1075
+ signals_df = self ._stock_frame ._check_signals (
1076
+ indicators = self ._indicator_signals ,
1077
+ indciators_comp_key = self ._indicators_comp_key ,
1078
+ indicators_key = self ._indicators_key
1079
+ )
1024
1080
1025
1081
return signals_df
1026
1082
0 commit comments