Harmonic Patterns Based Supertrend
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
//                                       ░▒             
//                                  ▒▒▒   ▒▒      
//                              ▒▒▒▒▒     ▒▒      
//                      ▒▒▒▒▒▒▒░     ▒     ▒▒          
//                  ▒▒▒▒▒▒           ▒     ▒▒          
//             ▓▒▒▒       ▒        ▒▒▒▒▒▒▒▒▒▒▒  
//   ▒▒▒▒▒▒▒▒▒▒▒ ▒        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒         
//   ▒  ▒       ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░        
//   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒         
//   ▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒                       
//    ▒▒▒▒▒         ▒▒▒▒▒▒▒                            
//                 ▒▒▒▒▒▒▒▒▒                           
//                ▒▒▒▒▒ ▒▒▒▒▒                          
//               ░▒▒▒▒   ▒▒▒▒▓      ████████╗██████╗ ███████╗███╗   ██╗██████╗  ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗
//              ▓▒▒▒▒     ▒▒▒▒      ╚══██╔══╝██╔══██╗██╔════╝████╗  ██║██╔══██╗██╔═══██╗██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔════╝
//              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒        ██║   ██████╔╝█████╗  ██╔██╗ ██║██║  ██║██║   ██║███████╗██║     ██║   ██║██████╔╝█████╗ 
//             ▒▒▒▒▒       ▒▒▒▒▒       ██║   ██╔══██╗██╔══╝  ██║╚██╗██║██║  ██║██║   ██║╚════██║██║     ██║   ██║██╔═══╝ ██╔══╝  
//            ▒▒▒▒▒         ▒▒▒▒▒      ██║   ██║  ██║███████╗██║ ╚████║██████╔╝╚██████╔╝███████║╚██████╗╚██████╔╝██║     ███████╗
//             ▒▒             ▒                        
//@version=5
import HeWhoMustNotBeNamed/HSupertrend/2 as hs

indicator('Harmonic Patterns Based Supertrend', 'HP-Supertrend [Trendoscope]', overlay=true, max_lines_count = 500)
base = input.string('CD', 'Base', ['minmax', 'correction', 'CD'], group="Supertrend")
entryPercent = input.int(30, 'Entry %', minval=30, maxval = 200, step=5, group='Supertrend')
stopPercent = input.int(5, 'Stop %', minval=0, maxval = 30, step=5, group='Supertrend')
useClosePrices = input.bool(true, 'Use Close Prices', group='Supertrend')

errorPercent = input.int(8, title='Error %', minval=3, step=5, maxval=21, group='Harmonic Patterns',
                             tooltip='Error threshold for calculation on patterns. Increased error threshold will reduce the accuracy of patterns. Lower error threshold will reduce number of patterns detected.')
zigzagLength = input.int(8, step=5, minval=3, title='Zigzag', group='Harmonic Patterns', tooltip='Zigzag Length on which pattern detection is built')
logScale = input.bool(false, 'Log Scale', group='Harmonic Patterns', tooltip='If selected, patterns are scanned on log scale instead of regular price scale')
showHarmonicPatterns = input.bool(true, 'Display Harmonic Patterns', group='Harmonic Patterns', tooltip='If selected, harmonic patterns scanned will be drawn on chart')

[dir, supertrend] = hs.hsupertrend(hs.ZigzagProperties.new(zigzagLength, na),
                                          hs.PatternProperties.new(base, entryPercent, stopPercent, useClosePrices, logScale),
                                          errorPercent, showHarmonicPatterns, color.blue
                                          )
plot(supertrend, 'HarmonicSupertrend', color=dir>0? color.green: color.red)