Combo 4+ KDJ STO RSI EMA3 Visual Trend Pine V5@RL
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RegisL76
// V 994 
// *** PINE SCRIPT V5 *** //
// *********************************************************************************** //

// V 1 publiée 2021-10-20 V 7.6.4 @RL
// V 2 publiée 2023-03-20 V 9.9.4 @RL

//@version=5
indicator(title='Combo 4+ KDJ STO RSI EMA3 Visual Trend Pine V5@RL',format=format.inherit,shorttitle='Combo 4+ Visual Trend @RL',overlay=false)  

// *********************************************************************************** // 
//                               Implemented by @Regis_L                               //

// *********************************** COMMON CODE *********************************** //
//                                     © RegisL76                                      //
// *********************************************************************************** //  
ArrowUp      =string('🔼')
ArrowDown    =string('🔽')
ArrowRight   =string('▶️')
//**************************************************************************************************************************
f_ExtLines(_NbVal,_ExtOffset,_Value1,_Value2,_Value3,_Color1,_Color2,_Color3,_style1,_style2,_style3,_width1,_width2,_width3)=>
// Definition de fonction : trace une pseudo tangente (etendue à droite) pour 1 à 3 courbes
// ! _NbVal== [1 to 3]
// ! _NbVal==1 -> _Value2==float(na) & _Color2==color(na) & _Value3==float(na) & _Color3==color(na)
// ! _NbVal==2 -> _Value3==float(na)) & _Color3==color(na)
    if _NbVal>=1 and _NbVal<4
        _ExtLine1 = line.new(bar_index-_ExtOffset, _Value1[_ExtOffset], bar_index, _Value1, color=_Color1,style=_style1, width=_width1, extend=extend.right)
        line.delete(_ExtLine1[1])
    // Extended line Fast
    if _NbVal>=2 and _NbVal<4
        _ExtLine2 = line.new(bar_index-_ExtOffset, _Value2[_ExtOffset], bar_index, _Value2, color=_Color2,style=_style2, width=_width2, extend=extend.right)
        line.delete(_ExtLine2[1])
    if _NbVal==3
        _ExtLine3 = line.new(bar_index-_ExtOffset, _Value3[_ExtOffset], bar_index, _Value3, color=_Color3,style=_style3, width=_width3, extend=extend.right)
        line.delete(_ExtLine3[1])
        // [na]
//**************************************************************************************************************************

//**************************************************************************************************************************
f_Delta (_Value1, _Value2) =>
    // Definition de fonction : Calcul de l'evolution et de la direction du delta entre 2 valeurs, en % (acceleration)
    _ArrowUp      =string('🔼')
    _ArrowDown    =string('🔽')
    _RedCross     =string('❌')
    _Delta=math.abs((_Value1 - _Value2))
    
    _DeltaPerCent  = ((_Delta - _Delta[1]) / _Delta)*100
    if math.abs(_DeltaPerCent)>=120
        _DeltaPerCent:=na
    
    _DeltaRise=_Delta>_Delta[1]
    _DeltaFall=_Delta<_Delta[1]
    _DeltaDir= _DeltaRise and _DeltaPerCent!=na(_DeltaPerCent) ? _ArrowUp : _DeltaFall and _DeltaPerCent!=na(_DeltaPerCent) ? _ArrowDown : _RedCross

    [_DeltaPerCent, _DeltaRise, _DeltaFall, _DeltaDir] 
//**************************************************************************************************************************

// *** Evolution Du Prix Actuel *** // 
// *** Current Price Evolution  *** //
priceuptemp = ta.rising(close, 1)
pricedowntemp = ta.falling(close, 1)
priceup = priceuptemp and not pricedowntemp
pricedown = not priceuptemp and pricedowntemp

high_up = ta.rising(high, 1)
high_down = ta.falling(high, 1)

low_up = ta.rising(low, 1)
low_down = ta.falling(low, 1)

open_up = ta.rising(open, 1)
open_down = ta.falling(open, 1)

show_ema = input.bool(false ,'Display : EMA Indicator', tooltip='!!! Settings : Choose Only One Of The 4 Indicators To Display !!! ') 
show_kdj = input.bool(false ,'Display : KDJ Indicator', tooltip='!!! Settings : Choose Only One Of The 4 Indicators To Display !!! ')
show_rsi = input.bool(false ,'Display : RSI Indicator', tooltip='!!! Settings : Choose Only One Of The 4 Indicators To Display !!! ')
show_sto = input.bool(true  ,'Display : STO Indicator', tooltip='!!! Settings : Choose Only One Of The 4 Indicators To Display !!! ')

display_combined_layouts = input.bool(true, 'Display Combined Layouts ', tooltip='Checked=Logical Result Of Each (4) Layout And [x] Combined Bkg (No Checked=Specific Indicator Layout And Bkg) '
 , confirm=true)

at_least_x_among_4_combined_bkg = input.int(3, title='At Least x Combined Bkg', minval=1, maxval=4,tooltip='[1 ; 4] Default=3', confirm=true)

ExtOffset  = input.int   (3 ,title='offset Extend lines',minval = 1,maxval=26,step=1,tooltip ='Default=3')

main_show_trend_label = input.bool(true, title ='Show Trend Label')
main_show_stops_label = input.bool(true, title ='Show Signal Stop Label')
main_show_infos_label = input.bool(false, title='Show Infos Label')
full_label_info       = input.bool(false, title='Full Infos Label', tooltip='Simple or Full Infos Label', confirm=true)  

// ********************************************************************************************************************************************************************** //

// *********************************************************************************** //  
//                               Implemented by @Regis_L                               //

// ************************** KDJ Indicator [Pine V5] @RL CODE *********************** // 
//                                     © RegisL76                                      //
// ************************ Based on KDJ Indicator [Pine V5] @RL ********************* //
// *********************************************************************************** // 
kdj_ilong = input(26, title='KDJ period',tooltip='default=26')
kdj_isig  = input(5, title='KDJ signal',tooltip='default=5')
kdj_high_threshold = input.int(115, title='KDJ High Threshold', minval=50, maxval=150,tooltip='default=115')
kdj_low_threshold  = input.int(-15, title='KDJ Low Threshold' , minval=-50, maxval=50,tooltip='default=-15')

// *********************************************************************************** // 

kdj_m = 1
kdj_c = close
kdj_h = ta.highest(high, kdj_ilong)
kdj_l = ta.lowest(low, kdj_ilong)
kdj_RSV = 100 * ((kdj_c - kdj_l) / (kdj_h - kdj_l))
kdj_pK = 0.0
kdj_pD = 0.0
kdj_pK := (kdj_m * kdj_RSV + (kdj_isig - kdj_m) * nz(kdj_pK[1])) / kdj_isig
kdj_pD := (kdj_m * kdj_pK + (kdj_isig - kdj_m) * nz(kdj_pD[1])) / kdj_isig
kdj_pJ = 3 * kdj_pK - 2 * kdj_pD

// *********************************************************************************** //

hline(show_kdj ? kdj_high_threshold : na, title='KDJ High Threshold', color=color.new(color.white, 0), linewidth=1, linestyle=hline.style_solid, editable=0) 
hline(show_kdj ? kdj_low_threshold  : na, title='KDJ Low Threshold' , color=color.new(color.white, 0), linewidth=1, linestyle=hline.style_solid, editable=0) 
hline(show_kdj ? 50                 : na, 'KDJ 50% Line', color=color.new(color.white, 0), linewidth=2, linestyle=hline.style_solid, editable=0)
// *********************************************************************************** // 

