# source: https://raw.githubusercontent.com/remiotore/freqtrade/44beaeb6a420cd8e9f2e4ea93e11d6cfa192ee03/strategies/flawless_lambo.py
import logging
import numpy as np  # noqa
import pandas as pd  # noqa
from pandas import DataFrame
from sqlalchemy.orm.base import RELATED_OBJECT_OK
from sqlalchemy.sql.elements import or_
import talib.abstract as ta
import pandas_ta as pta
import freqtrade.vendor.qtpylib.indicators as qtpylib
from freqtrade.exchange import timeframe_to_minutes
from freqtrade.persistence import Trade
from technical import indicators
from datetime import datetime, timezone
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, RealParameter,
                                IStrategy, IntParameter, merge_informative_pair)


class Github_remiotore_freqtrade__flawless_lambo__20260111_210550(IStrategy):

    logger = logging.getLogger(__name__)


    INTERFACE_VERSION = 2

    @property
    def protections(self):
        return [
            {
                "method": "MaxDrawdown",
                "lookback_period": 120,
                "trade_limit": 20,
                "stop_duration": 120,
                "max_allowed_drawdown": 0.05
            },
            {
                "method": "StoplossGuard",
                "lookback_period": 1440,
                "trade_limit": 1,
                "stop_duration": 1440,
                "only_per_pair": True
            },
            {
                "method": "LowProfitPairs",
                "lookback_period": 1440,
                "trade_limit": 2,
                "stop_duration": 3600,
                "required_profit": 0.01
            }
        ]



    '''
    minimal_roi = {
        "0": 0.0625,
        "28": 0.05,
        "76": 0.04,
        "125": 0.03,
        "240": 0.02,
        "360": 0
    }
    '''
    
    minimal_roi = {
            "120": 0.30135315985130107,
            "125": 0.29907620817843866,
            "130": 0.2967992565055762,
            "135": 0.29452230483271374,
            "140": 0.2922453531598513,
            "145": 0.2899684014869888,
            "150": 0.28769144981412637,
            "155": 0.2854144981412639,
            "160": 0.2831375464684015,
            "165": 0.28086059479553904,
            "170": 0.2785836431226766,
            "175": 0.2763066914498141,
            "180": 0.27402973977695166,
            "185": 0.2717527881040892,
            "190": 0.26947583643122675,
            "195": 0.2671988847583643,
            "200": 0.2649219330855018,
            "205": 0.26264498141263937,
            "210": 0.2603680297397769,
            "215": 0.25809107806691445,
            "220": 0.25581412639405204,
            "225": 0.2535371747211896,
            "230": 0.2512602230483271,
            "235": 0.2489832713754647,
            "240": 0.2467063197026022,
            "245": 0.24442936802973975,
            "250": 0.2421524163568773,
            "255": 0.23987546468401488,
            "260": 0.2375985130111524,
            "265": 0.23532156133828996,
            "270": 0.2330446096654275,
            "275": 0.23076765799256505,
            "280": 0.2284907063197026,
            "285": 0.22621375464684013,
            "290": 0.22393680297397767,
            "295": 0.22165985130111523,
            "300": 0.2193828996282528,
            "305": 0.21710594795539032,
            "310": 0.21482899628252783,
            "315": 0.2125520446096654,
            "320": 0.21027509293680297,
            "325": 0.2079981412639405,
            "330": 0.20572118959107805,
            "335": 0.2034442379182156,
            "340": 0.20116728624535313,
            "345": 0.1988903345724907,
            "350": 0.19661338289962824,
            "355": 0.19433643122676575,
            "360": 0.19205947955390332,
            "365": 0.18978252788104089,
            "370": 0.18750557620817845,
            "375": 0.18522862453531597,
            "380": 0.1829516728624535,
            "385": 0.18067472118959105,
            "390": 0.17839776951672862,
            "395": 0.17612081784386616,
            "400": 0.1738438661710037,
            "405": 0.17156691449814124,
            "410": 0.16928996282527878,
            "415": 0.16701301115241635,
            "420": 0.1647360594795539,
            "425": 0.16245910780669143,
            "430": 0.16018215613382897,
            "435": 0.15790520446096654,
            "440": 0.15562825278810408,
            "445": 0.15335130111524162,
            "450": 0.15107434944237916,
            "455": 0.1487973977695167,
            "460": 0.14652044609665427,
            "465": 0.1442434944237918,
            "470": 0.14196654275092935,
            "475": 0.1396895910780669,
            "480": 0.13741263940520443,
            "485": 0.135135687732342,
            "490": 0.13285873605947954,
            "495": 0.13058178438661708,
            "500": 0.12830483271375462,
            "505": 0.1260278810408922,
            "510": 0.12375092936802971,
            "515": 0.12147397769516728,
            "520": 0.1191970260223048,
            "525": 0.11692007434944236,
            "530": 0.11464312267657992,
            "535": 0.11236617100371746,
            "540": 0.11079597315436242,
            "545": 0.11028590604026846,
            "550": 0.1097758389261745,
            "555": 0.10926577181208054,
            "560": 0.10875570469798658,
            "565": 0.10824563758389262,
            "570": 0.10773557046979866,
            "575": 0.1072255033557047,
            "580": 0.10671543624161074,
            "585": 0.10620536912751678,
            "590": 0.10569530201342282,
            "595": 0.10518523489932886,
            "600": 0.1046751677852349,
            "605": 0.10416510067114094,
            "610": 0.103655033557047,
            "615": 0.10314496644295304,
            "620": 0.10263489932885908,
            "625": 0.10212483221476512,
            "630": 0.10161476510067116,
            "635": 0.1011046979865772,
            "640": 0.10059463087248324,
            "645": 0.10008456375838928,
            "650": 0.0995744966442953,
            "655": 0.09906442953020134,
            "660": 0.09855436241610738,
            "665": 0.09804429530201342,
            "670": 0.09753422818791946,
            "675": 0.0970241610738255,
            "680": 0.09651409395973154,
            "685": 0.09600402684563758,
            "690": 0.09549395973154362,
            "695": 0.09498389261744966,
            "700": 0.0944738255033557,
            "705": 0.09396375838926174,
            "710": 0.09345369127516778,
            "715": 0.09294362416107382,
            "720": 0.09243355704697986,
            "725": 0.0919234899328859,
            "730": 0.09141342281879196,
            "735": 0.090903355704698,
            "740": 0.09039328859060404,
            "745": 0.08988322147651007,
            "750": 0.08937315436241611,
            "755": 0.08886308724832215,
            "760": 0.08835302013422819,
            "765": 0.08784295302013423,
            "770": 0.08733288590604027,
            "775": 0.08682281879194631,
            "780": 0.08631275167785235,
            "785": 0.08580268456375839,
            "790": 0.08529261744966443,
            "795": 0.08478255033557047,
            "800": 0.08427248322147651,
            "805": 0.08376241610738255,
            "810": 0.0832523489932886,
            "815": 0.08274228187919463,
            "820": 0.08223221476510068,
            "825": 0.08172214765100672,
            "830": 0.08121208053691276,
            "835": 0.0807020134228188,
            "840": 0.08019194630872484,
            "845": 0.07968187919463088,
            "850": 0.07917181208053692,
            "855": 0.07866174496644296,
            "860": 0.078151677852349,
            "865": 0.07764161073825504,
            "870": 0.07713154362416108,
            "875": 0.07662147651006712,
            "880": 0.07611140939597316,
            "885": 0.0756013422818792,
            "890": 0.07509127516778524,
            "895": 0.07458120805369128,
            "900": 0.07407114093959732,
            "905": 0.07356107382550336,
            "910": 0.0730510067114094,
            "915": 0.07254093959731545,
            "920": 0.07203087248322149,
            "925": 0.07152080536912753,
            "930": 0.07101073825503357,
            "935": 0.07050067114093961,
            "940": 0.06999060402684565,
            "945": 0.06948053691275169,
            "950": 0.06897046979865773,
            "955": 0.06846040268456377,
            "960": 0.06795033557046981,
            "965": 0.06744026845637585,
            "970": 0.06693020134228189,
            "975": 0.06642013422818793,
            "980": 0.06591006711409397,
            "985": 0.06540000000000001,
            "990": 0.06488993288590604,
            "995": 0.06437986577181208,
            "1000": 0.06386979865771812,
            "1005": 0.06335973154362416,
            "1010": 0.0628496644295302,
            "1015": 0.06233959731543624,
            "1020": 0.06182953020134229,
            "1025": 0.06131946308724832,
            "1030": 0.060809395973154365,
            "1035": 0.060299328859060405,
            "1040": 0.059789261744966446,
            "1045": 0.059279194630872487,
            "1050": 0.05876912751677853,
            "1055": 0.05825906040268457,
            "1060": 0.05774899328859061,
            "1065": 0.05723892617449665,
            "1070": 0.05672885906040269,
            "1075": 0.05621879194630873,
            "1080": 0.05570872483221477,
            "1085": 0.05519865771812081,
            "1090": 0.05468859060402685,
            "1095": 0.05417852348993289,
            "1100": 0.05366845637583893,
            "1105": 0.05315838926174497,
            "1110": 0.052648322147651014,
            "1115": 0.05213825503355705,
            "1120": 0.05162818791946309,
            "1125": 0.05111812080536913,
            "1130": 0.05060805369127517,
            "1135": 0.05009798657718121,
            "1140": 0.04958791946308725,
            "1145": 0.04907785234899329,
            "1150": 0.04856778523489933,
            "1155": 0.04805771812080538,
            "1160": 0.04754765100671142,
            "1165": 0.04703758389261746,
            "1170": 0.0465275167785235,
            "1175": 0.04601744966442954,
            "1180": 0.04550738255033557,
            "1185": 0.04499731543624161,
            "1190": 0.04448724832214765,
            "1195": 0.04397718120805369,
            "1200": 0.04346711409395973,
            "1205": 0.04295704697986577,
            "1210": 0.04244697986577181,
            "1215": 0.04193691275167785,
            "1220": 0.04142684563758389,
            "1225": 0.04091677852348993,
            "1230": 0.04040671140939597,
            "1235": 0.039896644295302014,
            "1240": 0.039386577181208055,
            "1245": 0.038876510067114095,
            "1250": 0.038366442953020136,
            "1255": 0.037856375838926176,
            "1260": 0.03734630872483222,
            "1265": 0.03683624161073826,
            "1270": 0.0363261744966443,
            "1275": 0.03581610738255034,
            "1280": 0.03530604026845638,
            "1285": 0.03497163695299838,
            "1290": 0.03490072933549433,
            "1295": 0.03482982171799028,
            "1300": 0.034758914100486225,
            "1305": 0.034688006482982175,
            "1310": 0.034617098865478126,
            "1315": 0.03454619124797407,
            "1320": 0.03447528363047002,
            "1325": 0.03440437601296597,
            "1330": 0.03433346839546192,
            "1335": 0.03426256077795786,
            "1340": 0.03419165316045381,
            "1345": 0.03412074554294976,
            "1350": 0.034049837925445706,
            "1355": 0.033978930307941656,
            "1360": 0.033908022690437606,
            "1365": 0.033837115072933556,
            "1370": 0.0337662074554295,
            "1375": 0.03369529983792545,
            "1380": 0.0336243922204214,
            "1385": 0.03355348460291734,
            "1390": 0.03348257698541329,
            "1395": 0.03341166936790924,
            "1400": 0.03334076175040519,
            "1405": 0.033269854132901136,
            "1410": 0.033198946515397086,
            "1415": 0.033128038897893036,
            "1420": 0.03305713128038898,
            "1425": 0.03298622366288493,
            "1430": 0.03291531604538088,
            "1435": 0.03284440842787682,
            "1440": 0.03277350081037277,
            "1445": 0.03270259319286872,
            "1450": 0.03263168557536467,
            "1455": 0.032560777957860616,
            "1460": 0.032489870340356566,
            "1465": 0.032418962722852517,
            "1470": 0.03234805510534847,
            "1475": 0.03227714748784441,
            "1480": 0.03220623987034036,
            "1485": 0.03213533225283631,
            "1490": 0.03206442463533225,
            "1495": 0.0319935170178282,
            "1500": 0.03192260940032415,
            "1505": 0.031851701782820104,
            "1510": 0.03178079416531605,
            "1515": 0.031709886547812,
            "1520": 0.03163897893030795,
            "1525": 0.03156807131280389,
            "1530": 0.03149716369529984,
            "1535": 0.03142625607779579,
            "1540": 0.03135534846029174,
            "1545": 0.031284440842787684,
            "1550": 0.031213533225283634,
            "1555": 0.03114262560777958,
            "1560": 0.03107171799027553,
            "1565": 0.031000810372771477,
            "1570": 0.030929902755267427,
            "1575": 0.030858995137763377,
            "1580": 0.03078808752025932,
            "1585": 0.03071717990275527,
            "1590": 0.03064627228525122,
            "1595": 0.030575364667747167,
            "1600": 0.03050445705024311,
            "1605": 0.030433549432739064,
            "1610": 0.03036264181523501,
            "1615": 0.030291734197730957,
            "1620": 0.030220826580226907,
            "1625": 0.030149918962722858,
            "1630": 0.030079011345218804,
            "1635": 0.03000810372771475,
            "1640": 0.0299371961102107,
            "1645": 0.029866288492706648,
            "1650": 0.02979538087520259,
            "1655": 0.029724473257698544,
            "1660": 0.029653565640194494,
            "1665": 0.02958265802269044,
            "1670": 0.029511750405186388,
            "1675": 0.029440842787682334,
            "1680": 0.029369935170178284,
            "1685": 0.02929902755267423,
            "1690": 0.02922811993517018,
            "1695": 0.02915721231766613,
            "1700": 0.02908630470016208,
            "1705": 0.029015397082658025,
            "1710": 0.028944489465153975,
            "1715": 0.02887358184764992,
            "1720": 0.028802674230145868,
            "1725": 0.028731766612641815,
            "1730": 0.028660858995137768,
            "1735": 0.028589951377633715,
            "1740": 0.02851904376012966,
            "1745": 0.02844813614262561,
            "1750": 0.02837722852512156,
            "1755": 0.028306320907617505,
            "1760": 0.028235413290113455,
            "1765": 0.028164505672609405,
            "1770": 0.02809359805510535,
            "1775": 0.0280226904376013,
            "1780": 0.02795178282009725,
            "1785": 0.027880875202593195,
            "1790": 0.027809967585089145,
            "1795": 0.027739059967585092,
            "1800": 0.02766815235008104,
            "1805": 0.02759724473257699,
            "1810": 0.027526337115072935,
            "1815": 0.027455429497568885,
            "1820": 0.027384521880064832,
            "1825": 0.02731361426256078,
            "1830": 0.02724270664505673,
            "1835": 0.02717179902755268,
            "1840": 0.027100891410048625,
            "1845": 0.027029983792544572,
            "1850": 0.02695907617504052,
            "1855": 0.02688816855753647,
            "1860": 0.026817260940032416,
            "1865": 0.02674635332252837,
            "1870": 0.026675445705024316,
            "1875": 0.026604538087520262,
            "1880": 0.02653363047001621,
            "1885": 0.02646272285251216,
            "1890": 0.026391815235008102,
            "1895": 0.026320907617504052,
            "1900": 0.02625,
            "1905": 0.026179092382495953,
            "1910": 0.0261081847649919,
            "1915": 0.02603727714748785,
            "1920": 0.025966369529983796,
            "1925": 0.025895461912479743,
            "1930": 0.02582455429497569,
            "1935": 0.02575364667747164,
            "1940": 0.02568273905996759,
            "1945": 0.025611831442463536,
            "1950": 0.025540923824959483,
            "1955": 0.025470016207455433,
            "1960": 0.02539910858995138,
            "1965": 0.02532820097244733,
            "1970": 0.025257293354943276,
            "1975": 0.025186385737439223,
            "1980": 0.025115478119935173,
            "1985": 0.02504457050243112,
            "1990": 0.02497366288492707,
            "1995": 0.024902755267423016,
            "2000": 0.024831847649918963,
            "2005": 0.024760940032414913,
            "2010": 0.024690032414910863,
            "2015": 0.02461912479740681,
            "2020": 0.024548217179902757,
            "2025": 0.024477309562398707,
            "2030": 0.024406401944894653,
            "2035": 0.0243354943273906,
            "2040": 0.02426458670988655,
            "2045": 0.0241936790923825,
            "2050": 0.024122771474878447,
            "2055": 0.024051863857374393,
            "2060": 0.023980956239870344,
            "2065": 0.02391004862236629,
            "2070": 0.023839141004862237,
            "2075": 0.023768233387358187,
            "2080": 0.023697325769854137,
            "2085": 0.023626418152350084,
            "2090": 0.02355551053484603,
            "2095": 0.02348460291734198,
            "2100": 0.023413695299837927,
            "2105": 0.023342787682333874,
            "2110": 0.023271880064829824,
            "2115": 0.023200972447325777,
            "2120": 0.02313006482982172,
            "2125": 0.023059157212317667,
            "2130": 0.022988249594813617,
            "2135": 0.022917341977309564,
            "2140": 0.02284643435980551,
            "2145": 0.02277552674230146,
            "2150": 0.02270461912479741,
            "2155": 0.022633711507293357,
            "2160": 0.022562803889789304,
            "2165": 0.022491896272285258,
            "2170": 0.0224209886547812,
            "2175": 0.022350081037277147,
            "2180": 0.022279173419773098,
            "2185": 0.022208265802269048,
            "2190": 0.02213735818476499,
            "2195": 0.02206645056726094,
            "2200": 0.02199554294975689,
            "2205": 0.02192463533225284,
            "2210": 0.021853727714748784,
            "2215": 0.021782820097244734,
            "2220": 0.021711912479740685,
            "2225": 0.02164100486223663,
            "2230": 0.021570097244732574,
            "2235": 0.021499189627228528,
            "2240": 0.021428282009724475,
            "2245": 0.02135737439222042,
            "2250": 0.02128646677471637,
            "2255": 0.02121555915721232,
            "2260": 0.021144651539708268,
            "2265": 0.021073743922204215,
            "2270": 0.021002836304700165,
            "2275": 0.02093192868719611,
            "2280": 0.020861021069692055,
            "2285": 0.020790113452188008,
            "2290": 0.02071920583468396,
            "2295": 0.020648298217179905,
            "2300": 0.02057739059967585,
            "2305": 0.0205064829821718,
            "2310": 0.020435575364667752,
            "2315": 0.020364667747163695,
            "2320": 0.020293760129659645,
            "2325": 0.020222852512155595,
            "2330": 0.020151944894651545,
            "2335": 0.02008103727714749,
            "2340": 0.02001012965964344,
            "2345": 0.01993922204213939,
            "2350": 0.019868314424635332,
            "2355": 0.01979740680713128,
            "2360": 0.019726499189627232,
            "2365": 0.01965559157212318,
            "2370": 0.019584683954619125,
            "2375": 0.019513776337115075,
            "2380": 0.019442868719611026,
            "2385": 0.019371961102106972,
            "2390": 0.01930105348460292,
            "2395": 0.01923014586709887,
            "2400": 0.019159238249594816,
            "2405": 0.01908833063209076,
            "2410": 0.019017423014586712,
            "2415": 0.01894651539708266,
            "2420": 0.01887560777957861,
            "2425": 0.018804700162074556,
            "2430": 0.018733792544570502,
            "2435": 0.018662884927066452,
            "2440": 0.0185919773095624,
            "2445": 0.01852106969205835,
            "2450": 0.018450162074554296,
            "2455": 0.01837925445705025,
            "2460": 0.018308346839546193,
            "2465": 0.018237439222042143,
            "2470": 0.01816653160453809,
            "2475": 0.018095623987034036,
            "2480": 0.018024716369529983,
            "2485": 0.017953808752025933,
            "2490": 0.017882901134521883,
            "2495": 0.01781199351701783,
            "2500": 0.01774108589951378,
            "2505": 0.017670178282009726,
            "2510": 0.017599270664505673,
            "2515": 0.017528363047001623,
            "2520": 0.01745745542949757,
            "2525": 0.01738654781199352,
            "2530": 0.017315640194489466,
            "2535": 0.017244732576985417,
            "2540": 0.017173824959481363,
            "2545": 0.01710291734197731,
            "2550": 0.01703200972447326,
            "2555": 0.016961102106969207,
            "2560": 0.016890194489465157,
            "2565": 0.016819286871961103,
            "2570": 0.016748379254457053,
            "2575": 0.016677471636953,
            "2580": 0.016606564019448947,
            "2585": 0.016535656401944897,
            "2590": 0.016464748784440843,
            "2595": 0.016393841166936794,
            "2600": 0.01632293354943274,
            "2605": 0.01625202593192869,
            "2610": 0.016181118314424637,
            "2615": 0.016110210696920584,
            "2620": 0.016039303079416534,
            "2625": 0.01596839546191248,
            "2630": 0.01589748784440843,
            "2635": 0.015826580226904377,
            "2640": 0.015755672609400327,
            "2645": 0.015684764991896274,
            "2650": 0.01561385737439222,
            "2655": 0.01554294975688817,
            "2660": 0.015472042139384115,
            "2665": 0.015401134521880067,
            "2670": 0.015330226904376014,
            "2675": 0.015259319286871964,
            "2680": 0.01518841166936791,
            "2685": 0.015117504051863856,
            "2690": 0.015046596434359807,
            "2695": 0.014975688816855754,
            "2700": 0.014904781199351704,
            "2705": 0.01483387358184765,
            "2710": 0.0147629659643436,
            "2715": 0.014692058346839548,
            "2720": 0.014621150729335494,
            "2725": 0.014550243111831444,
            "2730": 0.014479335494327393,
            "2735": 0.01440842787682334,
            "2740": 0.014337520259319288,
            "2745": 0.014266612641815238,
            "2750": 0.014195705024311184,
            "2755": 0.014124797406807133,
            "2760": 0.01405388978930308,
            "2765": 0.013982982171799028,
            "2770": 0.013912074554294978,
            "2775": 0.013841166936790925,
            "2780": 0.013770259319286876,
            "2785": 0.01369935170178282,
            "2790": 0.013628444084278771,
            "2795": 0.013557536466774718,
            "2800": 0.013486628849270665,
            "2805": 0.013415721231766617,
            "2810": 0.01334481361426256,
            "2815": 0.013273905996758512,
            "2820": 0.013202998379254458,
            "2825": 0.013132090761750408,
            "2830": 0.013061183144246357,
            "2835": 0.012990275526742302,
            "2840": 0.012919367909238252,
            "2845": 0.012848460291734198,
            "2850": 0.012777552674230148,
            "2855": 0.012706645056726097,
            "2860": 0.012635737439222043,
            "2865": 0.012564829821717992,
            "2870": 0.012493922204213938,
            "2875": 0.012423014586709889,
            "2880": 0.012352106969205835,
            "2885": 0.012281199351701784,
            "2890": 0.012210291734197732,
            "2895": 0.012139384116693682,
            "2900": 0.012068476499189629,
            "2905": 0.011997568881685575,
            "2910": 0.011926661264181524,
            "2915": 0.011855753646677472,
            "2920": 0.011784846029173422,
            "2925": 0.011713938411669369,
            "2930": 0.01164303079416532,
            "2935": 0.011572123176661266,
            "2940": 0.011501215559157212,
            "2945": 0.011430307941653162,
            "2950": 0.011359400324149107,
            "2955": 0.01128849270664506,
            "2960": 0.011217585089141006,
            "2965": 0.011146677471636956,
            "2970": 0.011075769854132902,
            "2975": 0.011004862236628847,
            "2980": 0.0109339546191248,
            "2985": 0.010863047001620746,
            "2990": 0.010792139384116696,
            "2995": 0.010721231766612644,
            "3000": 0.010650324149108593,
            "3005": 0.01057941653160454,
            "3010": 0.010508508914100486,
            "3015": 0.010437601296596436,
            "3020": 0.010366693679092384,
            "3025": 0.010295786061588331,
            "3030": 0.01022487844408428,
            "3035": 0.01015397082658023,
            "3040": 0.010083063209076176,
            "3045": 0.010012155591572125,
            "3050": 0.009941247974068071,
            "3055": 0.00987034035656402,
            "3060": 0.00979943273905997,
            "3065": 0.009728525121555916,
            "3070": 0.009657617504051868,
            "3075": 0.009586709886547811,
            "3080": 0.00951580226904376,
            "3085": 0.00944489465153971,
            "3090": 0.009373987034035657,
            "3095": 0.009303079416531608,
            "3100": 0.009232171799027552,
            "3105": 0.009161264181523503,
            "3110": 0.00909035656401945,
            "3115": 0.009019448946515397,
            "3120": 0.008948541329011347,
            "3125": 0.008877633711507293,
            "3130": 0.008806726094003244,
            "3135": 0.00873581847649919,
            "3140": 0.00866491085899514,
            "3145": 0.008594003241491087,
            "3150": 0.008523095623987034,
            "3155": 0.008452188006482984,
            "3160": 0.00838128038897893,
            "3165": 0.00831037277147488,
            "3170": 0.008239465153970827,
            "3175": 0.008168557536466777,
            "3180": 0.008097649918962724,
            "3185": 0.00802674230145867,
            "3190": 0.00795583468395462,
            "3195": 0.007884927066450567,
            "3200": 0.007814019448946517,
            "3205": 0.007743111831442464,
            "3210": 0.007672204213938414,
            "3215": 0.007601296596434361,
            "3220": 0.007530388978930307,
            "3225": 0.007459481361426257,
            "3230": 0.007388573743922204,
            "3235": 0.007317666126418154,
            "3240": 0.007246758508914101,
            "3245": 0.007175850891410051,
            "3250": 0.0071049432739059976,
            "3255": 0.007034035656401944,
            "3260": 0.006963128038897894,
            "3265": 0.006892220421393841,
            "3270": 0.006821312803889791,
            "3275": 0.006750405186385738,
            "3280": 0.006679497568881688,
            "3285": 0.0066085899513776344,
            "3290": 0.006537682333873581,
            "3295": 0.006466774716369531,
            "3300": 0.006395867098865478,
            "3305": 0.006324959481361428,
            "3310": 0.006254051863857375,
            "3315": 0.006183144246353325,
            "3320": 0.006112236628849271,
            "3325": 0.006041329011345218,
            "3330": 0.005970421393841168,
            "3335": 0.005899513776337115,
            "3340": 0.005828606158833065,
            "3345": 0.0057576985413290115,
            "3350": 0.005686790923824962,
            "3355": 0.005615883306320908,
            "3360": 0.005544975688816855,
            "3365": 0.005474068071312805,
            "3370": 0.005403160453808752,
            "3375": 0.005332252836304702,
            "3380": 0.005261345218800648,
            "3385": 0.0051904376012965985,
            "3390": 0.005119529983792545,
            "3395": 0.005048622366288495,
            "3400": 0.004977714748784442,
            "3405": 0.0049068071312803885,
            "3410": 0.004835899513776339,
            "3415": 0.004764991896272285,
            "3420": 0.004694084278768235,
            "3425": 0.004623176661264182,
            "3430": 0.004552269043760132,
            "3435": 0.004481361426256079,
            "3440": 0.004410453808752025,
            "3445": 0.0043395461912479755,
            "3450": 0.004268638573743922,
            "3455": 0.004197730956239872,
            "3460": 0.004126823338735819,
            "3465": 0.004055915721231769,
            "3470": 0.003985008103727716,
            "3475": 0.003914100486223662,
            "3480": 0.003843192868719613,
            "3485": 0.003772285251215559,
            "3490": 0.0037013776337115056,
            "3495": 0.003630470016207456,
            "3500": 0.003559562398703406,
            "3505": 0.003488654781199349,
            "3510": 0.003417747163695299,
            "3515": 0.0033468395461912492,
            "3520": 0.0032759319286871993,
            "3525": 0.0032050243111831425,
            "3530": 0.0031341166936790926,
            "3535": 0.0030632090761750427,
            "3540": 0.002992301458670986,
            "3545": 0.002921393841166936,
            "3550": 0.002850486223662886,
            "3555": 0.002779578606158836,
            "3560": 0.0027086709886547794,
            "3565": 0.0026377633711507295,
            "3570": 0.0025668557536466796,
            "3575": 0.002495948136142623,
            "3580": 0.002425040518638573,
            "3585": 0.002354132901134523,
            "3590": 0.002283225283630473,
            "3595": 0.0022123176661264163,
            "3600": 0.0021414100486223664,
            "3605": 0.0020705024311183165,
            "3610": 0.0019995948136142597,
            "3615": 0.0019286871961102096,
            "3620": 0.00185777957860616,
            "3625": 0.00178687196110211,
            "3630": 0.0017159643435980532,
            "3635": 0.0016450567260940033,
            "3640": 0.0015741491085899534,
            "3645": 0.0015032414910858966,
            "3650": 0.0014323338735818469,
            "3655": 0.0013614262560777968,
            "3660": 0.0012905186385737469,
            "3665": 0.00121961102106969,
            "3670": 0.0011487034035656402,
            "3675": 0.0010777957860615905,
            "3680": 0.0010068881685575334,
            "3685": 0.0009359805510534837,
            "3690": 0.0008650729335494337,
            "3695": 0.0007941653160453838,
            "3700": 0.0007232576985413269,
            "3705": 0.000652350081037277,
            "3710": 0.0005814424635332271,
            "3715": 0.0005105348460291703,
            "3720": 0.0004396272285251204,
            "3725": 0.00036871961102107054,
            "3730": 0.00029781199351702065,
            "3735": 0.00022690437601296384,
            "3740": 0.00015599675850891392,
            "3745": 8.508914100486403e-05,
            "3750": 1.4181523500814142e-05,
            "3755": 0,
            "3900": -0.01,
            "3960": -0.02,
            "4020": -0.03,
            "4080": -0.04,
            "4140": -0.05,
            "4200": -0.06,
            "4260": -0.07,
            "4320": -0.08,
            "4380": -0.09
        }



    stoploss = -0.10 #-0.10

    trailing_stop = True
    trailing_stop_positive = 0.01
    trailing_stop_positive_offset = 0.03
    trailing_only_offset_is_reached = False
    process_only_new_candles = True

    startup_candle_count: int = 20 #30

    timeframe = '30m'

    use_sell_signal = True
    sell_profit_only = True

    ignore_roi_if_buy_signal = True

    sell_rsi = DecimalParameter(60, 100, default=73.9)
    sell_williams = DecimalParameter(-30, 0, default=-20)

    custom_info_trail_sell = dict()
    trailing_sell_order_enabled = True    

    trailing_expire_seconds = 1800/5    #NOTE 1m timeframe

    trailing_sell_uptrend_enabled = True    
    trailing_expire_seconds_uptrend = 90
    min_uptrend_trailing_profit = 0.02
    debug_mode = True
    trailing_sell_max_stop = 0.02   # stop trailing sell if current_price < starting_price * (1+trailing_buy_max_stop)
    trailing_sell_max_sell = 0.000  # sell if price between downlimit (=max of serie (current_price * (1 + trailing_sell_offset())) and (start_price * 1+trailing_sell_max_sell))
    abort_trailing_when_sell_signal_triggered = True

    
    init_trailing_sell_dict = {
        'trailing_sell_order_started': False,
        'trailing_sell_order_downlimit': 0,        
        'start_trailing_sell_price': 0,
        'sell_tag': None,
        'start_trailing_time': None,
        'offset': 0,
        'allow_sell_trailing': False,
    }

    order_types = {
        'buy': 'limit',
        'sell': 'limit',
        'stoploss': 'market',
        'stoploss_on_exchange': False
    }

    order_time_in_force = {
        'buy': 'gtc',
        'sell': 'gtc'
    }
    
    @property
    def plot_config(self):
        return {
            "main_plot": {
                "bb.lower": {
                    "color": "#9c6edc",
                    "type": "line"
                },
                "bb.upper": {
                    "color": "#9c6edc",
                    "type": "line"
                },
                "vwma": {
                    "color": "#4f9f02",
                    "type": "line"
                }
            },
            "subplots": {
                "obv": {
                    "OBV": {
                        "color": "#1b61ab",
                        "type": "line"
                    },
                    "OBVSlope": {
                        "color": "#f18b7a",
                        "type": "line"
                    }
                },
                "vpci": {
                    "vpci": {
                        "color": "#d59a7a",
                        "type": "line"
                    }
                },
                "macd": {
                    "macd": {
                        "color": "#1c3d6a",
                        "type": "line"
                    },
                    "macdsignal": {
                        "color": "#873480",
                        "type": "line"
                    },
                    "macdhist": {
                        "color": "#478a87",
                        "type": "bar"
                    }
                },
                "wiliams": {
                    "williamspercent": {
                        "color": "#10f551",
                        "type": "line"
                    }
                },
                "stoch + rsi": {
                    "rsi": {
                        "color": "#d7affd",
                        "type": "line"
                    },
                    "slowd": {
                        "color": "#d7cc5c",
                        "type": "line"
                    },
                    "fastk": {
                        "color": "#186f86",
                        "type": "line"
                    }
                },
                "adx": {
                    "adx": {
                        "color": "#c392cd",
                        "type": "line"
                    },
                    "plus.di": {
                        "color": "#bcd6c5",
                        "type": "line"
                    },
                    "minus.di": {
                        "color": "#eb044c",
                        "type": "line"
                    }
                }
            }
        }

    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"),
                            ]
        """
        pairs = self.dp.current_whitelist()
        informative_pairs = [(pair, self.timeframe) for pair in pairs]

        return informative_pairs

    def trailing_sell(self, pair, reinit=False):

        if not pair in self.custom_info_trail_sell:
            self.custom_info_trail_sell[pair] = dict()
        if (reinit or not 'trailing_sell' in self.custom_info_trail_sell[pair]):
            self.custom_info_trail_sell[pair]['trailing_sell'] = self.init_trailing_sell_dict.copy()
        
        return self.custom_info_trail_sell[pair]['trailing_sell']

    def trailing_sell_info(self, pair: str, current_price: float):

        current_time = datetime.now(timezone.utc)
        if not self.debug_mode:
            return
        trailing_sell = self.trailing_sell(pair)

        duration = 0
        try:
            duration = (current_time - trailing_sell['start_trailing_time'])
        except TypeError:
            duration = 0
        finally:
            self.logger.info("'\033[36m'SELL: "
                f"pair: {pair} : "
                f"start: {trailing_sell['start_trailing_sell_price']:.4f}, "
                f"duration: {duration}, "
                f"current: {current_price:.4f}, "
                f"downlimit: {trailing_sell['trailing_sell_order_downlimit']:.4f}, "
                f"profit: {self.current_trailing_sell_profit_ratio(pair, current_price)*100:.2f}%, "
                f"offset: {trailing_sell['offset']}")

    def current_trailing_sell_profit_ratio(self, pair: str, current_price: float) -> float:
        trailing_sell = self.trailing_sell(pair)
        if trailing_sell['trailing_sell_order_started']:
            return (current_price - trailing_sell['start_trailing_sell_price'])/ trailing_sell['start_trailing_sell_price']

        else:
            return 0
    
    def trailing_sell_offset(self, dataframe, pair: str, current_price: float):




        current_trailing_sell_profit_ratio = self.current_trailing_sell_profit_ratio(pair, current_price)
        last_candle = dataframe.iloc[-1]
        adapt  = (last_candle['perc_norm']).round(5)
        default_offset = 0.003 * (1 + adapt)        #NOTE: default_offset 0.003 <--> 0.006
        
        trailing_sell  = self.trailing_sell(pair)
        if not trailing_sell['trailing_sell_order_started']:
            return default_offset


        last_candle = dataframe.iloc[-1]
        current_time = datetime.now(timezone.utc)
        trailing_duration =  current_time - trailing_sell['start_trailing_time']
        if trailing_duration.total_seconds() > self.trailing_expire_seconds:
            if ((current_trailing_sell_profit_ratio > 0) and (last_candle['sell'] != 0)):

                return 'forcesell'
            else:

                return None
        elif (self.trailing_sell_uptrend_enabled and (trailing_duration.total_seconds() < self.trailing_expire_seconds_uptrend) and (current_trailing_sell_profit_ratio < (-1 * self.min_uptrend_trailing_profit))):

            return 'forcesell'

        if current_trailing_sell_profit_ratio > 0:

            return default_offset

        trailing_sell_offset = {


            0.1: default_offset,
        }

        for key in trailing_sell_offset:
            if current_trailing_sell_profit_ratio < key:
                return trailing_sell_offset[key]

        return default_offset


    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:



        if self.dp:
            if self.dp.runmode.value in ('live', 'dry_run'):
                ob = self.dp.orderbook(metadata['pair'], 1)
                dataframe['best_bid'] = ob['bids'][0][0]
                dataframe['best_ask'] = ob['asks'][0][0]

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

        dataframe['OBV'] = ta.OBV(dataframe)
        dataframe['OBVSlope'] = pta.momentum.slope(dataframe['OBV'])








        dataframe['vpci'] = indicators.vpci(dataframe, period_long=14)

        dataframe['williamspercent'] = indicators.williams_percent(dataframe)

        dataframe['adx'] = ta.ADX(dataframe)
        dataframe['plus.di'] = ta.PLUS_DI(dataframe)
        dataframe['minus.di'] = ta.MINUS_DI(dataframe)

        dataframe['rsi'] = ta.RSI(dataframe)

        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        stoch_slow = ta.STOCH(dataframe)
        dataframe['slowd'] = stoch_slow['slowd']
        dataframe['slowk'] = stoch_slow['slowk']

        dataframe['perc'] = ((dataframe['high'] - dataframe['low']) / dataframe['low']*100)
        dataframe['avg3_perc'] = ta.EMA(dataframe['perc'], 3)
        dataframe['perc_norm'] = (dataframe['perc'] - dataframe['perc'].rolling(50).min())/(dataframe['perc'].rolling(50).max()-dataframe['perc'].rolling(50).min())

        self.trailing_sell(metadata['pair'])

        return dataframe


    def do_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

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

        dataframe['OBV'] = ta.OBV(dataframe)
        dataframe['OBVSlope'] = pta.momentum.slope(dataframe['OBV'])





        dataframe['vpci'] = indicators.vpci(dataframe, period_long=14)

        dataframe['williamspercent'] = indicators.williams_percent(dataframe)

        dataframe['adx'] = ta.ADX(dataframe)
        dataframe['plus.di'] = ta.PLUS_DI(dataframe)
        dataframe['minus.di'] = ta.MINUS_DI(dataframe)

        dataframe['rsi'] = ta.RSI(dataframe)

        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        stoch_slow = ta.STOCH(dataframe)
        dataframe['slowd'] = stoch_slow['slowd']
        dataframe['slowk'] = stoch_slow['slowk']

        dataframe['perc'] = ((dataframe['high'] - dataframe['low']) / dataframe['low']*100)
        dataframe['avg3_perc'] = ta.EMA(dataframe['perc'], 3)
        dataframe['perc_norm'] = (dataframe['perc'] - dataframe['perc'].rolling(50).min())/(dataframe['perc'].rolling(50).max()-dataframe['perc'].rolling(50).min())

        self.trailing_sell(metadata['pair'])

        return dataframe

    def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,
                           rate: float, time_in_force: str, sell_reason: str, **kwargs) -> bool:
        val = super().confirm_trade_exit(pair, trade, order_type, amount, rate, time_in_force, sell_reason, **kwargs)        
        
        if val:
            if self.trailing_sell_order_enabled and self.config['runmode'].value in ('live', 'dry_run'):
                val = False
                dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
                if(len(dataframe) >= 1):
                    last_candle = dataframe.iloc[-1].squeeze()
                    current_price = rate
                    trailing_sell= self.trailing_sell(pair)
                    trailing_sell_offset = self.trailing_sell_offset(dataframe, pair, current_price)

                    if trailing_sell['allow_sell_trailing']:
                        if (not trailing_sell['trailing_sell_order_started'] and (last_candle['sell'] != 0)):
                            trailing_sell['trailing_sell_order_started'] = True
                            trailing_sell['trailing_sell_order_downlimit'] = last_candle['close']
                            trailing_sell['start_trailing_sell_price'] = last_candle['close']
                            trailing_sell['sell_tag'] = last_candle['sell_tag']
                            trailing_sell['start_trailing_time'] = datetime.now(timezone.utc)
                            trailing_sell['offset'] = 0
                            
                            self.trailing_sell_info(pair, current_price)
                            self.logger.info(f'start trailing sell for {pair} at {last_candle["close"]}')

                        elif trailing_sell['trailing_sell_order_started']:
                            if trailing_sell_offset == 'forcesell':

                                val = True
                                ratio = "%.2f" % ((self.current_trailing_sell_profit_ratio(pair, current_price)) * 100)
                                self.trailing_sell_info(pair, current_price)
                                self.logger.info(f"FORCESELL for {pair} ({ratio} %, {current_price})")

                            elif trailing_sell_offset is None:

                                self.trailing_sell(pair, reinit=True)
                                self.logger.info(f'STOP trailing sell for {pair} because "trailing sell offset" returned None')

                            elif current_price > trailing_sell['trailing_sell_order_downlimit']:

                                old_downlimit = trailing_sell["trailing_sell_order_downlimit"]
                                self.custom_info_trail_sell[pair]['trailing_sell']['trailing_sell_order_downlimit'] = max(current_price * (1 - trailing_sell_offset), self.custom_info_trail_sell[pair]['trailing_sell']['trailing_sell_order_downlimit'])
                                self.custom_info_trail_sell[pair]['trailing_sell']['offset'] = trailing_sell_offset
                                self.trailing_sell_info(pair, current_price)
                                self.logger.info(f'update trailing sell for {pair} at {old_downlimit} -> {self.custom_info_trail_sell[pair]["trailing_sell"]["trailing_sell_order_downlimit"]}')

                            elif current_price > (trailing_sell['start_trailing_sell_price'] * (1 - self.trailing_sell_max_sell)):

                                val = True
                                ratio = "%.2f" % ((self.current_trailing_sell_profit_ratio(pair, current_price)) * 100)
                                self.trailing_sell_info(pair, current_price)
                                self.logger.info(f"current price ({current_price}) < downlimit ({trailing_sell['trailing_sell_order_downlimit']}) but higher than starting price ({(trailing_sell['start_trailing_sell_price'] * (1 + self.trailing_sell_max_sell))}). OK for {pair} ({ratio} %)")

                            elif current_price < (trailing_sell['start_trailing_sell_price'] * (1 - self.trailing_sell_max_stop)):

                                val = True                                
                                self.trailing_sell_info(pair, current_price)
                                self.logger.info(f'STOP trailing sell for {pair} because of the price is much lower than starting price * {1 + self.trailing_sell_max_stop}')
                            else:

                                self.trailing_sell_info(pair, current_price)
                                self.logger.info(f'price too low for {pair} !')

                    else:
                        self.logger.info(f"Wait for next sell signal for {pair}")

                if (val == True):
                    self.trailing_sell_info(pair, rate)
                    self.trailing_sell(pair, reinit=True)
                    self.logger.info(f'STOP trailing sell for {pair} because I SOLD it')

        if sell_reason != 'sell_signal':
            val = True

        return val
        
    def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
            (dataframe['volume'] > 0) &
            (dataframe['OBVSlope'] > 0) &
            (qtpylib.crossed_above(dataframe['close'], dataframe['bb.lower']))
            ),'buy'] = 1
        
        return dataframe

    def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

        dataframe.loc[
            (
                (dataframe['volume'] > 0) &
                (qtpylib.crossed_above(dataframe['close'], dataframe['bb.upper'])) &
                (dataframe['vpci'] > 0) &
                (dataframe['williamspercent'] > self.sell_williams.value) &
                (dataframe['rsi'] > self.sell_rsi.value)
            ),
            'sell'] = 1

        if self.trailing_sell_order_enabled and self.config['runmode'].value in ('live', 'dry_run'): 
            last_candle = dataframe.iloc[-1].squeeze()
            trailing_sell = self.trailing_sell(metadata['pair'])
            if (last_candle['sell'] != 0):
                if not trailing_sell['trailing_sell_order_started']:
                    open_trades = Trade.get_trades([Trade.pair == metadata['pair'], Trade.is_open.is_(True), ]).all()

                    if open_trades:
                        self.logger.info(f"Set 'allow_SELL_trailing' to True for {metadata['pair']} to start *SELL* trailing")

                        trailing_sell['allow_sell_trailing'] = True
                        initial_sell_tag = last_candle['sell_tag'] if 'sell_tag' in last_candle else 'sell signal'
                        dataframe.loc[:, 'sell_tag'] = f"{initial_sell_tag} (start trail price {last_candle['close']})"
            else:
                if (trailing_sell['trailing_sell_order_started'] == True):
                    self.logger.info(f"Continue trailing for {metadata['pair']}. Manually trigger sell signal!")
                    dataframe.loc[:,'sell'] = 1
                    dataframe.loc[:, 'sell_tag'] = trailing_sell['sell_tag']

        return dataframe

