Skip to content

Commit 94fbfe1

Browse files
new version
1 parent e8058ac commit 94fbfe1

2 files changed

Lines changed: 83 additions & 36 deletions

File tree

entry/entry_fibo.py

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,89 @@
1+
"""Module that will try to enter the market using Fibonnacci techniques"""
2+
13
import math_op as mo
24
import initialize as init
35
import operator as op
46
import math
57

68
class EntFibo():
7-
9+
"""
10+
Class that uses Fibonnacci strategies to enter the market """
811

912
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'
1226

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
1330
1431
Trying to enter the market with Fibonacci retracement and extension. 3 types:
1532
Retracement from the last wave
1633
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.
1837
38+
Parameters
39+
----------
40+
`self.buy_signal` and `self.sell_signal` : bool
41+
1942
2043
Notes
2144
-----
2245
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
2447
current price or the next desired price
2548
2649
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()`
2851
Taking into account the system, those are really rare cases. However it could be tested by using a
2952
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+
3085
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'
4586
46-
47-
def ent_fibo(self,curr_row,buy_signal=False,sell_signal=False):
48-
"""
49-
Default function called to determine the entry level
5087
"""
5188

5289
#ENTRY TRACKER
@@ -113,7 +150,6 @@ def ent_fibo(self,curr_row,buy_signal=False,sell_signal=False):
113150
self.set_value()
114151
self.try_entry()
115152

116-
117153
def largest_extension(self):
118154
"""
119155
Find largest extension (setback) from current trend (Fibonacci) in size + largest in time

exit/exit_fibo.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,37 @@ def __call__(self,curr_row,buy_signal=False,sell_signal=False):
2525
""" Method that will first try to enter the market with `self.ent_fibo` then it will try to exit with
2626
`self.try_exit()` whenever we have a position
2727
"""
28+
2829
super().__init__()
2930
self.ent_fibo(curr_row=curr_row, buy_signal=buy_signal, sell_signal=sell_signal)
3031
return self.try_exit()
3132

3233
def try_exit(self):
3334
"""
34-
This is the ethod that tries to exit the market when wr have a position with `entry_fibo.py`
35+
This is the method that tries to exit the market when we have a position with `entry_fibo.py`
36+
37+
We first get an entry confirmation with the function `self.ent_fibo()` in `entry_fibo.py`. Then we run through
38+
the remaining data (according to the determined data range). We have an profit, stop loss and the method
39+
even tighten the stop under certain circumstances.
3540
36-
Then it tries to exit
37-
the market using Fibonacci retracement and extension. 1 type at the moment:
38-
1- Largest extension `self.largest_extension_` from the current trend
41+
Then it tries to exit the market using Fibonacci retracement and extension. 1 type at the moment:
42+
1- Largest extension `self.largest_extension_` from the current trend. The `self.largest_extension_` is set
43+
in `entry_fibo.py`. It is in fact the largest setback in the current trend. This method uses
44+
`self.profit_ext` to calculate the profit level and `self.stop_ext` for the stop level
3945
4046
There is no slippage included in `try_exit()`. If the price reached the desired level, we just exit at
4147
either the current price or the next desired price
4248
43-
44-
45-
This method will make the system exit the market when a close or a stop loss signal is triggered
49+
Parameters
50+
----------
51+
`self.profit_ext` : float
52+
% of the largest extension from previous trend that the system uses to exit the market to take profit
53+
Default value is 2.618. Possible values are 1.618, 2 , 2.618, 3.382, 4.236.
54+
`self.stop_ext` : float
55+
% of the largest extension from previous trend that the system uses as a stop loss.
56+
Default value is 1.618. Possible values are 1, 1.382, 1.618, 2.
57+
`self.is_entry` : bool
58+
The value comes from `entry_fibo.py`. It says if we have a position.
4659
4760
Notes
4861
-----
@@ -51,9 +64,6 @@ def try_exit(self):
5164
The system doesn't check on a shorter time frame if it reaches an exit point and a stop in `try_exit()`
5265
in case of high volatility. Really rare cases
5366
54-
No slippage included in `try_exit()`. If the price reached the desired level, we just exit at either the
55-
current price.
56-
5767
"""
5868

5969
#If no entry signal, exit the function
@@ -80,7 +90,7 @@ def try_exit(self):
8090
_tight_value = self.stop_tight_dict[self.stop_tight_pour][self.tight_value]
8191
_pour_tight = self.stop_tight_dict[self.stop_tight_pour][self.pour_tight]
8292

83-
#Check if the first row (where the signal is trigerred) is already below the stop loss (for buy)
93+
#Check if the first row (where the signal is trigerred) is already below the stop loss (for buy)
8494
# and vice versa for sell signal. If yes, stop loss trigerred
8595
if self.exit_dict[self.exit_name][self.exit_ext_bool] & \
8696
self.six_op(self.series.loc[self.curr_row,self.stop],self.stop_value):
@@ -94,6 +104,7 @@ def try_exit(self):
94104

95105
data_test = len(self.series) - self.curr_row - 1
96106

107+
#This is the part where we run through the data to try to exit the market
97108
for curr_row_ in range(data_test):
98109

99110
self.curr_row += 1

0 commit comments

Comments
 (0)