💬 Forum

madrid_ribbon_1h

🏆 League #82 / 1927

remiotore/ccxt-freqtrade/strategies/madrid_ribbon_1h.py · ★3 · ⑂2 · first seen 2026-07-16 · repo updated 2026-01-11

Basics mode: futures timeframe: 1h interface version: 3
Settings stoploss: -0.1 has minimal roi trailing custom stoploss process only new candles: false
Indicators Bollinger_Bands EMA MACD RSI Stochastic talib technical
Concepts trailing
Methods custom_stoploss
4 related strategies ( identical code, similar name)

Each tile is a different kind of check — from an instant code lint to full sandboxed backtests and forward tests on recent data. Not sure what a check actually proves? See the FAQ →

Source

Download Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from technical.util import resample_to_interval, resampled_merge
from freqtrade.strategy import IStrategy
from typing import Dict, List
from functools import reduce
from pandas import DataFrame
from datetime import datetime


import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib


class madrid_ribbon_1h(IStrategy):
    """
    Madrid Ribbon 001
    author@: Hessebo
    This strategy aims to follow emas.
    How to use it?

    """
    INTERFACE_VERSION: int = 3


    minimal_roi = {
        "60":  0.01,
        "30":  0.03,
        "20":  0.04,
        "0":  0.05
    }
    can_short = True


    stoploss = -0.10

    timeframe = '1h'

    trailing_stop = False
    trailing_stop_positive = 0.01
    trailing_stop_positive_offset = 0.02

    use_custom_stoploss = True


    def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
                        current_rate: float, current_profit: float, **kwargs) -> float:

        if (current_profit > 0.3):
            return 0.01
        elif (current_profit > 0.1):
            return 0.015
        elif (current_profit > 0.06):
            return 0.01
        elif (current_profit > 0.02):
            return 0.05
        elif (current_profit > 0.01):
            return 0.003

        return 0.15

    process_only_new_candles = False

    use_exit_signal = True
    exit_profit_only = False
    ignore_roi_if_entry_signal = False

    order_types = {
        'entry': 'limit',
        'exit': 'limit',
        'stoploss': 'market',
        'stoploss_on_exchange': False
    }

    use_custom_stoploss = False


    def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
                        current_rate: float, current_profit: float, **kwargs) -> float:

        if (current_profit > 0.3):
            return 0.01
        elif (current_profit > 0.1):
            return 0.015
        elif (current_profit > 0.06):
            return 0.01
        elif (current_profit > 0.02):
            return 0.05
        elif (current_profit > 0.01):
            return 0.003

        return 0.15



    def informative_pairs(self):
        """
        Define additional, informative pair/interval combinations to be cached from the exchange.
        These pair/interval combinations are non-tradeable, unless they are part
        of the whitelist as well.
        For more information, please consult the documentation
        :return: List of tuples in the format (pair, interval)
            Sample: return [("ETH/USDT", "5m"),
                            ("BTC/USDT", "15m"),
                            ]
        """
        return []

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame

        Performance Note: For the best performance be frugal on the number of indicators
        you are using. Let uncomment only the indicator you are using in your strategies
        or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
        """

        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']

        stoch = ta.STOCH(
            dataframe,
            fastk_period=14,
            slowk_period=3,
            slowk_matype=0,
            slowd_period=3,
            slowd_matype=0,
        )
        dataframe["slowd"] = stoch["slowd"]
        dataframe["slowk"] = stoch["slowk"]


        macd = ta.MACD(
            dataframe,
            fastperiod=12,
            fastmatype=0,
            slowperiod=26,
            slowmatype=0,
            signalperiod=9,
            signalmatype=0,
        )
        dataframe["macd"] = macd["macd"]
        dataframe["macdsignal"] = macd["macdsignal"]
        dataframe["macdhist"] = macd["macdhist"]


        dataframe['ema_madrid'] = ta.EMA(dataframe, timeperiod=10)
        dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
        dataframe['ema15'] = ta.EMA(dataframe, timeperiod=15)
        dataframe['ema20'] = ta.EMA(dataframe, timeperiod=20)
        dataframe['ema25'] = ta.EMA(dataframe, timeperiod=25)
        dataframe['ema30'] = ta.EMA(dataframe, timeperiod=30)
        dataframe['ema35'] = ta.EMA(dataframe, timeperiod=35)
        dataframe['ema40'] = ta.EMA(dataframe, timeperiod=40)
        dataframe['ema45'] = ta.EMA(dataframe, timeperiod=45)
        dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
        dataframe['ema55'] = ta.EMA(dataframe, timeperiod=55)
        dataframe['ema60'] = ta.EMA(dataframe, timeperiod=60)
        dataframe['ema65'] = ta.EMA(dataframe, timeperiod=65)
        dataframe['ema70'] = ta.EMA(dataframe, timeperiod=70)
        dataframe['ema75'] = ta.EMA(dataframe, timeperiod=75)
        dataframe['ema80'] = ta.EMA(dataframe, timeperiod=80)
        dataframe['ema85'] = ta.EMA(dataframe, timeperiod=85)
        dataframe['ema90'] = ta.EMA(dataframe, timeperiod=90)
        dataframe['ema95'] = ta.EMA(dataframe, timeperiod=95)
        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
        dataframe['ema200'] = ta.EMA(dataframe, timeperiod=200)

        dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)

        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Based on TA indicators, populates the buy signal for the given dataframe
        :param dataframe: DataFrame
        :return: DataFrame with buy column
        """
        dataframe.loc[
            (

                (dataframe["rsi"] > 51) &

                (dataframe['ema5'] > dataframe['ema10']) &
                (dataframe['ema10'] > dataframe['ema15']) &
                (dataframe['ema15'] > dataframe['ema20']) &
                (dataframe['ema20'] > dataframe['ema25']) &
                (dataframe['ema25'] > dataframe['ema30']) &
                (dataframe['ema30'] > dataframe['ema35']) &
                (dataframe['ema35'] > dataframe['ema40']) &
                (dataframe['ema40'] > dataframe['ema45']) &
                (dataframe['ema45'] > dataframe['ema50']) &
                (dataframe['ema50'] > dataframe['ema55']) &
                (dataframe['ema55'] > dataframe['ema60']) &
                (dataframe['ema60'] > dataframe['ema65']) &
                (dataframe['ema65'] > dataframe['ema70']) &
                (dataframe['ema70'] > dataframe['ema75']) &
                (dataframe['ema75'] > dataframe['ema80']) &
                (dataframe['ema80'] > dataframe['ema85']) &
                (dataframe['ema85'] > dataframe['ema90']) &
                (dataframe['ema90'] > dataframe['ema95']) &
                (dataframe['ema95'] > dataframe['ema100']) &
                (dataframe['ema100'] > dataframe['ema200']) &
                (dataframe['close'] > dataframe['bb_middleband'])

            ),
            'enter_long'] = 1

        dataframe.loc[
            (

                (dataframe["rsi"] < 51) &
                (dataframe['ema5'] < dataframe['ema10']) &
                (dataframe['ema10'] < dataframe['ema15']) &
                (dataframe['ema15'] < dataframe['ema20']) &
                (dataframe['ema20'] < dataframe['ema25']) &
                (dataframe['ema25'] < dataframe['ema30']) &
                (dataframe['ema30'] < dataframe['ema35']) &
                (dataframe['ema35'] < dataframe['ema40']) &
                (dataframe['ema40'] < dataframe['ema45']) &
                (dataframe['ema45'] < dataframe['ema50']) &
                (dataframe['ema50'] < dataframe['ema55']) &
                (dataframe['ema55'] < dataframe['ema60']) &
                (dataframe['ema60'] < dataframe['ema65']) &
                (dataframe['ema65'] < dataframe['ema70']) &
                (dataframe['ema70'] < dataframe['ema75']) &
                (dataframe['ema75'] < dataframe['ema80']) &
                (dataframe['ema80'] < dataframe['ema85']) &
                (dataframe['ema85'] < dataframe['ema90']) &
                (dataframe['ema90'] < dataframe['ema95']) &
                (dataframe['ema95'] < dataframe['ema100']) &
                (dataframe['ema100'] < dataframe['ema200']) &
                (dataframe['close'] < dataframe['bb_middleband'])


            ),
            'enter_short'] = 1


        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Based on TA indicators, populates the sell signal for the given dataframe
        :param dataframe: DataFrame
        :return: DataFrame with buy column
        """
        dataframe.loc[
            (
                qtpylib.crossed_above(dataframe['ema10'], dataframe['ema100']) 


            ),
            'exit_long'] = 1

        dataframe.loc[
            (
                qtpylib.crossed_below(dataframe['ema10'], dataframe['ema100']) 


            ),
            'exit_short'] = 1


        return dataframe