💬 Forum

TrendStrategy

rasoky2/TradingBot/tradingbotexe/app/strategies/trend_strategy.py · first seen 2026-07-16 · repo updated 2025-12-16 · ⬇ 1 download

Basics mode: spot timeframe: 1d
Settings stoploss: -0.1 has minimal roi
Concepts swing
Other base_strategy
15 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
from .base_strategy import BaseStrategy
import pandas as pd
import numpy as np

class TrendStrategy(BaseStrategy):
    """
    Estrategia de Tendencia + Momentum (Versión Pandas Puro)
    Combina RSI y Bollinger Bands sin dependencias externas pesadas.
    """
    # Configuración SWING TRADING (4H)
    # Buscamos movimientos del 3% al 10% en días
    minimal_roi = {
        "2880": 0.01, # Dsp de 2 dias (48h*60), aceptar 1%
        "1440": 0.03, # Dsp de 1 dia, aceptar 3%
        "720": 0.05,  # Dsp de 12h, aceptar 5%
        "0": 0.10     # Aceptar 10% inmediato
    }
    
    stoploss = -0.10  # 10% Stoploss (Swing da espacio)
    timeframe = '1d'  # Gráfico de 1 Día (24h)
    
    def populate_indicators(self, dataframe):
        closes = dataframe['close']
        
        # 1. RSI (Manual calculation)
        delta = closes.diff()
        gain = (delta.where(delta > 0, 0)).rolling(window=14).mean()
        loss = (-delta.where(delta < 0, 0)).rolling(window=14).mean()
        rs = gain / loss
        dataframe['rsi'] = 100 - (100 / (1 + rs))
        
        # 2. Bollinger Bands (Manual calculation)
        sma = closes.rolling(window=20).mean()
        std = closes.rolling(window=20).std()
        dataframe['bb_upper'] = sma + (std * 2)
        dataframe['bb_lower'] = sma - (std * 2)
        dataframe['bb_middle'] = sma
        
        # 3. SMA Shorts & Longs
        dataframe['sma_50'] = closes.rolling(window=50).mean()
        
        return dataframe

    def populate_entry_trend(self, dataframe):
        dataframe['enter_long'] = 0
        
        # Regla: RSI bajo (<35) Y Precio tocando banda inferior
        conditions = (
            (dataframe['rsi'] < 35) &
            (dataframe['close'] <= dataframe['bb_lower'])
        )
        
        dataframe.loc[conditions, 'enter_long'] = 1
        return dataframe

    def populate_exit_trend(self, dataframe):
        dataframe['exit_long'] = 0
        
        # Regla: RSI alto (>70) O Precio tocando banda superior
        conditions = (
            (dataframe['rsi'] > 70) |
            (dataframe['close'] >= dataframe['bb_upper'])
        )
        
        dataframe.loc[conditions, 'exit_long'] = 1
        return dataframe