wolfpack by multigrain
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © multigrain
// @version=5
//                 _  __                  _    
//  __      _____ | |/ _|_ __   __ _  ___| | __
//  \ \ /\ / / _ \| | |_| '_ \ / _` |/ __| |/ /
//   \ V  V / (_) | |  _| |_) | (_| | (__|   < 
//    \_/\_/ \___/|_|_| | .__/ \__,_|\___|_|\_\
//                      |_|                    
indicator('wolfpack by multigrain', 'wolfpack')


//   _                   _       
//  (_)_ __  _ __  _   _| |_ ___ 
//  | | '_ \| '_ \| | | | __/ __|
//  | | | | | |_) | |_| | |_\__ \
//  |_|_| |_| .__/ \__,_|\__|___/
//          |_|                  
wp_group    = 'WolfPack (Fast, Slow, Source)'
wp_show     = input.bool            (true,      'Show WolfPack?',           inline='0',     group=wp_group)
wp_fast     = input.int             (3,         '',                         inline='1',     group=wp_group)
wp_slow     = input.int             (8,         '',                         inline='1',     group=wp_group)
wp_src      = input.source          (close,     '',                         inline='1',     group=wp_group)

ema_group   = 'Exponential Moving Average (Length)'
ema_show    = input.bool            (true,      'Show EMA?',                inline='0',     group=ema_group)
ema_len     = input.int             (13,        '',                         inline='1',     group=ema_group)

//    __                  _   _                 
//   / _|_   _ _ __   ___| |_(_) ___  _ __  ___ 
//  | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
//  |  _| |_| | | | | (__| |_| | (_) | | | \__ \
//  |_|  \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
//                                              
f_wolf(float src, int _fast, int _slow) =>
    slow 			= ta.sma(src, _slow)
    fast 			= ta.sma(src, _fast)
    macdLine 		= fast - slow
    
    sd_mac 			= ta.stdev(macdLine, 500)
    basis_mac 		= ta.ema(macdLine, 500)
    up_mac 			= basis_mac + sd_mac * 2
    dn_mac 			= basis_mac - sd_mac * 2
    rescaled_mac 	= ((macdLine - dn_mac) / (up_mac - dn_mac) * 50) - 25
    
wp          = f_wolf(wp_src, wp_fast, wp_slow)
wp_jma      = ta.ema(wp, ema_len)


//             _                
//    ___ ___ | | ___  _ __ ___ 
//   / __/ _ \| |/ _ \| '__/ __|
//  | (_| (_) | | (_) | |  \__ \
//   \___\___/|_|\___/|_|  |___/
//                              
green           =                       color.new(#00CB65,      000)  
red             =                       color.new(#F05D5E,      000) 
yellow          =                       color.new(#F4D03F,      000)
grey            =                       color.new(#939FA6,      000)

blue            =                       color.new(#3980BC,      000)

bull_color      =                       color.new(blue,         80 )
bear_color      =                       color.new(red,          80 )

wp_color        = wp > wp_jma and ta.falling(wp, 1) ? yellow : wp < wp_jma and ta.rising(wp, 1) ? green : grey
wp_ema_color    = wp > wp_jma ? blue : red
wp_fill_color   = wp > wp_jma ? bull_color : bear_color

//         _       _       
//   _ __ | | ___ | |_ ___ 
//  | '_ \| |/ _ \| __/ __|
//  | |_) | | (_) | |_\__ \
//  | .__/|_|\___/ \__|___/
//  |_|                    
hline(0)
wp_plot         = plot                  (wp,        'WolfPack',     wp_color,       1)
wp_ema_plot     = plot                  (wp_jma,    'WolfPack EMA', wp_ema_color,   1)
fill                                    (wp_plot,   wp_ema_plot,    wp_fill_color)

//   _                             _ _   _                 _       
//  | |__  _   _   _ __ ___  _   _| | |_(_) __ _ _ __ __ _(_)_ __  
//  | '_ \| | | | | '_ ` _ \| | | | | __| |/ _` | '__/ _` | | '_ \ 
//  | |_) | |_| | | | | | | | |_| | | |_| | (_| | | | (_| | | | | |
//  |_.__/ \__, | |_| |_| |_|\__,_|_|\__|_|\__, |_|  \__,_|_|_| |_|
//         |___/                           |___/                   