|
| 1 | +"""Module that will try to enter the market using Fibonnacci techniques""" |
| 2 | + |
1 | 3 | import math_op as mo |
2 | 4 | import initialize as init |
3 | 5 | import operator as op |
4 | 6 | import math |
5 | 7 |
|
6 | 8 | class EntFibo(): |
7 | | - |
| 9 | + """ |
| 10 | + Class that uses Fibonnacci strategies to enter the market """ |
8 | 11 |
|
9 | 12 | def __init__(self): |
10 | | - """ |
11 | | - Class that uses Fibonnacci strategy to enter the market |
| 13 | + self.extreme = {} |
| 14 | + self.high="max" |
| 15 | + self.low="min" |
| 16 | + self.high_idx="max_idx" |
| 17 | + self.low_idx = "min_idx" |
| 18 | + self.fst_ext_cdt = False #by default first condition for extension is not met, set to False |
| 19 | + self.is_entry = False |
| 20 | + self.relative_extreme = None #last wave the system uses (relative low for buy, vice versa) as a |
| 21 | + # basis to calculate the profit taking price. It uses the default data (close) |
| 22 | + # to smooth data |
| 23 | + self.row_rel_extreme = 0 |
| 24 | + self.largest_time = 0 #extension in time |
| 25 | + self.index_name = 'index' |
12 | 26 |
|
| 27 | + |
| 28 | + def ent_fibo(self,curr_row,buy_signal=False,sell_signal=False): |
| 29 | + """This the main method that uses Fibonnacci strategies to enter the market |
13 | 30 |
|
14 | 31 | Trying to enter the market with Fibonacci retracement and extension. 3 types: |
15 | 32 | Retracement from the last wave |
16 | 33 | Retracement from beginning of the trend |
17 | | - Extension from a previous wave (largest one in the last trend) |
| 34 | + Extension from the current trend (largest one in the last trend) |
| 35 | +
|
| 36 | + At the moment, it is possible to enter the market only with extensions from the current wave. |
18 | 37 |
|
| 38 | + Parameters |
| 39 | + ---------- |
| 40 | + `self.buy_signal` and `self.sell_signal` : bool |
| 41 | + |
19 | 42 |
|
20 | 43 | Notes |
21 | 44 | ----- |
22 | 45 |
|
23 | | - No slippage included in `try_entry()`. If the price reached the desired level, we just exit at either the |
| 46 | + No slippage included in `self.try_entry()`. If the price reached the desired level, we just exit at either the |
24 | 47 | current price or the next desired price |
25 | 48 |
|
26 | 49 | The system doesn't check on a shorter time frame if it reaches an entry point and a stop at the same time |
27 | | - or even an exit point and stop at the same time (in case of high volatility) in `try_entry()` |
| 50 | + or even an exit point and stop at the same time (in case of high volatility) in `self.try_entry()` |
28 | 51 | Taking into account the system, those are really rare cases. However it could be tested by using a |
29 | 52 | shorter time every time an entry or exit signal |
| 53 | + We first get an entry confirmation with the function `self.ent_fibo()` in `entry_fibo.py`. Then we run through |
| 54 | + the remaining data (according to the determined data range). We have an profit, stop loss and the method |
| 55 | + even tighten the stop under certain circumstances. |
| 56 | +
|
| 57 | +
|
| 58 | + Then it tries to exit the market using Fibonacci retracement and extension. 1 type at the moment: |
| 59 | + 1- Largest extension `self.largest_extension_` from the current trend. The `self.largest_extension_` is set |
| 60 | + in `entry_fibo.py`. It is in fact the largest setback in the current trend. This method uses |
| 61 | + `self.profit_ext` to calculate the profit level and `self.stop_ext` for the stop level |
| 62 | +
|
| 63 | + There is no slippage included in `try_exit()`. If the price reached the desired level, we just exit at |
| 64 | + either the current price or the next desired price |
| 65 | +
|
| 66 | + Parameters |
| 67 | + ---------- |
| 68 | + `self.profit_ext` : float |
| 69 | + % of the largest extension from previous trend that the system uses to exit the market to take profit |
| 70 | + Default value is 2.618. Possible values are 1.618, 2 , 2.618, 3.382, 4.236. |
| 71 | + `self.stop_ext` : float |
| 72 | + % of the largest extension from previous trend that the system uses as a stop loss. |
| 73 | + Default value is 1.618. Possible values are 1, 1.382, 1.618, 2. |
| 74 | + `self.is_entry` : bool |
| 75 | + The value comes from `entry_fibo.py`. It says if we have a position. |
| 76 | +
|
| 77 | + Notes |
| 78 | + ----- |
| 79 | + The stops may be tightened (see "stop tightening" in `initialize.py`) |
| 80 | +
|
| 81 | + The system doesn't check on a shorter time frame if it reaches an exit point and a stop in `try_exit()` |
| 82 | + in case of high volatility. Really rare cases |
| 83 | +
|
| 84 | +
|
30 | 85 |
|
31 | | - """ |
32 | | - self.extreme = {} |
33 | | - self.high="max" |
34 | | - self.low="min" |
35 | | - self.high_idx="max_idx" |
36 | | - self.low_idx = "min_idx" |
37 | | - self.fst_ext_cdt = False #by default first condition for extension is not met, set to False |
38 | | - self.is_entry = False |
39 | | - self.relative_extreme = None #last wave the system uses (relative low for buy, vice versa) as a |
40 | | - # basis to calculate the profit taking price. It uses the default data (close) |
41 | | - # to smooth data |
42 | | - self.row_rel_extreme = 0 |
43 | | - self.largest_time = 0 #extension in time |
44 | | - self.index_name = 'index' |
45 | 86 |
|
46 | | - |
47 | | - def ent_fibo(self,curr_row,buy_signal=False,sell_signal=False): |
48 | | - """ |
49 | | - Default function called to determine the entry level |
50 | 87 | """ |
51 | 88 |
|
52 | 89 | #ENTRY TRACKER |
@@ -113,7 +150,6 @@ def ent_fibo(self,curr_row,buy_signal=False,sell_signal=False): |
113 | 150 | self.set_value() |
114 | 151 | self.try_entry() |
115 | 152 |
|
116 | | - |
117 | 153 | def largest_extension(self): |
118 | 154 | """ |
119 | 155 | Find largest extension (setback) from current trend (Fibonacci) in size + largest in time |
|
0 commit comments