diff --git a/Bottle.py b/Bottle.py new file mode 100644 index 0000000..6e4fe79 --- /dev/null +++ b/Bottle.py @@ -0,0 +1,39 @@ + +# Base parameters +expected_cost = 0.5 * (lot / 10000) +assets = asset_list(1) +window = 1000 + +# Trading parameters +horizon = 'H1' + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data): + for i in range(len(Data)): + # Bullish Bottle + if Data[i, 3] > Data[i, 0] and Data[i, 0] == Data[i, 2]: + Data[i, 6] = 1 + # Bearish Bottle + if Data[i, 3] < Data[i, 0] and Data[i, 0] == Data[i, 1]: + Data[i, 7] = -1 + + +############################################################################## 1 + +my_data = adder(my_data, 10) +my_data = rounding(my_data, 4) +signal(my_data) + +if sigchart == True: + signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 250) + +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]) + +plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) +plt.grid() +plt.legend() +plt.axhline(y = investment, color = 'black', linewidth = 1) \ No newline at end of file diff --git a/Contrarian_Countdown_Duration.py b/Contrarian_Countdown_Duration.py new file mode 100644 index 0000000..839f62c --- /dev/null +++ b/Contrarian_Countdown_Duration.py @@ -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 +cross_ma_lookback = 13 +upper_barrier = 5 +lower_barrier = -5 + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data, extreme, buy, sell): + + Data = adder(Data, 10) + + for i in range(len(Data)): + + if Data[i, extreme] <= -5 and Data[i - 1, buy] == 0 and Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0: + Data[i, buy] = 1 + + elif Data[i, extreme] >= 5 and Data[i - 1, sell] == 0 and Data[i - 2, sell] == 0 and Data[i - 3, 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 = extreme_duration(my_data, 4, upper_barrier, lower_barrier, 7, 6, 8) +my_data = deleter(my_data, 5, 1) +my_data = signal(my_data, 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, 5, window = 250) + plt.axhline(y = 5, color = 'black', linewidth = 1, linestyle = '--') + plt.axhline(y = -5, 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) \ No newline at end of file diff --git a/Contrarian_Demarker_Duration.py b/Contrarian_Demarker_Duration.py new file mode 100644 index 0000000..0709bf7 --- /dev/null +++ b/Contrarian_Demarker_Duration.py @@ -0,0 +1,52 @@ + +# 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.7 +lower_barrier = 0.3 + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data, extreme, buy, sell): + + Data = adder(Data, 10) + + for i in range(len(Data)): + + if Data[i, extreme] <= -5 and Data[i - 1, buy] == 0 and Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0: + Data[i, buy] = 1 + + elif Data[i, extreme] >= 5 and Data[i - 1, sell] == 0 and Data[i - 2, sell] == 0 and Data[i - 3, sell] == 0: + Data[i, sell] = -1 + + return Data + +############################################################################## 1 + +my_data = demarker(my_data, lookback, 1, 2, 4) +my_data = extreme_duration(my_data, 4, upper_barrier, lower_barrier, 7, 6, 8) +my_data = deleter(my_data, 5, 1) +my_data = signal(my_data, 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, 5, window = 250) + plt.axhline(y = 5, color = 'black', linewidth = 1, linestyle = '--') + plt.axhline(y = -5, 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) \ No newline at end of file diff --git a/Contrarian_Disparity_Index_Extremes.py b/Contrarian_Disparity_Index_Extremes.py new file mode 100644 index 0000000..12b16ff --- /dev/null +++ b/Contrarian_Disparity_Index_Extremes.py @@ -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.2 +lower_barrier = -0.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 = disparity_index(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) \ No newline at end of file diff --git a/Contrarian_Fisher_Duration.py b/Contrarian_Fisher_Duration.py new file mode 100644 index 0000000..292a428 --- /dev/null +++ b/Contrarian_Fisher_Duration.py @@ -0,0 +1,52 @@ + +# 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 = 1.0 +lower_barrier = -1.0 + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data, extreme, buy, sell): + + Data = adder(Data, 10) + + for i in range(len(Data)): + + if Data[i, extreme] <= -5 and Data[i - 1, buy] == 0 and Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0: + Data[i, buy] = 1 + + elif Data[i, extreme] >= 5 and Data[i - 1, sell] == 0 and Data[i - 2, sell] == 0 and Data[i - 3, sell] == 0: + Data[i, sell] = -1 + + return Data + +############################################################################## 1 + +my_data = fisher_transform(my_data, lookback, 3, 4) +my_data = extreme_duration(my_data, 4, upper_barrier, lower_barrier, 7, 6, 8) +my_data = deleter(my_data, 5, 1) +my_data = signal(my_data, 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, 5, window = 250) + plt.axhline(y = 5, color = 'black', linewidth = 1, linestyle = '--') + plt.axhline(y = -5, 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) \ No newline at end of file diff --git a/Contrarian_RSI_Duration.py b/Contrarian_RSI_Duration.py new file mode 100644 index 0000000..d9c9277 --- /dev/null +++ b/Contrarian_RSI_Duration.py @@ -0,0 +1,52 @@ + +# 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 = 70 +lower_barrier = 30 + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data, extreme, buy, sell): + + Data = adder(Data, 10) + + for i in range(len(Data)): + + if Data[i, extreme] <= -5 and Data[i - 1, buy] == 0 and Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0: + Data[i, buy] = 1 + + elif Data[i, extreme] >= 5 and Data[i - 1, sell] == 0 and Data[i - 2, sell] == 0 and Data[i - 3, sell] == 0: + Data[i, sell] = -1 + + return Data + +############################################################################## 1 + +my_data = rsi(my_data, lookback, 3, 4, genre = 'Smoothed') +my_data = extreme_duration(my_data, 4, upper_barrier, lower_barrier, 7, 6, 8) +my_data = deleter(my_data, 5, 1) +my_data = signal(my_data, 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, 5, window = 250) + plt.axhline(y = 5, color = 'black', linewidth = 1, linestyle = '--') + plt.axhline(y = -5, 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) \ No newline at end of file diff --git a/Contrarian_Real_Range_Extremes.py b/Contrarian_Real_Range_Extremes.py new file mode 100644 index 0000000..a30423d --- /dev/null +++ b/Contrarian_Real_Range_Extremes.py @@ -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 = 1 +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 = rri(my_data, lookback, 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) \ No newline at end of file diff --git a/Contrarian_Stochastic_Duration.py b/Contrarian_Stochastic_Duration.py new file mode 100644 index 0000000..d8d6e75 --- /dev/null +++ b/Contrarian_Stochastic_Duration.py @@ -0,0 +1,52 @@ + +# 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 = 80 +lower_barrier = 20 + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data, extreme, buy, sell): + + Data = adder(Data, 10) + + for i in range(len(Data)): + + if Data[i, extreme] <= -5 and Data[i - 1, buy] == 0 and Data[i - 2, buy] == 0 and Data[i - 3, buy] == 0: + Data[i, buy] = 1 + + elif Data[i, extreme] >= 5 and Data[i - 1, sell] == 0 and Data[i - 2, sell] == 0 and Data[i - 3, sell] == 0: + Data[i, sell] = -1 + + return Data + +############################################################################## 1 + +my_data = stochastic(my_data, lookback, 3, 4, genre = 'High-Low') +my_data = extreme_duration(my_data, 4, upper_barrier, lower_barrier, 7, 6, 8) +my_data = deleter(my_data, 5, 1) +my_data = signal(my_data, 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, 5, window = 250) + plt.axhline(y = 5, color = 'black', linewidth = 1, linestyle = '--') + plt.axhline(y = -5, 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) \ No newline at end of file diff --git a/Doji.py b/Doji.py new file mode 100644 index 0000000..758d1b5 --- /dev/null +++ b/Doji.py @@ -0,0 +1,45 @@ + +# Base parameters +expected_cost = 0.5 * (lot / 10000) +assets = asset_list(1) +window = 1000 + +# Trading parameters +horizon = 'H1' + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data): + + for i in range(len(Data)): + + # Bullish Doji + if Data[i, 3] == Data[i, 0] and Data[i, 3] < Data[i - 1, 3] and \ + Data[i, 3] < Data[i - 2, 3]: + + Data[i, 6] = 1 + + # Bearish Doji + if Data[i, 3] == Data[i, 0] and Data[i, 3] > Data[i - 1, 3] and \ + Data[i, 3] > Data[i - 2, 3]: + + Data[i, 7] = -1 + +############################################################################## 1 + +my_data = adder(my_data, 10) +my_data = rounding(my_data, 4) +signal(my_data) + +if sigchart == True: + signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 250) + +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]) + +plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) +plt.grid() +plt.legend() +plt.axhline(y = investment, color = 'black', linewidth = 1) \ No newline at end of file diff --git a/Harami.py b/Harami.py new file mode 100644 index 0000000..1d424cd --- /dev/null +++ b/Harami.py @@ -0,0 +1,39 @@ + +# Base parameters +expected_cost = 0.5 * (lot / 10000) +assets = asset_list(1) +window = 1000 + +# Trading parameters +horizon = 'H1' + +# Mass imports +my_data = mass_import(0, horizon) + +def signal(Data): + for i in range(len(Data)): + # Bullish Harami + if Data[i, 1] < Data[i - 1, 1] and Data[i, 2] > Data[i - 1, 2] and Data[i, 3] < Data[i - 1, 0] and Data[i, 0] > Data[i - 1, 3] and Data[i, 3] > Data[i, 0] and Data[i - 1, 3] < Data[i - 1, 0]: + Data[i, 6] = 1 + # Bearish Harami + if Data[i, 1] < Data[i - 1, 1] and Data[i, 2] > Data[i - 1, 2] and Data[i, 3] > Data[i - 1, 0] and Data[i, 0] < Data[i - 1, 3] and Data[i, 3] < Data[i, 0] and Data[i - 1, 3] > Data[i - 1, 0]: + Data[i, 7] = -1 + + +############################################################################## 1 + +my_data = adder(my_data, 10) +my_data = rounding(my_data, 4) +signal(my_data) + +if sigchart == True: + signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 250) + +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]) + +plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) +plt.grid() +plt.legend() +plt.axhline(y = investment, color = 'black', linewidth = 1) \ No newline at end of file diff --git a/Morning_Evening_Star.py b/Morning_Evening_Star.py new file mode 100644 index 0000000..ff8b342 --- /dev/null +++ b/Morning_Evening_Star.py @@ -0,0 +1,45 @@ + +# Base parameters +expected_cost = 0.5 * (lot / 10000) +assets = asset_list(1) +window = 1000 + +# Trading parameters +horizon = 'H1' + +# Mass imports +my_data = mass_import(0, horizon) + +# Defining the minimum width of the first and third candles +side_body = 0.0010 + +# Defining the maximum width of the second candle +middle_body = 0.0003 + +# Signal function +def signal(Data): + for i in range(len(Data)): + # Morning Star + if Data[i - 2, 3] < Data[i - 2, 0] and (Data[i - 2, 0] - Data[i - 2, 3]) > side_body and (abs(Data[i - 1, 3] - Data[i - 1, 0])) <= middle_body and Data[i, 3] > Data[i, 0] and abs(Data[i, 3] - Data[i, 0]) > side_body: + Data[i, 6] = 1 + # Evening Star + if Data[i - 2, 3] > Data[i - 2, 0] and (Data[i - 2, 3] - Data[i - 2, 0]) > side_body and (abs(Data[i - 1, 3] - Data[i - 1, 0])) <= middle_body and Data[i, 3] < Data[i, 0] and abs(Data[i, 3] - Data[i, 0]) > side_body: + Data[i, 7] = -1 + +############################################################################## 1 + +my_data = adder(my_data, 10) +my_data = rounding(my_data, 4) +signal(my_data) + +if sigchart == True: + signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 500) + +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]) + +plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) +plt.grid() +plt.legend() +plt.axhline(y = investment, color = 'black', linewidth = 1) \ No newline at end of file diff --git a/Three_Soldiers_Crows.py b/Three_Soldiers_Crows.py new file mode 100644 index 0000000..5d51b59 --- /dev/null +++ b/Three_Soldiers_Crows.py @@ -0,0 +1,41 @@ + +# Base parameters +expected_cost = 0.5 * (lot / 10000) +assets = asset_list(1) +window = 1000 + +# Trading parameters +horizon = 'H1' + +# Mass imports +my_data = mass_import(0, horizon) + +# Defining the minimum width of the candle +body = 0.0005 +def signal(Data, body): + for i in range(len(Data)): + # Three White Soldiers + if Data[i, 3] > Data[i, 0] and (Data[i, 3] - Data[i, 0]) >= body and Data[i, 3] > Data[i - 1, 3] and Data[i - 1, 3] > Data[i - 1, 0] and (Data[i - 1, 3] - Data[i - 1, 0]) >= body and Data[i - 1, 3] > Data[i - 2, 3] and Data[i - 2, 3] > Data[i - 2, 0] and (Data[i - 2, 3] - Data[i - 2, 0]) >= body and Data[i - 2, 3] > Data[i - 3, 3]: + Data[i, 6] = 1 + # Three Black Crows + if Data[i, 3] < Data[i, 0] and (Data[i, 0] - Data[i, 3]) >= body and Data[i, 3] < Data[i - 1, 3] and Data[i - 1, 3] < Data[i - 1, 0] and (Data[i - 1, 0] - Data[i - 1, 3]) >= body and Data[i - 1, 3] < Data[i - 2, 3] and Data[i - 2, 3] < Data[i - 2, 0] and (Data[i - 2, 0] - Data[i - 2, 3]) >= body and Data[i - 2, 3] < Data[i - 3, 3]: + Data[i, 7] = -1 + + +############################################################################## 1 + +my_data = adder(my_data, 10) +my_data = rounding(my_data, 4) +signal(my_data, body) + +if sigchart == True: + signal_chart_ohlc_color(my_data, assets[0], 3, 6, 7, window = 250) + +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]) + +plt.plot(my_data_eq[:, 3], linewidth = 1, label = assets[0]) +plt.grid() +plt.legend() +plt.axhline(y = investment, color = 'black', linewidth = 1) \ No newline at end of file