Setup Max e Min Larry Willians
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
///\\===============================================================================//\\\
//████████╗██████╗  █████╗ ██████╗ ██╗███╗   ██╗ ██████╗ ██╗   ██╗██╗███████╗██╗    ██╗\\
//╚══██╔══╝██╔══██╗██╔══██╗██╔══██╗██║████╗  ██║██╔════╝ ██║   ██║██║██╔════╝██║    ██║\\
//   ██║   ██████╔╝███████║██║  ██║██║██╔██╗ ██║██║  ███╗██║   ██║██║█████╗  ██║ █╗ ██║\\
//   ██║   ██╔══██╗██╔══██║██║  ██║██║██║╚██╗██║██║   ██║╚██╗ ██╔╝██║██╔══╝  ██║███╗██║\\
//   ██║   ██║  ██║██║  ██║██████╔╝██║██║ ╚████║╚██████╔╝ ╚████╔╝ ██║███████╗╚███╔███╔╝\\
//   ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚═════╝ ╚═╝╚═╝  ╚═══╝ ╚═════╝   ╚═══╝  ╚═╝╚══════╝ ╚══╝╚══╝ \\
//\\==============================================================================//\\ \\
// ----------------------------------------------------------------------------------- \\
// Setup Max e Min Larry Willians : Developed by Cavuca-Trader                         \\                                  
// ----------------------------------------------------------------------------------- \\
// ................................................................................... \\
// Name                  : Setup Max e Min Larry Willians                              \\                                                  
// Surname               : Setup Max Min                                               \\                       
// Description           : Technical Analysis Setup Scalper                            \\
// Info                  : Setup for quick operations following the asset trend.       \\
// Creation Date         : 01/02/2023                                                  \\
// Version TradingView   : 5                                                           \\
// ................................................................................... \\
// v1.0 - release = TradingView = Ok                                                   \\
// v2.0 - fixed system stop indication                                                 \\
// v3.0 - fixed corrected documentation                                                \\
//=====================================================================================\\
// © Cavuca-Trader
// @version=5
indicator(title="Setup Max e Min Larry Willians", shorttitle="Setup Max Min", overlay=true)

// Creating var
var int sma1 = 3
var int sma2 = 3
var int sma3 = 21
var bool stp = false
var bool stpX = false

// Creating moving averages
ma1 = ta.sma(high,sma1)
ma2 = ta.sma(low,sma2)
ma3 = ta.sma(close,sma3)


// Moving average coloring 
m_col = color.gray
if ma3 < ma2 and ma3 < ma1 
    m_col := color.rgb(7, 249, 15)   
if ma3 > ma2 and ma3 > ma1 
    m_col :=color.rgb(247, 8, 8)
    
// System Disable
if ma3 > ma2 and ma3[1] < ma2[1] and stp 
    stpX := true
    stp := false
else
    if ma3 < ma1 and ma3[1] > ma1[1] and stp
        stpX := true
        stp := false 
    else
        stpX := false 

// Coloring Rule Entry
Cwbar = close != open
Cgbar = ma3 < ma2 and ma3 < ma1 and low <= ma2 and stp == false
Crbar = ma3 > ma1 and ma3 > ma1 and high >= ma1 and stp == false

// Stop enable 
if Cgbar
    stp := true
else 
    if Crbar
        stp := true
    
// Stop Rule
StopCgbar = ma3 < ma2 and ma3 < ma1 and high >= ma1 and stp
StopCrbar = ma3 > ma1 and ma3 > ma1 and low <= ma2 and stp
if StopCgbar
    stp := false
else
    if StopCrbar
        stp := false

// Color of candles
barcolor(Cgbar ? color.green : na)
barcolor(Crbar ? color.red: na)
barcolor(Cwbar ? color.white : na)

// Trade indication
plotshape(Cgbar, style=shape.triangleup, color=color.rgb(7, 249, 15), location=location.belowbar, size=size.small)
plotshape(StopCgbar, style=shape.triangledown, color=color.rgb(247, 8, 8), location=location.abovebar, size=size.small)
plotshape(Crbar, style=shape.triangledown, color=color.rgb(247, 8, 8), location=location.abovebar, size=size.small)
plotshape(StopCrbar, style=shape.triangleup, color=color.rgb(7, 249, 15), location=location.belowbar, size=size.small)
plotshape(stpX, style=shape.xcross, color=color.purple, location=location.belowbar, size=size.small)

// Moving average plots
plot(ma1,color = color.purple,linewidth = 1)
plot(ma2,color = color.blue,linewidth = 1)
plot(ma3,color = m_col,linewidth = 2)