plot(show_kdj ? kdj_pK : na, 'KDJ Pk', color=color.new(#ffffff, 0), linewidth=2, trackprice=0)
plot(show_kdj ? kdj_pD : na, 'KDJ Pd', color=color.new(#ff0000, 0), linewidth=2, trackprice=0)
plot(show_kdj ? kdj_pJ : na, 'KDJ Pj', color=color.new(#82fc00, 0), linewidth=2, trackprice=0)

// Extended line kdj_pJ kdj_pD kdj_pK
if show_kdj
    f_ExtLines(3,ExtOffset,kdj_pJ,kdj_pD,kdj_pK,color.new(#82fc00, 0),color.new(#ff0000, 0),color.new(#ffffff, 0),line.style_dotted,line.style_dotted,line.style_dashed,2,2,2)
// *********************************************************************************** // 
// Calcule et affichage du delta kdj_pD-kdj_pJ en %
if show_kdj
    // fonction : calcul de l'evolution et de la direction du delta kdj_pD kdj_pJ en % (acceleration)
    [DeltaPerCent, DeltaRise, DeltaFall, DeltaDir] = f_Delta(kdj_pD, kdj_pJ)

    DeltaText=string(na)
    if DeltaPerCent!=na(DeltaPerCent)
        DeltaText:='[D-J]\nAccel.\n' + DeltaDir + str.tostring(DeltaPerCent,'#.##') + ' %'
    else
        DeltaText:='[D-J]\nAccel.\n' + DeltaDir + 'Crossing ?'

    DeltaLabel = label.new(bar_index+41, kdj_pK, text=DeltaText, yloc=yloc.price,
     color=kdj_pJ>=kdj_pD and DeltaRise ? color.new(#00ff00, 0) : kdj_pJ<kdj_pD and DeltaRise ? color.new(#ff0000, 0) 
     : kdj_pJ>=kdj_pD and DeltaFall ? color.new(#00ddff, 0) : kdj_pJ<kdj_pD and DeltaFall ? color.new(#ff6106, 0) : color.new(#ffffff,30), 
     textcolor=color.black, style=label. style_label_left, size=size.normal)

    label.delete(DeltaLabel[1])
// ****************************************************************************************************************************

    BoxColorKdj=kdj_pJ>kdj_pD and DeltaRise ? color.new(#00ff00, 75) : kdj_pJ<kdj_pD and DeltaRise ? color.new(#ff0000, 75) 
     : kdj_pJ>kdj_pD and DeltaFall ? color.new(#00ddff, 75) : kdj_pJ<kdj_pD and DeltaFall ? color.new(#ff9200, 75) : color.new(#ffffff, 75)

    DeltaKdjMult=5
    BoxKdj=box(na)
    if kdj_pJ>=kdj_pD
        BoxKdj:=box.new(bar_index+50,kdj_pJ+(kdj_pJ*DeltaKdjMult/100),bar_index+70,kdj_pD-(kdj_pJ*DeltaKdjMult/100),
         border_color=color.new(BoxColorKdj,0),border_width=2,text='[pD-pJ] + ' + str.tostring(DeltaKdjMult*2) + ' %',
         text_size=size.small,text_color=#ffffff,text_halign=text.align_left,extend=extend.both, bgcolor=BoxColorKdj )
    else
        BoxKdj:=box.new(bar_index+50,kdj_pJ-(kdj_pD*DeltaKdjMult/100),bar_index+70,kdj_pD+(kdj_pD*DeltaKdjMult/100),
         border_color=color.new(BoxColorKdj,0),border_width=2,text='[pD-pJ] + ' + str.tostring(DeltaKdjMult*2) + ' %',
         text_size=size.small,text_color=#ffffff,text_halign=text.align_left,extend=extend.both, bgcolor=BoxColorKdj )
    box.delete(BoxKdj[1])
// *********************************************************************************** // 

// *** Signaux STOP Achat Ou Vente KDJ *** //
// *** Stop Signals Buy Or Sell KDJ *** //
kdj_stop_long_temp = kdj_pJ[1] >= kdj_pJ[2] and kdj_pJ[2] >= kdj_pJ[3] and ta.falling(kdj_pJ[0], 1)
kdj_stop_short_temp = kdj_pJ[1] <= kdj_pJ[2] and kdj_pJ[2] <= kdj_pJ[3] and ta.rising(kdj_pJ[0], 1)

kdj_signal_stop_long = kdj_stop_long_temp and not kdj_stop_short_temp
kdj_signal_stop_short = kdj_stop_short_temp and not kdj_stop_long_temp

plotshape(not display_combined_layouts and show_kdj ? 50 : na, title='KDJ Stop Long' , style=shape.square, location=location.absolute, 
 color=kdj_signal_stop_long  ? color.new(#82fc00, 0) : na, size=size.tiny)
plotshape(not display_combined_layouts and show_kdj ? 50 : na, title='KDJ Stop Short', style=shape.square, location=location.absolute, 
 color=kdj_signal_stop_short ? color.new(#ff00ff, 0) : na, size=size.tiny)

// *********************************************************************************** // 

// *** Detection Des Signaux Achat Ou Vente KDJ *** //
// *** KDJ Buy Or Sell Signals Detection *** //
kdj_long_temp = ta.rising(kdj_pJ, 1) or kdj_pJ >= kdj_high_threshold
kdj_short_temp = ta.falling(kdj_pJ, 1) or kdj_pJ <= kdj_low_threshold

kdj_signal_long = kdj_long_temp and not kdj_short_temp and not kdj_signal_stop_long
kdj_signal_short = kdj_short_temp and not kdj_long_temp and not kdj_signal_stop_short

// *********************************************************************************** // 

bgcolor(show_kdj and not display_combined_layouts and kdj_signal_long ? color.new(#82fc00, 81) : na, title='KDJ BKG LONG')
bgcolor(show_kdj and not display_combined_layouts and kdj_signal_short ? color.new(#ff0000, 81) : na, title='KDJ BKG SHORT')

// *********************************************************************************** // 
// ************************ END KDJ Indicator [Pine V5] @RL CODE ********************* //
// ************************            © RegisL76                  ******************* //
// *********************************************************************************** //



// ********************************************************************************************************************************************************************** //



// *********************************************************************************** //
//                               Implemented by @Regis_L                               //

// ******************************* RSI DIVERGENCE CODE ******************************* //
//                                     © RegisL76                                      //
// **************************** Based on RSI DIVERGENCE @RL*************************** //
// *********************************************************************************** // 
// *** Default Values RSI : [13, 21, 6, -6, 1.5] *** //
rsi_src_fast = close
rsi_len_fast = input.int(5, minval=1, title='RSI Length Fast',tooltip='Default=5')
rsi_src_slow = close
rsi_len_slow = input.int(26, minval=1, title='RSI Length Slow',tooltip='Default=26')

rsi_overbought_threshold = input.int(6, minval=0, maxval=100, title='RSI OverBought Threshold',tooltip='Default=6')
rsi_oversold_threshold = input.int(-6, minval=-100, maxval=0, title='RSI OverSold Threshold',tooltip='Default=-6')

rsi_highfilter_threshold = input.float(1.5, minval=-15, maxval=15, title='RSI Filter +- Threshold', step=0.5,tooltip='Default=1.5')
rsi_lowfilter_threshold = rsi_highfilter_threshold * -1

// *********************************************************************************** // 
// *** RSI DIVERGENCE *** //
rsi_up_fast = ta.rma(math.max(ta.change(rsi_src_fast), 0), rsi_len_fast)
rsi_down_fast = ta.rma(-math.min(ta.change(rsi_src_fast), 0), rsi_len_fast)
rsi_fast = rsi_down_fast == 0 ? 100 : rsi_up_fast == 0 ? 0 : 100 - 100 / (1 + rsi_up_fast / rsi_down_fast)
rsi_up_slow = ta.rma(math.max(ta.change(rsi_src_slow), 0), rsi_len_slow)
rsi_down_slow = ta.rma(-math.min(ta.change(rsi_src_slow), 0), rsi_len_slow)
rsi_slow = rsi_down_slow == 0 ? 100 : rsi_up_slow == 0 ? 0 : 100 - 100 / (1 + rsi_up_slow / rsi_down_slow)

// *********************************************************************************** // 
// *** DIVERGENCE *** //
rsi_divergence = rsi_fast - rsi_slow

//****************************************************************************************************************************//
// *** Bands Lines*** //
rsi_linesup = hline(show_rsi ? rsi_overbought_threshold : na, title='RSI Sup % Line', color=color.green, linewidth=1, linestyle=hline.style_solid, editable=0) 
rsi_lineinf = hline(show_rsi ? rsi_oversold_threshold : na  , title='RSI Inf % Line', color=color.red, linewidth=1, linestyle=hline.style_solid, editable=0)
rsi_line0 = hline(show_rsi ? 0 : na, title='RSI 0% Line', color=color.new(#ffffff,0), linewidth=1, linestyle=hline.style_solid, editable=0)

// *** Bands Plots *** //
rsi_bandsup = plot(show_rsi ? rsi_overbought_threshold : na, title='RSI Band Sup %', color=na, linewidth=1, trackprice=1, editable=0)
rsi_bandinf = plot(show_rsi ? rsi_oversold_threshold : na, title='RSI Band Inf %', color=na, linewidth=1, trackprice=1, editable=0)
rsi_band0 = plot(show_rsi ? 0 : na, title='RSI Neutral Band 0%', color=na, linewidth=1, trackprice=1, editable=0)
//
rsi_plot_div = plot(show_rsi ? rsi_divergence : na, title='RSI Divergence', color=priceup ? color.new(#82fc00, 0) : color.new(#ff0000, 0), linewidth=2, trackprice=1, style=plot.style_line)

//****************************************************************************************************************************//
// *** Divergence + et Divergence - *** //
rsi_div_pos = rsi_divergence
rsi_div_neg = rsi_divergence * -1

// *** rsi_plot_div_neg *** //
plot(show_rsi ? rsi_div_neg : na, title='RSI Mirror Divergence -', color=color.new(color.white, 85), style= plot.style_area, linewidth=2, trackprice=1)

//****************************************************************************************************************************//

// *** Background High Low Thresholds *** //
rsi_overbandsup = rsi_div_pos > rsi_overbought_threshold
rsi_underbandinf = rsi_div_pos < rsi_oversold_threshold

fill(rsi_plot_div, rsi_bandsup, color=rsi_overbandsup and show_rsi  ? color.new(#82fc00, 60) : na, title='RSI Bkg>= Band Sup')
fill(rsi_plot_div, rsi_bandinf, color=rsi_underbandinf and show_rsi ? color.new(#ff0000, 60) : na, title='RSI Bkg <= Band inf')

// *********************************************************************************** // 
// *** Signaux STOP Achat Ou Vente RSI DIVERGENCE  *** Dépendant du RSI (Over Or Under) THRESHOLD //
// *** STOP Signals Buy Or Sell RSI DIVERGENCE *** RSI (Over Or Under) Threshold dependent //
rsi_stop_long_temp = rsi_divergence[1] >= rsi_overbought_threshold and rsi_divergence[0] <= rsi_overbought_threshold
rsi_stop_short_temp = rsi_divergence[1] <= rsi_oversold_threshold and rsi_divergence[0] >= rsi_oversold_threshold

rsi_signal_stop_long = rsi_stop_long_temp and not rsi_stop_short_temp
rsi_signal_stop_short = rsi_stop_short_temp and not rsi_stop_long_temp

// *********************************************************************************** // 

// *** Signaux RSI Signal STOP Long & Short *** //
// *** Show RSI Signal STOPLong *** //
plotshape(not display_combined_layouts and show_rsi ? 0 : na, style=shape.square, location=location.absolute, color=rsi_signal_stop_long  
 ? color.new(#82fc00, 0) : na, title='RSI STOP Long Signal', size=size.tiny)

// *** Show RSI Signal STOP Short *** //
plotshape(not display_combined_layouts and show_rsi ? 0 : na, style=shape.square, location=location.absolute, color=rsi_signal_stop_short 
 ? color.new(#ff00ff, 0) : na, title='RSI STOP Short Signal', size=size.tiny)

//************************************************************************************ //

// *** Detection Des Signaux Achat Ou Vente RSI *** Dépendant du RSI (High Or Low) THRESHOLD //
// *** RSI Buy Or Sell Signal Detection *** RSI (High Or Low) Threshold dependent //
rsi_long_temp =  ta.rising(rsi_divergence, 1)  or ta.falling(rsi_divergence, 1) and rsi_divergence >= rsi_highfilter_threshold
rsi_short_temp = ta.falling(rsi_divergence, 1) or ta.rising(rsi_divergence, 1)  and rsi_divergence <= rsi_lowfilter_threshold

rsi_signal_long = rsi_long_temp and not rsi_short_temp and not rsi_signal_stop_long
rsi_signal_short = not rsi_long_temp and rsi_short_temp and not rsi_signal_stop_short

// *********************************************************************************** //

// *** Background Long & Short Zones *** //
rsi_bkg_gen_buy = rsi_signal_long
rsi_bkg_gen_sell = rsi_signal_short

//****************************************************************************************************************************//

// *** Background Long & Short Zones *** //
bgcolor(rsi_signal_long  and not display_combined_layouts and show_rsi ? color.new(#82fc00, 81) : na, title='RSI:Bkg Buy Zone')
bgcolor(rsi_signal_short and not display_combined_layouts and show_rsi ? color.new(#ff0000, 81) : na, title='RSI:Bkg Sell Zone')

// *********************************************************************************** //
// ****************************** END RSI DIVERGENCE CODE **************************** //
// ******************************      © RegisL76         **************************** //
// *********************************************************************************** //



// ********************************************************************************************************************************************************************** //



// ******************************** STOCHASTIQUE CODE ******************************** // 
//                                     © RegisL76                                      //
// ***************************** Based on STOCHASTIC @RL****************************** //
// *********************************************************************************** //

// *** Default Values STOCHASTIC : [21, 3, 3] *** //
// *** Valeur par defaut : [21, 3, 3] *** //
sto_periodK = input.int(26, title='STO K', minval=1,tooltip='Default=26')
sto_periodD = input.int(5, title='STO D', minval=1,tooltip='Default=5')
sto_smoothK = input.int(3, title='STO Smooth K', minval=1,tooltip='Default=3')

sto_highzone = input.int(80 , title='STO High Zone', minval=50, maxval=100, step=1,tooltip='Default=80')
sto_lowzone  = input.int(20 , title='STO Low Zone' , minval=0, maxval=50  , step=1,tooltip='Default=20')
sto_maxzone  = input.int(100, title='STO Max Zone' , minval=50, maxval=100, step=1,tooltip='Default=100')
sto_minzone  = input.int(0  , title='STO Min Zone' , minval=0, maxval=050 , step=1,tooltip='Default=0')
// *********************************************************************************** // 

// *** STOCHASTIC *** //
sto_k = ta.sma(ta.stoch(close, high, low, sto_periodK), sto_smoothK)
sto_d = ta.sma(sto_k, sto_periodD)

// *********************************************************************************** // 

// *** Moyenne entre K et D *** // *** Detecte une eventuelle inversion de tendance si k et Moy en opposition *** //
// *** Average between K and D *** // *** Detects a possible trend reversal if k and Moy in opposition *** //
sto_moy = (sto_k + sto_d) / 2

// *********************************************************************************** // 

// *** Band High - Low - Neutral *** //
sto_highline = hline(show_sto ? sto_highzone : na, title='STO Upper Band'  , color=color.new(#82fc00, 0), linewidth=1, linestyle=hline.style_solid)
sto_lowline  = hline(show_sto ? sto_lowzone  : na , title='STO Lower Band'  , color=color.new(#ff0000, 0), linewidth=1, linestyle=hline.style_solid)
sto_line50   = hline(show_sto ? 50           : na          , title='STO Neutral Line', color=color.new(#ffffff, 0), linewidth=1, linestyle=hline.style_solid)
sto_linemax  = hline(show_sto ? sto_maxzone  : na          , title='STO Max Line'    , color=color.new(#00ff00, 0), linewidth=1, linestyle=hline.style_solid)
sto_linemin  = hline(show_sto ? sto_minzone  : na          , title='STO Min Line'    , color=color.new(#ff0000, 0), linewidth=1, linestyle=hline.style_solid)

// *********************************************************************************** // 

// *** Plot Low - 50 % - High Lines ***//
sto_plotlowline  = plot(show_sto ? sto_lowzone  : na, title='Low Line' , color=na, editable=0)
sto_plothighline = plot(show_sto ? sto_highzone : na, title='High Line', color=na, editable=0)
sto_plot50line   = plot(show_sto ? 50           : na, title='50% Line' , color=na, editable=0)
sto_plotmaxline  = plot(show_sto ? sto_maxzone  : na, title='95% Line' , color=na, editable=0)
sto_plotminline  = plot(show_sto ? sto_minzone  : na, title='05% Line' , color=na, editable=0)

// *********************************************************************************** //

// Plot STOCHASTIC Curves *** //
sto_k1 = plot(show_sto ? sto_k : na, title='STO %K', color=color.new(#82fc00, 0), linewidth=2, trackprice=0)
sto_d1 = plot(show_sto ? sto_d : na, title='STO %D', color=color.new(#ff0000, 0), linewidth=2, trackprice=0)

// Extended line sto_k sto_d 
if show_sto
    f_ExtLines(2,ExtOffset,sto_k,sto_d,float(na),color.new(#82fc00, 0),color.new(#ff0000, 0),color(na),line.style_dotted,line.style_dotted,string(na),2,2,int(na))

// *********************************************************************************** // 
// Calcule et affichage du delta sto_k-sto_d en %
if show_sto
    // fonction : calcul de l'evolution et de la direction du delta sto_k sto_d en % (acceleration)
    [DeltaPerCent, DeltaRise, DeltaFall, DeltaDir] = f_Delta(sto_k, sto_d)
    
    DeltaText=string(na)
    if DeltaPerCent!=na(DeltaPerCent)
        DeltaText:='[K-D]\nAccel.\n' + DeltaDir + str.tostring(DeltaPerCent,'#.##') + ' %'
    else
        DeltaText:='[K-D]\nAccel.\n' + DeltaDir + 'Crossing ?'

    DeltaLabel = label.new(bar_index+41, (sto_k+sto_d)/2, text=DeltaText, yloc=yloc.price,
     color=sto_k>=sto_d and DeltaRise ? color.new(#00ff00, 0) : sto_k<sto_d and DeltaRise ? color.new(#ff0000, 0) 
     : sto_k>=sto_d and DeltaFall ? color.new(#00ddff, 0) : sto_k<sto_d and DeltaFall ? color.new(#ff6106, 0) : color.new(#ffffff,30), 
     textcolor=color.black, style=label. style_label_left, size=size.normal)

    label.delete(DeltaLabel[1])
// ****************************************************************************************************************************

    BoxColorSto=sto_k>sto_d and DeltaRise ? color.new(#00ff00, 75) : sto_k<sto_d and DeltaRise ? color.new(#ff0000, 75) 
     : sto_k>sto_d and DeltaFall ? color.new(#00ddff, 75) : sto_k<sto_d and DeltaFall ? color.new(#ff9200, 75) : color.new(#ffffff, 75)

    DeltaStoMult=5
    BoxSto=box(na)
    if sto_k>=sto_d
        BoxSto:=box.new(bar_index+50,sto_k+(sto_k*DeltaStoMult/100),bar_index+70,sto_d-(sto_k*DeltaStoMult/100),
         border_color=color.new(BoxColorSto,0),border_width=2,text='[K-D] + ' + str.tostring(DeltaStoMult*2) + ' %',
         text_size=size.small,text_color=#ffffff,text_halign=text.align_left,extend=extend.both, bgcolor=BoxColorSto )
    else
        BoxSto:=box.new(bar_index+50,sto_d+(sto_d*DeltaStoMult/100),bar_index+70,sto_k-(sto_d*DeltaStoMult/100),
         border_color=color.new(BoxColorSto,0),border_width=2,text='[K-D] + ' + str.tostring(DeltaStoMult*2) + ' %',
         text_size=size.small,text_color=#ffffff,text_halign=text.align_left,extend=extend.both, bgcolor=BoxColorSto )
    box.delete(BoxSto[1])
    
// *** Over Bought & Over Sold Zones *** //
sto_overbought = sto_k >= sto_highzone
sto_oversold = sto_k <= sto_lowzone
fill(sto_plothighline, sto_k1, color=show_sto and sto_overbought          ? color.new(#82fc00, 60) : na, title='STO: Bkg Over Bought Zone')
fill(sto_plotlowline , sto_k1, color=show_sto and sto_oversold            ? color.new(#ff0000, 60) : na, title='STO: Bkg Over Sold Zone')
fill(sto_plothighline, sto_plotmaxline, color=show_sto and sto_overbought ? color.new(#ffffff, 70) : na, title='STO: Bkg Max Over Bought Zone')
fill(sto_plotlowline , sto_plotminline, color=show_sto and sto_oversold   ? color.new(#ffffff, 70) : na, title='STO: Bkg Max Over Sold Zone')
// *********************************************************************************** // 

// *** STO : Signal STOP Achat Ou Vente STOCHASTIQUE Basé sur la Divergence entre K et Moyenne de K & D *** //
// *** STO: STOCHASTIC Buy Or Sell STOP Signal Based on the K & D Divergence between K and Average *** //

// *** STO : Conditions Signal STOP Long & Short ***
// *** STO : Conditions Avertissement STOP Long & Short ***
sto_signal_stop_long_temp = ta.rising(sto_moy, 1) and ta.falling(sto_k, 1)
sto_signal_stop_short_temp = ta.falling(sto_moy, 1) and ta.rising(sto_k, 1)

sto_signal_stop_long = sto_signal_stop_long_temp and not sto_signal_stop_short_temp
sto_signal_stop_short = sto_signal_stop_short_temp and not sto_signal_stop_long_temp

plotshape(not display_combined_layouts and show_sto ? 50 : na, title='STO Stop Long', style=shape.square, location=location.absolute, 
 color=ta.rising(sto_moy, 1) and ta.falling(sto_k, 1) ? color.new(#82fc00, 0) : na, size=size.tiny)
plotshape(not display_combined_layouts and show_sto ? 50 : na, title='STO Stop Short', style=shape.square, location=location.absolute, 
 color=ta.falling(sto_moy, 1) and ta.rising(sto_k, 1) ? color.new(#ff00ff, 0) : na, size=size.tiny)

// *********************************************************************************** //

// *** Detection Des Signaux Achat Ou Vente STOCHASTIQUE *** //
// *** STOCHASTIC Buy Or Sell Signals Detection *** //
sto_long_temp = ta.rising(sto_moy, 1) and ta.rising(sto_k, 1)
sto_short_temp = ta.falling(sto_moy, 1) and ta.falling(sto_k, 1)

sto_signal_long  = sto_long_temp  and not sto_short_temp and not sto_signal_stop_long
sto_signal_short = sto_short_temp and not sto_long_temp  and not sto_signal_stop_short

// *********************************************************************************** //

// *** Background STOCH *** //
bgcolor(sto_signal_long  and not display_combined_layouts and show_sto ? color.new(#82fc00, 81) : na, title='STO:Bkg Long Zone')
bgcolor(sto_signal_short and not display_combined_layouts and show_sto ? color.new(#ff0000, 81) : na, title='STO:Bkg Short Zone')

// *********************************************************************************** // 

// ***background STO General trend conditions Long & Short Zone (and watch zone) *** //
// *** background STO Conditions générales de tendance Zone Long & Short (et zone de veille)  ***
sto_bkg_gen_buy = sto_signal_long
sto_bkg_gen_sell = sto_signal_short

// *********************************************************************************** //
// ******************************** END STOCHASTIQUE CODE **************************** //
// ********************************      © RegisL76       **************************** //
// *********************************************************************************** //



// ********************************************************************************************************************************************************************** //



// ************************************ EMA 3 CODE *********************************** //
//                                     © RegisL76                                      //
// *********************************************************************************** //

// *** INPUTS EMA's Slow - Middle - Fast ***
ema_len_slow = input.int(5, minval=1, title='EMA Length Slow',tooltip='Default=5')
ema_len_middle = input.int(14, minval=1, title='EMA Length Median',tooltip='Default=14')
ema_len_fast = input.int(26, minval=1, title='EMA Length Fast',tooltip='Default=26')
ema_len_high_low = input.int(31, minval=1, maxval=300, title='EMA Lenght High/Low Price',tooltip='Default=31')

// *** Lenght Very SLOW : (Len Very Slow = Len Slow / Len Very Slow)
ema_len_VSlow = input.int(2, minval=1, maxval=3, title='EMA Len V_Slow=Len Slow / x ? ->', step=1,tooltip='Default=2')

ema_src_slow   = input(close, title='EMA Source Slow'      ,tooltip='Default=close')
ema_src_median = input(close, title='EMA Source EMA_Median',tooltip='Default=close')
ema_src_fast   = input(close, title='EMA Source Fast'      ,tooltip='Default=close')
ema_src_VSlow  = input(close, title='EMA Source Very Slow' ,tooltip='Default=close')
ema_src_high   = input(high , title='EMA Source High Price',tooltip='Default=high')
ema_src_low    = input(low  , title='EMA Source Low Price' ,tooltip='Default=low')

// *********************************************************************************** // 

// *** ZOOM Factors (Difference & Very Slow MA)***
ema_zoom_diff  = input.float(1.7, title='EMA Zoom Difference Slow-Fast', minval=1  , maxval=3.0, step=0.1,tooltip='Default=1.7')
ema_zoom_VSlow = input.float(3.4, title='EMA Zoom Very Slow'           , minval=3.1, maxval=6  , step=0.1,tooltip='Default=3.4')

// *** EMA's : Ema_Slow, Ema_Median, Ema_Fast ***
ema_out_slow   = ta.ema(ema_src_slow, ema_len_slow)
ema_out_median = ta.ema(ema_src_median, ema_len_middle)
ema_out_fast   = ta.ema(ema_src_fast, ema_len_fast)

// *********************************************************************************** // 

// *** 3 Curves EMA : Ema_Slow, Ema_Median, Ema_Fast ***
ema_slow   = plot(show_ema ? ema_out_slow   : na, title='EMA Slow'  , color=color.new(#00f6ff, 0), linewidth=1, trackprice=0)  // 1-bleu clair = ema_slow = light Blue
ema_median = plot(show_ema ? ema_out_median : na, title='EMA Median', color=color.new(#FFFFFF, 0), linewidth=2, trackprice=1)  // 2-Blanc = ema_median = White
ema_fast   = plot(show_ema ? ema_out_fast   : na, title='EMA Fast'  , color=color.new(#ff0000, 0), linewidth=1, trackprice=0)  // 3-rouge = ema_fast = Red

// *********************************************************************************** // 

// *** Difference Ema_Slow-Ema_Fast ***
ema_diff_sl_fa = ema_out_slow - ema_out_fast

// *********************************************************************************** // 

// *** Amplified Deviation MA's Slow_Fast From The Ema_Median *** //
// *** Déviation Amplifiée Par Rapport A La Courbe Mediane    *** //
ema_diff_zoom = ema_out_median + ema_diff_sl_fa * ema_zoom_diff

// *** Moving Average VERY SLOW MA Amplified *** //
ema_diff_VSlow = ta.ema(ema_src_VSlow, int(ema_len_slow / ema_len_VSlow)) - ema_out_median
ema_out_VSlow_z = ema_zoom_VSlow * ema_diff_VSlow + ema_out_median

// *** Plot Very Slow EMA Amplified *** //
// *** Tracé Very Slow MA Amplifiée *** //
ema_VSlow_z = plot(show_ema ? ema_out_VSlow_z : na, color=color.new(color.orange, 0), linewidth=2, title='EMA Very Slow Amplified', trackprice=1)

// *********************************************************************************** //

graph_text = 'Graph --> ERROR !'
bkg_text = ' ERROR'

// *** Vertical Center Layouts *** //
v_center_layouts = ema_out_median

if show_kdj
    graph_text := 'Graph --> KDJ'
    bkg_text := ' KDJ'
    v_center_layouts := 50
    v_center_layouts
else if show_rsi
    graph_text := 'Graph --> RSI'
    bkg_text := ' RSI'
    v_center_layouts := 0
    v_center_layouts
else if show_sto
    graph_text := 'Graph --> STO'
    bkg_text := ' STO'
    v_center_layouts := 50
    v_center_layouts
else if show_ema
    graph_text := 'Graph --> EMA'
    bkg_text := ' EMA'
    v_center_layouts := ema_out_median
    v_center_layouts

if show_ema 
 and (show_kdj or show_rsi or show_sto) 
 or show_kdj and (show_ema or show_rsi or show_sto) 
 or show_rsi and (show_ema or show_kdj or show_sto) 
 or show_sto and (show_ema or show_kdj or show_rsi) 
    graph_text := 'WARNING : Settings -->\nChoose Only One Of The\n4 Indicators To Display\n'
    bkg_text := ' ERROR !'
    bkg_text

if  not show_ema and not show_kdj and not show_rsi and not show_sto
    graph_text := 'Graph : Settings -->\nChoose At Least\nOne Indicator To Display\n'
    bkg_text := ' ERROR !'
    bkg_text

// *********************************************************************************** //

// HIGH - LOW Price & Middle High/Low Price (Not Ploted)
ema_middlel_hl = (ta.ema(ema_src_high[0], ema_len_high_low) + ta.ema(ema_src_low[0], ema_len_high_low)) / 2
ema_hi = ta.ema(ema_src_high, ema_len_high_low)
ema_lo = ta.ema(ema_src_low, ema_len_high_low)

// *** Create Long & Short Thresholds   ***
// *** Creation Seuils Long & Short ***
ema_threshold = (ema_out_VSlow_z + ema_diff_zoom) / 2

// *********************************************************************************** //

// *** Conditions Warning STOP Long & Short ***
// *** Conditions Avertissement STOP Long & Short ***
ema_signal_stop_long_temp = ema_out_VSlow_z >= ema_threshold and ta.rising(ema_out_VSlow_z[1], 2) and pricedown
ema_signal_stop_short_temp = ema_out_VSlow_z <= ema_threshold and ta.falling(ema_out_VSlow_z[1], 2) and priceup

ema_signal_stop_long = ema_signal_stop_long_temp and not ema_signal_stop_short_temp
ema_signal_stop_short = ema_signal_stop_short_temp and not ema_signal_stop_long_temp

// *********************************************************************************** //

// *** Layouts of the EMA Stop Long & Short Warnings ***
// *** Tracés des Avertissements EMA STOP Long & Short ***
plotshape(not display_combined_layouts and show_ema ? v_center_layouts : na, title='EMA Stop_Long Signal', style=shape.square, 
 location=location.absolute, color=ema_signal_stop_long ? color.new(#82fc00, 0) : na, size=size.tiny)

plotshape(not display_combined_layouts and show_ema ? v_center_layouts : na, title='EMA Stop_Short Signal', style=shape.square, 
 location=location.absolute, color=ema_signal_stop_short ? color.new(#ff00ff, 0) : na, size=size.tiny)

// ******************************************************************************** // 

// *** Long & Short Conditions ***
// *** Conditions Vente ou Achat ***

ema_condbuy_anda = priceup and ta.rising(ema_diff_zoom, 1) and not pricedown and ta.pvt > ta.pvt[1]
ema_condsell_anda = pricedown and ta.falling(ema_diff_zoom, 1) and not priceup and ta.pvt < ta.pvt[1]

ema_condbuy_andb = ta.rising(ema_out_VSlow_z, 1)
ema_condsell_andb = ta.falling(ema_out_VSlow_z, 1)

// ***  Suite des conditions *** //
// *** Continuation of conditions *** //
ema_condbuytemp = ema_condbuy_anda and ema_condbuy_andb
ema_condselltemp = ema_condsell_anda and ema_condsell_andb

ema_condbuy_andg = not ema_condselltemp
ema_condsell_andg = not ema_condbuytemp

ema_signal_long = ema_condbuytemp and ema_condbuy_andg
ema_signal_short = ema_condselltemp and ema_condsell_andg

// *********************************************************************************** //

// *** Background Zones Long & Short ***
// *** Background Zones Long & Short ***
ema_bkg_buy = ema_signal_long
ema_bkg_sell = ema_signal_short

// *********************************************************************************** //

// ***  Long & Short Zone Trend Conditions ***
// ***  Conditions De Tendance Zone Long & Short ***
ema_condbkg_buy = ema_out_VSlow_z >= ema_out_slow and ema_out_VSlow_z > ema_threshold or ema_signal_long
ema_condbkg_sell = ema_out_VSlow_z <= ema_out_fast and ema_out_VSlow_z < ema_threshold or ema_signal_short

// *********************************************************************************** //       

// *** Background General EMA Trend Conditions Long & Short Zone (And Standbye Zone) ***
// *** Background EMA Conditions Générales De Tendance Zone Long & Short (Et Zone De Veille)  ***
ema_condtempbuy = ema_bkg_buy and ema_condbkg_buy and not ema_signal_stop_long
ema_condtempsell = ema_bkg_sell and ema_condbkg_sell and not ema_signal_stop_short

ema_bkg_gen_buy = ema_condtempbuy and not ema_condtempsell
ema_bkg_gen_sell = ema_condtempsell and not ema_condtempbuy

// *** Background EMA *** //
bgcolor(ema_bkg_gen_buy  and not display_combined_layouts and show_ema ? color.new(#82fc00, 81) : na, title='EMA:Bkg Long Zone')
bgcolor(ema_bkg_gen_sell and not display_combined_layouts and show_ema ? color.new(#ff0000, 81) : na, title='EMA:Bkg Short Zone')

// ******************************************************************************** //
// ********************************* END EMA's 3 CODE ***************************** //
// *********************************    © RegisL76    ***************************** //
// ******************************************************************************** //



// ********************************************************************************************************************************************************************** //



// ********************************* MAIN CODE ************************************ //
//                                  © RegisL76                                      //
// ******************************************************************************** //

main_offset_lab_trend = input.int(26,  minval=-120, maxval=80,  title='Main:Offset Trend Label', tooltip='[-120 ; 80] default=26')
main_offset_lab_stop  = input.int(41,  minval=-105, maxval=105, title='Main:Offset Stop Label' , tooltip='[-105 ; 105] default=41')
main_offset_lab_info  = input.int(-44, minval=-160, maxval=-10, title='Main:Offset Infos Label', tooltip='[-160 ; -10] default=-44')

// ************************************************************* //

// *** General Conditions Warning STOP Long & Short *** //
// *** Conditions Generales Avertissement STOP Long & Short ***
main_signal_stop_long_temp = ema_signal_stop_long or sto_signal_stop_long or rsi_signal_stop_long or kdj_signal_stop_long
main_signal_stop_short_temp = ema_signal_stop_short or sto_signal_stop_short or rsi_signal_stop_short or kdj_signal_stop_short

main_signal_stop_long = main_signal_stop_long_temp and not main_signal_stop_short_temp
main_signal_stop_short = main_signal_stop_short_temp and not main_signal_stop_long_temp

// *** INIT *** //
main_power_stop_long = 0
main_power_stop_short = 0
main_power_stop = 0

// stop_pow_text =""

color_text_stop = color.new(#ffffff, 0)

if ema_signal_stop_long
    main_power_stop_long := main_power_stop_long + 1
    main_power_stop_long

if ema_signal_stop_short
    main_power_stop_short := main_power_stop_short + 1
    main_power_stop_short

if sto_signal_stop_long
    main_power_stop_long := main_power_stop_long + 1
    main_power_stop_long

if rsi_signal_stop_short
    main_power_stop_short := main_power_stop_short + 1
    main_power_stop_short

if rsi_signal_stop_long
    main_power_stop_long := main_power_stop_long + 1
    main_power_stop_long

if sto_signal_stop_short
    main_power_stop_short := main_power_stop_short + 1
    main_power_stop_short

if kdj_signal_stop_long
    main_power_stop_long := main_power_stop_long + 1
    main_power_stop_long

if kdj_signal_stop_short
    main_power_stop_short := main_power_stop_short + 1
    main_power_stop_short

// ************************************************************* //

// *** Force Du Signal STOP Long & Short *** //
// *** Signal Strength STOP Long & Short *** //
stop_pow_text = '??'

main_power_stop := math.abs(main_power_stop_long - main_power_stop_short)

if main_power_stop_long > main_power_stop_short
    color_text_stop := color.new(#ff0000, 0)
    stop_pow_text := 'STOP LG: '
    stop_pow_text
else if main_power_stop_long < main_power_stop_short
    color_text_stop := color.new(#0aa01a, 0)
    stop_pow_text := 'STOP SH: '
    stop_pow_text
else if main_power_stop_long == main_power_stop_short
    color_text_stop := color.new(#000000, 0)
    stop_pow_text := 'NO STOP:'
    stop_pow_text

// ******************************************************************************** // 

// ***   Main LONG & SHORT Conditions     *** //
// *** Conditions Generales Vente & Achat *** //
main_power = 0
main_power_long = 0
main_power_short = 0

// ******************************************************************************** // 

// *** 4 Conditions Sur 4 (Exclusif) *** //
// *** 4 Out of 4 Conditions (Exclusive) *** //
signal_long_temp4_4 = rsi_signal_long and sto_signal_long and ema_signal_long and kdj_signal_long

signal_short_temp4_4 = rsi_signal_short and sto_signal_short and ema_signal_short and kdj_signal_short

if signal_long_temp4_4
    main_power_long := 4
    main_power_long

if signal_short_temp4_4
    main_power_short := 4
    main_power_short

// **************************************** //

// *** 3 Seules Conditions Sur 4 (Exclusif) *** //
// *** Only 3 Conditions Out of 4 (Exclusive) *** //
signal_long_temp3_4 = (sto_signal_long and rsi_signal_long and ema_signal_long 
 or sto_signal_long and ema_signal_long and kdj_signal_long 
 or sto_signal_long and rsi_signal_long and kdj_signal_long 
 or rsi_signal_long and ema_signal_long and kdj_signal_long) 
 and not signal_long_temp4_4

signal_short_temp3_4 = (sto_signal_short and rsi_signal_short and ema_signal_short 
 or sto_signal_short and ema_signal_short and kdj_signal_short 
 or sto_signal_short and rsi_signal_short and kdj_signal_short 
 or rsi_signal_short and ema_signal_short and kdj_signal_short) 
 and not signal_short_temp4_4

if signal_long_temp3_4
    main_power_long := 3
    main_power_long

if signal_short_temp3_4
    main_power_short := 3
    main_power_short

// **************************************** //

// *** 2 Seules Conditions sur 4 (Exclusif) *** //
// *** Only 2 Conditions out of 4 (Exclusive) *** //
signal_long_temp2_4 = (rsi_signal_long and sto_signal_long 
 or rsi_signal_long and ema_signal_long 
 or rsi_signal_long and kdj_signal_long 
 or sto_signal_long and ema_signal_long 
 or sto_signal_long and kdj_signal_long 
 or ema_signal_long and kdj_signal_long) 
 and not signal_long_temp3_4 
 and not signal_long_temp4_4

signal_short_temp2_4 = (rsi_signal_short and sto_signal_short 
 or rsi_signal_short and ema_signal_short 
 or rsi_signal_short and kdj_signal_short 
 or sto_signal_short and ema_signal_short 
 or sto_signal_short and kdj_signal_short 
 or ema_signal_short and kdj_signal_short) 
 and not signal_short_temp3_4 
 and not signal_short_temp4_4

if signal_long_temp2_4
    main_power_long := 2
    main_power_long

if signal_short_temp2_4
    main_power_short := 2
    main_power_short

// **************************************** // 

// *** 1 Seule Condition Sur 4 (Exclusif) *** //
// *** Only 1 Condition Out of 4 (Exclusive) *** //
signal_long_temp1_4 = 
 (rsi_signal_long or sto_signal_long or ema_signal_long or kdj_signal_long) 
 and not signal_long_temp2_4 
 and not signal_long_temp3_4 
 and not signal_long_temp4_4

signal_short_temp1_4 = 
 (rsi_signal_short or sto_signal_short or ema_signal_short or kdj_signal_short) 
 and not signal_short_temp2_4 
 and not signal_short_temp3_4 
 and not signal_short_temp4_4

if signal_long_temp1_4
    main_power_long := 1
    main_power_long

if signal_short_temp1_4
    main_power_short := 1
    main_power_short

// **************************************** //

main_power := math.abs(main_power_long - main_power_short)

main_signal_long_temp = 
 signal_long_temp1_4 and at_least_x_among_4_combined_bkg <= 1 
 or signal_long_temp2_4 and at_least_x_among_4_combined_bkg <= 2 
 or signal_long_temp3_4 and at_least_x_among_4_combined_bkg <= 3 
 or signal_long_temp4_4 and at_least_x_among_4_combined_bkg <= 4

main_signal_short_temp = 
 signal_short_temp1_4 and at_least_x_among_4_combined_bkg <= 1 
 or signal_short_temp2_4 and at_least_x_among_4_combined_bkg <= 2 
 or signal_short_temp3_4 and at_least_x_among_4_combined_bkg <= 3 
 or signal_short_temp4_4 and at_least_x_among_4_combined_bkg <= 4

// ******************************************************************************** // 

// *** Force Du Signal Long & Short *** //
// *** Signal Strength Long & Short *** //

trend_pow_text = ''
trend_color_long  = color.new(#82fc00, 0)
trend_color_short = color.new(#ff0000, 0)

trend_color_text = color.new(na, 0)

if main_power_long > main_power_short
    trend_pow_text := 'LG PWR :'
    trend_color_text := trend_color_long
else if main_power_long < main_power_short
    trend_pow_text := 'SH PWR :'
    trend_color_text := trend_color_short
    trend_color_text
else
    trend_pow_text := 'WAIT & SEE:'
    trend_color_text := color.new(#ffffff, 0)
    trend_color_text

// ******************************************************************************** // 

// *** Main LONG & SHORT Conditions Finales *** //
// *** Main LONG & SHORT Final Conditions *** //
main_signal_long  = main_signal_long_temp  and not main_signal_stop_long  and main_power_long > main_power_short
main_signal_short = main_signal_short_temp and not main_signal_stop_short and main_power_long < main_power_short

// ******************************************************************************** // 

// *** Layouts of the General Stop Long & Short Warnings ***
// *** Tracés des Avertissements Generaux STOP Long & Short ***
plotshape(display_combined_layouts ? v_center_layouts : na, title='MAIN Stop_Long Signal', style=shape.square, 
 location=location.absolute, color=main_signal_stop_long ? color.new(#82fc00, 0) : na, size=size.tiny)

plotshape(display_combined_layouts ? v_center_layouts : na, title='MAIN Stop_Short Signal', style=shape.square, 
 location=location.absolute, color=main_signal_stop_short ? color.new(#ff00ff, 0) : na, size=size.tiny)

// ******************************************************************************** // 

// *** Main Background : Trend Conditions Long & Short Zone (And Standbye Zone) ***
// *** background général : Conditions De Tendance Zone Long & Short (Et Zone De Veille)  ***
bgcolor(display_combined_layouts and main_signal_long and not main_signal_short and main_power >= at_least_x_among_4_combined_bkg ? color.new(#82fc00, 65) : na, title='Main:Bkg Long Zone')
bgcolor(display_combined_layouts and main_signal_short and not main_signal_long and main_power >= at_least_x_among_4_combined_bkg ? color.new(#ff0000, 65) : na, title='Main:Bkg Short Zone')

// ******************************************************************************** //

// *** Define F_print function To Show Infos *** //
f_print(_offsetx, _offsety, _lab_styl, _bkg_color, _text, _color_text, _size) =>
    // *** Create label *** //.
    var _label = label(na)
    label.delete(_label)
    _label := label.new(bar_index + _offsetx, _offsety, _text, xloc.bar_index, yloc.price, _bkg_color, _lab_styl, _color_text, _size, text.align_left)
    _label

// ******************************************************************************** // 

// *** Init Texts & Colors *** //
text_long_rsi = 'nul '
text_long_sto = 'nul '
text_long_ema = 'nul '
text_long_kdj = 'nul '

text_short_rsi = 'nul '
text_short_sto = 'nul '
text_short_ema = 'nul '
text_short_kdj = 'nul '

text_stop_long_rsi = 'nul '
text_stop_long_sto = 'nul '
text_stop_long_ema = 'nul '
text_stop_long_kdj = 'nul '

text_stop_short_rsi = 'nul '
text_stop_short_sto = 'nul '
text_stop_short_ema = 'nul '
text_stop_short_kdj = 'nul '

close_up_down_text = ' : ---- '
high_up_down_text = ' : ---- '
low_up_down_text = ' : ---- '
open_up_down_text = ' : ---- '

color_0 = color.new(#ffffff, 0)
color_text = color.new(#ffffff, 0)
bkg_color = color.new(#081156, 0)
bkg_color_stop = color.new(#ffffff, 0)  //0000ff

// **************************** //
if priceup
    close_up_down_text := ' : RISING  '
    close_up_down_text
else if pricedown
    close_up_down_text := ' : FALLING '
    close_up_down_text
else
    close_up_down_text := ' : ??????? '
    close_up_down_text

// **************************** //
if high_up
    high_up_down_text := ' : RISING  '
    high_up_down_text
else if high_down
    high_up_down_text := ' : FALLING '
    high_up_down_text
else
    high_up_down_text := ' : ??????? '
    high_up_down_text

// **************************** //
if low_up
    low_up_down_text := ' : RISING  '
    low_up_down_text
else if low_down
    low_up_down_text := ' : FALLING '
    low_up_down_text
else
    low_up_down_text := ' : ??????? '
    low_up_down_text

// **************************** //
if open_up
    open_up_down_text := ' : RISING  '
    open_up_down_text
else if open_down
    open_up_down_text := ' : FALLING '
    open_up_down_text
else
    open_up_down_text := ' : ??????? '
    open_up_down_text

// **************************** // 

if rsi_signal_long
    text_long_rsi := 'RSI '
    text_long_rsi
else
    text_long_rsi := '000 '
    text_long_rsi

if sto_signal_long
    text_long_sto := 'STO '
    text_long_sto
else
    text_long_sto := '000 '
    text_long_sto

if ema_signal_long
    text_long_ema := 'EMA '
    text_long_ema
else
    text_long_ema := '000 '
    text_long_ema

if kdj_signal_long
    text_long_kdj := 'KDJ '
    text_long_kdj
else
    text_long_kdj := '000 '
    text_long_kdj

// **************************** //

if rsi_signal_short
    text_short_rsi := 'RSI '
    text_short_rsi
else
    text_short_rsi := '000 '
    text_short_rsi

if sto_signal_short
    text_short_sto := 'STO '
    text_short_sto
else
    text_short_sto := '000 '
    text_short_sto

if ema_signal_short
    text_short_ema := 'EMA '
    text_short_ema
else
    text_short_ema := '000 '
    text_short_ema

if kdj_signal_short
    text_short_kdj := 'KDJ '
    text_short_kdj
else
    text_short_kdj := '000 '
    text_short_kdj

// **************************** //
if rsi_signal_stop_long
    text_stop_long_rsi := 'RSI '
    text_stop_long_rsi
else
    text_stop_long_rsi := '000 '
    text_stop_long_rsi

if sto_signal_stop_long
    text_stop_long_sto := 'STO '
    text_stop_long_sto
else
    text_stop_long_sto := '000 '
    text_stop_long_sto

if ema_signal_stop_long
    text_stop_long_ema := 'EMA '
    text_stop_long_ema
else
    text_stop_long_ema := '000 '
    text_stop_long_ema

if kdj_signal_stop_long
    text_stop_long_kdj := 'KDJ '
    text_stop_long_kdj
else
    text_stop_long_kdj := '000 '
    text_stop_long_kdj
// **************************** //    
if rsi_signal_stop_short
    text_stop_short_rsi := 'RSI '
    text_stop_short_rsi
else
    text_stop_short_rsi := '000 '
    text_stop_short_rsi

if sto_signal_stop_short
    text_stop_short_sto := 'STO '
    text_stop_short_sto
else
    text_stop_short_sto := '000 '
    text_stop_short_sto

if ema_signal_stop_short
    text_stop_short_ema := 'EMA '
    text_stop_short_ema
else
    text_stop_short_ema := '000 '
    text_stop_short_ema

if kdj_signal_stop_short
    text_stop_short_kdj := 'KDJ '
    text_stop_short_kdj
else
    text_stop_short_kdj := '000 '
    text_stop_short_kdj

// ******************************************************************************** // 
if main_signal_long
    color_text := trend_color_long
    color_text
else if main_signal_short
    color_text := trend_color_short
    color_text
else
    color_text := color_0
    color_text

// ******************************************************************************** // 

main_bkg_zone_txt = 'BKG    : ?'
if display_combined_layouts
    main_bkg_zone_txt := ' ' + str.tostring(at_least_x_among_4_combined_bkg) + ' of 4'
    main_bkg_zone_txt
else
    main_bkg_zone_txt := bkg_text
    main_bkg_zone_txt

// *** Label Pour POWER Long ou Short **** //
// *** Label For POWER Long or Short **** //
// *** Ordre Des Parametres Pour F_Print : (_Offsetx,_Offsety,_Lab_styl,_Bkg_color,_Text,_Color_text,_Size) *** //
// *** Order Of Parameters For F_Print: (_Offsetx, _Offsety, _Lab_styl, _Bkg_color, _Text, _Color_text, _Size) *** //

if main_show_trend_label
    f_print(main_offset_lab_trend, v_center_layouts, label.style_label_right, bkg_color,
     trend_pow_text + str.tostring(main_power) + '/4' 
     + '\nLONG :' + str.tostring(main_power_long) 
     + '  SHORT :' + str.tostring(main_power_short) 
     + '\n' + graph_text + '\nBKG  -->' + main_bkg_zone_txt,
     trend_color_text, size.normal)

// ******************************************************************************** // 

// *** Label Pour Signal STOP Long ou Short **** //
// *** Label For Signal STOP Long or Short *** //
// *** Ordre Des Parametres Pour F_Print : (_Offsetx,_Offsety,_Lab_styl,_Bkg_color,_Text,_Color_text,_Size) *** //
// *** Order Of Parameters For F_Print: (_Offsetx, _Offsety, _Lab_styl, _Bkg_color, _Text, _Color_text, _Size) *** //

if main_show_stops_label
    f_print(main_offset_lab_stop, v_center_layouts, label.style_label_right, bkg_color_stop, 
     stop_pow_text + str.tostring(main_power_stop), color_text_stop, size.normal)

// ******************************************************************************** // 

// *** Version Label Infos SIMPLIFIE *** //
// *** Version Label Info SIMPLIFIED *** //
// *** Ordre Des Parametres Pour F_Print : (_Offsetx,_Offsety,_Lab_styl,_Bkg_color,_Text,_Color_text,_Size) *** //
// *** Order Of Parameters For F_Print: (_Offsetx, _Offsety, _Lab_styl, _Bkg_color, _Text, _Color_text, _Size) *** //

if main_show_infos_label and not full_label_info
    f1 = f_print(main_offset_lab_info, v_center_layouts, label.style_label_right, bkg_color, 
     'LONG    : ' + text_long_rsi + text_long_sto + text_long_ema + text_long_kdj 
     + ' - SHORT   :  ' + text_short_rsi + text_short_sto + text_short_ema + text_short_kdj 
     + '\nSTOP_Lg: ' + text_stop_long_rsi + text_stop_long_sto + text_stop_long_ema + text_stop_long_kdj 
     + '  - STOP_Sh:  ' + text_stop_short_rsi + text_stop_short_sto + text_stop_short_ema + text_stop_short_kdj, 
     trend_color_text, size.normal)
    f1

// ******************************************************************************** // 

// *** Version Label Infos COMPLETE *** //
// *** Version Label Info COMPLETE *** //
// *** Ordre Des Parametres Pour F_Print : (_Offsetx,_Offsety,_Lab_styl,_Bkg_color,_Text,_Color_text,_Size) *** //
// *** Order Of Parameters For F_Print: (_Offsetx, _Offsety, _Lab_styl, _Bkg_color, _Text, _Color_text, _Size) *** //
if main_show_infos_label and full_label_info
    f1 = f_print(main_offset_lab_info, v_center_layouts, label.style_label_right, bkg_color, 
     'LONG    : ' + text_long_rsi + text_long_sto + text_long_ema + text_long_kdj 
     + ' - SHORT   :  ' + text_short_rsi + text_short_sto + text_short_ema + text_short_kdj 
     + '\nSTOP_Lg: ' + text_stop_long_rsi + text_stop_long_sto + text_stop_long_ema + text_stop_long_kdj 
     + '  - STOP_Sh:  ' + text_stop_short_rsi + text_stop_short_sto + text_stop_short_ema + text_stop_short_kdj 
     + '\nHIGH = ' + high_up_down_text + str.format('{0,number,#.########}', high) 
     + '    -    LOW  = ' + low_up_down_text + str.format('{0,number,#.########}', low) 
     + '\nOPEN = ' + open_up_down_text + str.format('{0,number,#.########}', open) 
     + '    -    CLOSE= ' + close_up_down_text + str.format('{0,number,#.########}', close), 
     trend_color_text, size.normal)
    f1

// ******************************************************************************** // 



// ******************************************************************************** // 
//                                      END                                         //
// ******************************************************************************** //




//

