
    _i                     f    d dl mZmZmZ d dlmZ d dlmZ d dl	m
c mc mZ  G d de          ZdS )    )	IStrategyIntParametermerge_informative_pair)	DataFrameNc                   (   e Zd ZdZdZdZdZdZdddd	d
ZdZ	dZ
dZdZdZdddddZed             Z edddd          Z edddd          Z edddd          Zd Zd ed!ed"efd#Zd ed!ed"efd$Zd ed!ed"efd%Zd&ed'ed(ed)ed*ed+ed"efd,Zd-S ).CiccioStrategyMTFa  
    CiccioStrategy Multi-Timeframe

    Logica:
    - Timeframe principale: 15m (entry/exit veloci)
    - Timeframe conferma: 1h (trend direction)

    Entry (15m):
    - RSI < 35 (oversold)
    - MACD histogram positivo (momentum in ripresa)
    - Prezzo sotto BB middle
    - CONFERMA 1h: prezzo sopra EMA50 O RSI 1h < 40

    Exit (15m):
    - RSI > 65 (overbought)
    - O trailing stop
    - O ROI target
       15m1h2   g{Gz?g{Gz?g{Gz?g{Gz?)03060120g{GzTgQ?g?limitmarketF)entryexitstoplossstoploss_on_exchangec                 *    ddddddddd	d
dddddgS )NCooldownPeriod   )methodstop_duration_candlesMaxDrawdown   0      g333333?)r   trade_limitlookback_period_candlesr   max_allowed_drawdownStoplossGuard   r	   F)r   r!   r    r   only_per_pair )selfs    [/var/www/html/cicciotrading.cuttalo.com/freqtrade/user_data/strategies/CiccioStrategyMTF.pyprotectionszCiccioStrategyMTF.protectionsC   sT     +)* 
 (!+-)*(,  *+- )*!& 
 	
       (   #   buy)defaultspace   -   <   P   A   sellc                 V      j                                         } fd|D             }|S )zL
        Definisce le coppie informative (1h) per ogni pair tradato
        c                 "    g | ]}|j         fS r&   )informative_timeframe).0pairr'   s     r(   
<listcomp>z7CiccioStrategyMTF.informative_pairs.<locals>.<listcomp>d   s!    RRRDdD$>?RRRr*   )dpcurrent_whitelist)r'   pairsinformative_pairss   `  r(   r@   z#CiccioStrategyMTF.informative_pairs_   s8     ))++RRRRERRR  r*   	dataframemetadatareturnc                 l   t          j        |d          |d<   t          j        |          }|d         |d<   |d         |d<   |d         |d<   t          j        t          j        |          dd	          }|d
         |d<   |d         |d<   |d         |d<   t          j        |d          |d<   t          j        |d          |d<   t          j        |d          |d<   |d                             d                                          |d<   t          j	        |          }|d         |d<   |d         |d<   | j
        r| j
                            |d         | j                  }|j        st          j        |d          |d<   t          j        |d          |d<   t          j        |d          |d <   t          j        |          }|d         |d!<   |d         |d"<   |d#         |d         k                        t                    |d$<   t!          ||| j        | j        d%&          }|S )'z+
        Calcola indicatori su 15m
           )
timeperiodrsimacd
macdsignalmacdhistr   r   )windowstdslowerbb_lowerbandmidbb_middlebandupperbb_upperband	   ema9   ema21r   ema50volume)rK   volume_meanslowkslowdr;   )r;   	timeframersi_1hema50_1h   	ema200_1hmacd_1hmacdsignal_1hclosetrend_1hT)ffill)taRSIMACDqtpylibbollinger_bandstypical_priceEMArollingmeanSTOCHr=   get_pair_dataframer9   emptyastypeintr   r\   )r'   rA   rB   rH   	bollingerstochinformative_1hra   s           r(   populate_indicatorsz%CiccioStrategyMTF.populate_indicatorsg   so   
 6);;;	% wy!! L	&"&|"4	, $Z 0	* +G,A),L,LUW^_```	$-g$6	.!%.u%5	/"$-g$6	.! F9;;;	&VI"===	'VI"===	' $-X#6#>#>b#>#I#I#N#N#P#P	-  ##"7^	'"7^	' 7 	!W77f%4 8  N
 "' +-6.R+P+P+Px(-/VNr-R-R-Rz*.0f^PS.T.T.T{+ '.11,3FOy)29,2G/ $G,~j/IIQQRUVV z*
 3~ND$>  	 r*   c                 D   d|j         v }|rd|j        |d         | j        j        k     |d         dk    |d         |d                             d          k    z  z  |d         |d         k     z  |d         |d	         d
z  k    z  |d         | j        j        k     |d         dk    z  z  |d         dk    z  df<   nfd|j        |d         | j        j        k     |d         |d                             d          k    z  |d         |d         k     z  |d         dk    z  df<   |S )a-  
        Entry su 15m con conferma 1h

        Condizioni 15m:
        - RSI < 35 (oversold)
        - MACD histogram > 0 O in crescita (momentum)
        - Prezzo < BB middle

        Conferma 1h (almeno una):
        - RSI 1h < 45 (non overbought)
        - Prezzo sopra EMA50 1h (trend ok)
        	rsi_1h_1h   rG   rJ   r   rc   rP   rX   rY   g      ?trend_1h_1h
enter_long)columnslocbuy_rsi_15mvalueshift
buy_rsi_1h)r'   rA   rB   has_1h_datas       r(   populate_entry_trendz&CiccioStrategyMTF.populate_entry_trend   s    "Y%66 (	"< !"; M u%(8(>> #:.2":.:1F1L1LQ1O1OOQ	 w')O*DD	F x(9]+Cc+IIK" #;/$/2GG"=1Q68#. x(1,/.2 9 N !" Mu%(8(>>z*Yz-B-H-H-K-KKMw')O*DDF x(1,.
  r*   c                     d|j         |d         | j        j        k    |d         |d         k     z  |d         dk    z  df<   |S )zi
        Exit su 15m

        Condizioni:
        - RSI > 65 (overbought)
        - MACD bearish
        rz   rG   rH   rI   rX   r   	exit_long)r~   sell_rsir   )r'   rA   rB   s      r(   populate_exit_trendz%CiccioStrategyMTF.populate_exit_trend   sf    &  	 5!DM$77 6"Y|%<<> 8$q(* 
	 r*   r;   current_rateproposed_leveragemax_leverage	entry_tagsidec                     dS )z&
        No leverage per spot
        g      ?r&   )	r'   r;   current_timer   r   r   r   r   kwargss	            r(   leveragezCiccioStrategyMTF.leverage   s	     sr*   N)__name__
__module____qualname____doc__INTERFACE_VERSIONr\   r9   startup_candle_countminimal_roir   trailing_stoptrailing_stop_positivetrailing_stop_positive_offsettrailing_only_offset_is_reachedorder_typespropertyr)   r   r   r   r   r@   r   dictrw   r   r   strfloatr   r&   r*   r(   r   r   
   s        &  I !  	 K H M"$)!&*#  %	 K 
 
 X
. ,r2r???Kb"b>>>J|BBf===H! ! !>Y >$ >9 > > > >@;i ;4 ;I ; ; ; ;zY $ 9    .S e $)9>KN).     r*   r   )freqtrade.strategyr   r   r   pandasr   talib.abstractabstractrf   #freqtrade.vendor.qtpylib.indicatorsvendorri   
indicatorsr   r&   r*   r(   <module>r      s    O N N N N N N N N N             5 5 5 5 5 5 5 5 5 5 5 5w w w w w	 w w w w wr*   