forked from sofienkaabar/the-book-of-trading-strategies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ad5ce2
commit 442ef6f
Showing
13 changed files
with
854 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
# Base parameters | ||
expected_cost = 0.0 * (lot / 100000) | ||
assets = asset_list(1) | ||
window = 1000 | ||
|
||
# Trading parameters | ||
horizon = 'H1' | ||
|
||
# Indicator / Strategy parameters | ||
lookback = 8 | ||
ma_lookback = 3 | ||
cross_ma_lookback = 13 | ||
upper_barrier = 10 | ||
lower_barrier = -10 | ||
|
||
# Mass imports | ||
my_data = mass_import(0, horizon) | ||
|
||
def signal(Data, rsi_col, ma_col, buy, sell): | ||
|
||
Data = adder(Data, 10) | ||
Data = rounding(Data, 5) | ||
|
||
for i in range(len(Data)): | ||
|
||
if Data[i, rsi_col] > Data[i, ma_col] and Data[i - 1, rsi_col] < Data[i - 1, ma_col]: | ||
|
||
Data[i, buy] = 1 | ||
|
||
elif Data[i, rsi_col] < Data[i, ma_col] and Data[i - 1, rsi_col] > Data[i - 1, ma_col]: | ||
|
||
Data[i, sell] = -1 | ||
return Data | ||
|
||
############################################################################## 1 | ||
|
||
my_data = countdown_indicator(my_data, lookback, ma_lookback, 0, 1, 2, 3, 4) | ||
my_data = ma(my_data, cross_ma_lookback, 4, 5) | ||
my_data = signal(my_data, 4, 5, 6, 7) | ||
|
||
holding(my_data, 6, 7, 8, 9) | ||
my_data_eq = equity_curve(my_data, 8, expected_cost, lot, investment) | ||
performance(my_data_eq, 8, my_data, assets[0]) | ||
|
||
if sigchart == True: | ||
signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 500) | ||
indicator_plot_double(my_data, 0, 1, 2, 3, 4, window = 250) | ||
plt.axhline(y = upper_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
plt.axhline(y = lower_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
|
||
plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) | ||
plt.grid() | ||
plt.legend() | ||
plt.axhline(y = investment, color = 'black', linewidth = 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
# Base parameters | ||
expected_cost = 0.0 * (lot / 100000) | ||
assets = asset_list(1) | ||
window = 1000 | ||
|
||
# Trading parameters | ||
horizon = 'H1' | ||
|
||
# Indicator / Strategy parameters | ||
lookback = 8 | ||
ma_lookback = 3 | ||
upper_barrier = 10 | ||
lower_barrier = -10 | ||
|
||
# Mass imports | ||
my_data = mass_import(0, horizon) | ||
|
||
def signal(Data, what, buy, sell): | ||
|
||
Data = adder(Data, 10) | ||
Data = rounding(Data, 5) | ||
|
||
for i in range(len(Data)): | ||
|
||
if Data[i, what] <= lower_barrier and Data[i - 1, buy] == 0 and \ | ||
Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0 and Data[i - 4, buy] == 0: | ||
Data[i, buy] = 1 | ||
|
||
elif Data[i, what] >= upper_barrier and Data[i - 1, sell] == 0 and \ | ||
Data[i - 2, sell] == 0 and Data[i - 3, sell] == 0 and Data[i - 4, sell] == 0: | ||
Data[i, sell] = -1 | ||
|
||
return Data | ||
|
||
############################################################################## 1 | ||
|
||
my_data = countdown_indicator(my_data, lookback, ma_lookback, 0, 1, 2, 3, 4) | ||
my_data = signal(my_data, 4, 6, 7) | ||
|
||
holding(my_data, 6, 7, 8, 9) | ||
my_data_eq = equity_curve(my_data, 8, expected_cost, lot, investment) | ||
performance(my_data_eq, 8, my_data, assets[0]) | ||
|
||
if sigchart == True: | ||
signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 500) | ||
indicator_plot_double(my_data, 0, 1, 2, 3, 4, window = 250) | ||
plt.axhline(y = upper_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
plt.axhline(y = lower_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
|
||
plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) | ||
plt.grid() | ||
plt.legend() | ||
plt.axhline(y = investment, color = 'black', linewidth = 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
# Base parameters | ||
expected_cost = 0.0 * (lot / 100000) | ||
assets = asset_list(1) | ||
window = 1000 | ||
|
||
# Trading parameters | ||
horizon = 'H1' | ||
|
||
# Indicator / Strategy parameters | ||
lookback = 14 | ||
upper_barrier = 0.70 | ||
lower_barrier = 0.30 | ||
|
||
# Mass imports | ||
my_data = mass_import(0, horizon) | ||
|
||
def signal(Data, rsi_col, ma_col, buy, sell): | ||
|
||
Data = adder(Data, 10) | ||
Data = rounding(Data, 5) | ||
|
||
for i in range(len(Data)): | ||
|
||
if Data[i, rsi_col] > Data[i, ma_col] and Data[i - 1, rsi_col] < Data[i - 1, ma_col]: | ||
|
||
Data[i, buy] = 1 | ||
|
||
elif Data[i, rsi_col] < Data[i, ma_col] and Data[i - 1, rsi_col] > Data[i - 1, ma_col]: | ||
|
||
Data[i, sell] = -1 | ||
return Data | ||
|
||
|
||
############################################################################## 1 | ||
|
||
my_data = demarker(my_data, lookback, 1, 2, 4) | ||
my_data = ma(my_data, ma_lookback, 4, 5) | ||
my_data = signal(my_data, 4, 5, 6, 7) | ||
|
||
holding(my_data, 6, 7, 8, 9) | ||
my_data_eq = equity_curve(my_data, 8, expected_cost, lot, investment) | ||
performance(my_data_eq, 8, my_data, assets[0]) | ||
|
||
if sigchart == True: | ||
signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 500) | ||
indicator_plot_double(my_data, 0, 1, 2, 3, 4, window = 250) | ||
plt.axhline(y = upper_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
plt.axhline(y = lower_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
|
||
plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) | ||
plt.grid() | ||
plt.legend() | ||
plt.axhline(y = investment, color = 'black', linewidth = 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
# Base parameters | ||
expected_cost = 0.0 * (lot / 100000) | ||
assets = asset_list(1) | ||
window = 1000 | ||
|
||
# Trading parameters | ||
horizon = 'H1' | ||
|
||
# Indicator / Strategy parameters | ||
lookback = 14 | ||
upper_barrier = 0.70 | ||
lower_barrier = 0.30 | ||
|
||
# Mass imports | ||
my_data = mass_import(0, horizon) | ||
|
||
def divergence(Data, indicator, lower_barrier, upper_barrier, width, buy, sell): | ||
|
||
Data = adder(Data, 10) | ||
|
||
for i in range(len(Data)): | ||
|
||
try: | ||
if Data[i, indicator] < lower_barrier: | ||
|
||
for a in range(i + 1, i + width): | ||
|
||
# First trough | ||
if Data[a, indicator] > lower_barrier: | ||
|
||
for r in range(a + 1, a + width): | ||
|
||
if Data[r, indicator] < lower_barrier and \ | ||
Data[r, indicator] > Data[i, indicator] and Data[r, 3] < Data[i, 3]: | ||
|
||
for s in range(r + 1, r + width): | ||
|
||
# Second trough | ||
if Data[s, indicator] > lower_barrier: | ||
Data[s, buy] = 1 | ||
break | ||
|
||
else: | ||
break | ||
else: | ||
break | ||
else: | ||
break | ||
else: | ||
break | ||
|
||
except IndexError: | ||
pass | ||
|
||
for i in range(len(Data)): | ||
|
||
try: | ||
if Data[i, indicator] > upper_barrier: | ||
|
||
for a in range(i + 1, i + width): | ||
|
||
# First trough | ||
if Data[a, indicator] < upper_barrier: | ||
for r in range(a + 1, a + width): | ||
if Data[r, indicator] > upper_barrier and \ | ||
Data[r, indicator] < Data[i, indicator] and Data[r, 3] > Data[i, 3]: | ||
for s in range(r + 1, r + width): | ||
|
||
# Second trough | ||
if Data[s, indicator] < upper_barrier: | ||
Data[s, sell] = -1 | ||
break | ||
else: | ||
break | ||
else: | ||
break | ||
else: | ||
break | ||
else: | ||
break | ||
except IndexError: | ||
pass | ||
return Data | ||
|
||
|
||
############################################################################## 1 | ||
|
||
my_data = demarker(my_data, lookback, 1, 2, 4) | ||
my_data = divergence(my_data, 4, lower_barrier, upper_barrier, width, 6, 7) | ||
|
||
holding(my_data, 6, 7, 8, 9) | ||
my_data_eq = equity_curve(my_data, 8, expected_cost, lot, investment) | ||
performance(my_data_eq, 8, my_data, assets[0]) | ||
|
||
if sigchart == True: | ||
signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 500) | ||
indicator_plot_double(my_data, 0, 1, 2, 3, 4, window = 250) | ||
plt.axhline(y = upper_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
plt.axhline(y = lower_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
|
||
plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) | ||
plt.grid() | ||
plt.legend() | ||
plt.axhline(y = investment, color = 'black', linewidth = 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
# Base parameters | ||
expected_cost = 0.0 * (lot / 100000) | ||
assets = asset_list(1) | ||
window = 1000 | ||
|
||
# Trading parameters | ||
horizon = 'H1' | ||
|
||
# Indicator / Strategy parameters | ||
lookback = 14 | ||
upper_barrier = 0.70 | ||
lower_barrier = 0.30 | ||
|
||
# Mass imports | ||
my_data = mass_import(0, horizon) | ||
|
||
def signal(Data, what, buy, sell): | ||
|
||
Data = adder(Data, 10) | ||
Data = rounding(Data, 5) | ||
|
||
for i in range(len(Data)): | ||
|
||
if Data[i, what] <= lower_barrier and Data[i - 1, buy] == 0 and \ | ||
Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0 and Data[i - 4, buy] == 0: | ||
Data[i, buy] = 1 | ||
|
||
elif Data[i, what] >= upper_barrier and Data[i - 1, sell] == 0 and \ | ||
Data[i - 2, sell] == 0 and Data[i - 3, sell] == 0 and Data[i - 4, sell] == 0: | ||
Data[i, sell] = -1 | ||
|
||
return Data | ||
|
||
############################################################################## 1 | ||
|
||
my_data = demarker(my_data, lookback, 1, 2, 4) | ||
my_data = signal(my_data, 4, 6, 7) | ||
|
||
holding(my_data, 6, 7, 8, 9) | ||
my_data_eq = equity_curve(my_data, 8, expected_cost, lot, investment) | ||
performance(my_data_eq, 8, my_data, assets[0]) | ||
|
||
if sigchart == True: | ||
signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 500) | ||
indicator_plot_double(my_data, 0, 1, 2, 3, 4, window = 250) | ||
plt.axhline(y = upper_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
plt.axhline(y = lower_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
|
||
plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) | ||
plt.grid() | ||
plt.legend() | ||
plt.axhline(y = investment, color = 'black', linewidth = 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
# Base parameters | ||
expected_cost = 0.0 * (lot / 100000) | ||
assets = asset_list(1) | ||
window = 1000 | ||
|
||
# Trading parameters | ||
horizon = 'H1' | ||
|
||
# Indicator / Strategy parameters | ||
lookback = 14 | ||
upper_barrier = 2 | ||
lower_barrier = -2 | ||
|
||
# Mass imports | ||
my_data = mass_import(0, horizon) | ||
|
||
def signal(Data, what, buy, sell): | ||
|
||
Data = adder(Data, 10) | ||
Data = rounding(Data, 5) | ||
|
||
for i in range(len(Data)): | ||
|
||
if Data[i, what] <= lower_barrier and Data[i - 1, buy] == 0 and \ | ||
Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0 and Data[i - 4, buy] == 0: | ||
Data[i, buy] = 1 | ||
|
||
elif Data[i, what] >= upper_barrier and Data[i - 1, sell] == 0 and \ | ||
Data[i - 2, sell] == 0 and Data[i - 3, sell] == 0 and Data[i - 4, sell] == 0: | ||
Data[i, sell] = -1 | ||
|
||
return Data | ||
|
||
############################################################################## 1 | ||
|
||
my_data = fisher_transform(my_data, lookback, 3, 4) | ||
my_data = signal(my_data, 4, 6, 7) | ||
|
||
holding(my_data, 6, 7, 8, 9) | ||
my_data_eq = equity_curve(my_data, 8, expected_cost, lot, investment) | ||
performance(my_data_eq, 8, my_data, assets[0]) | ||
|
||
if sigchart == True: | ||
signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 500) | ||
indicator_plot_double(my_data, 0, 1, 2, 3, 4, window = 250) | ||
plt.axhline(y = upper_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
plt.axhline(y = lower_barrier, color = 'black', linewidth = 1, linestyle = '--') | ||
|
||
plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) | ||
plt.grid() | ||
plt.legend() | ||
plt.axhline(y = investment, color = 'black', linewidth = 1) |
Oops, something went wrong.