{# Jinja2 template — rendered by generator.py to produce a valid Freqtrade strategy #}
# --- Generated by VARRD {{ version }} ---
# This strategy was statistically validated by VARRD before generation.
# Do NOT modify the entry logic without re-validating.
#
# Hypothesis: {{ hypothesis_name }}
# Market:     {{ market }} ({{ pair }})
# Direction:  {{ direction }}
# Timeframe:  {{ timeframe }}
#
# --- VARRD Validation Stats ---
{%- if has_edge is not none %}
# Edge:         {{ "YES" if has_edge else "NO" }}
{%- endif %}
{%- if win_rate is not none %}
# Win Rate:     {{ "%.1f"|format(win_rate * 100) }}%
{%- endif %}
{%- if sharpe is not none %}
# Sharpe:       {{ "%.2f"|format(sharpe) }}
{%- endif %}
{%- if ev_per_trade is not none %}
# EV/Trade:     {{ "%.2f"|format(ev_per_trade) }}%
{%- endif %}
{%- if profit_factor is not none %}
# Profit Factor: {{ "%.2f"|format(profit_factor) }}
{%- endif %}
{%- if total_trades is not none %}
# Total Trades: {{ total_trades }}
{%- endif %}
{%- if risk_reward is not none %}
# Risk/Reward:  {{ "%.2f"|format(risk_reward) }}
{%- endif %}
{%- if stop_loss_atr is not none %}
# Stop Loss:    {{ "%.1f"|format(stop_loss_atr) }}x ATR
{%- endif %}
{%- if take_profit_atr is not none %}
# Take Profit:  {{ "%.1f"|format(take_profit_atr) }}x ATR
{%- endif %}
{%- if selected_horizon is not none %}
# Horizon:      {{ selected_horizon }} bars
{%- endif %}
{%- if explanation %}
#
{{ explanation }}
{%- endif %}
# --------------------------------

from freqtrade.strategy import IStrategy, IntParameter, DecimalParameter
from freqtrade.persistence import Trade
import pandas as pd
import numpy as np
import talib.abstract as ta


{{ timeframe_to_seconds_func }}


class {{ strategy_class }}(IStrategy):
    """
    {{ hypothesis_name }}

    Generated by VARRD — statistically validated before deployment.
    https://varrd.com
    """

    INTERFACE_VERSION = 3

    timeframe = "{{ timeframe }}"

    # Disable ROI — exits handled by custom_exit
    minimal_roi = {"0": 100}

    stoploss = {{ default_stoploss }}

    # Trailing stop disabled — using ATR-based custom stoploss
    trailing_stop = False
    use_custom_stoploss = {{ use_custom_stoploss }}

    process_only_new_candles = True
    use_exit_signal = False
    startup_candle_count: int = {{ startup_candles }}

    can_short = {{ can_short }}

    def populate_indicators(self, dataframe: pd.DataFrame, metadata: dict) -> pd.DataFrame:
        # ATR for stop-loss / take-profit calculations
        dataframe["atr"] = ta.ATR(dataframe, timeperiod=14)

        # --- VARRD setup_code (translated) ---
        {{ indicators_code }}

        return dataframe

    def populate_entry_trend(self, dataframe: pd.DataFrame, metadata: dict) -> pd.DataFrame:
        # --- VARRD formula (translated) ---
        {{ entry_code }}

        return dataframe

    def populate_exit_trend(self, dataframe: pd.DataFrame, metadata: dict) -> pd.DataFrame:
        # Exits handled by custom_exit (ATR take-profit + time limit)
        return dataframe

{{ custom_stoploss_code }}

{{ custom_exit_code }}
