FOREX MASTER PATTERN Value Lines by nnam
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nnamdert
//Updated November 05, 2023
//@version=5
indicator("FOREX MASTER PATTERN Value Lines by nnam", overlay=true, max_lines_count = 500)
//                                                          BEGIN SCRIPT                                                        // 
valueline_timeframe = input.timeframe(                                                                                          //
 defval = '',                                                                                                                   //
 title = 'Value Line TimeFrame',                                                                                                //
//options = [],                                                                                                                 //
 group = 'Line Settings',                                                                                                       //
 tooltip='Unchecking this box will hide the Forex Master Pattern Value Lines on the chart.'                                     //
 )                                                                                                                              //
//HANDLES MAX_LINES_COUNTS ISSUE================================================================================================//
lineLimitInput = input.int(                                                                                                     //
 defval = 100,                                                                                                                  //
 minval = 1,                                                                                                                    //
 maxval = 499,                                                                                                                  //
 title = 'Max Lines to Show (Total of ALL Lines combined)',                                                                     // 
 tooltip = 'Adjust this number to increase or decrease the total number of lines seen on the chart. (ONLY this indicator)',     //
 group = 'Line Settings'                                                                                                        //
 )                                                                                                                              //
if array.size(line.all) > lineLimitInput                                                                                        //
    for i = 0 to array.size(line.all) - lineLimitInput - 1                                                                      //
        line.delete(array.get(line.all, i))                                                                                     //
//BEGIN Get User Inputs=========================================================================================================//
//BEGIN Get User Inputs - Line Settings                                                                                         //
hide_pivot_lines = input.bool(false, title = 'hide Pivot Lines?', group = 'Show Pivot Lines')                                   //
show_lines = input.bool(                                                                                                        //
 defval = true,                                                                                                                 //
 title = 'Show Lines on chart',                                                                                                 //
 group = 'Line Settings',                                                                                                       //
 tooltip = 'Unchecking this box will hide ALL lines on the chart - NO LINES generated by this indicator will appear'            //
 )                                                                                                                              //                                                                                                                          
show_valuelines = input.bool(                                                                                                   //
 defval = true,                                                                                                                 //
 title = 'Show Value Lines on chart',                                                                                           //
 group = 'Line Settings',                                                                                                       //
 tooltip='Unchecking this box will hide the Forex Master Pattern Value Lines on the chart.'                                     //
 )                                                                                                                              //
total_vl_to_show = input.int(                                                                                                   //
 defval = 3,                                                                                                                    // 
 title = 'Total number of Value Lines to Show on Chart',                                                                        //
 group = 'Line Settings',                                                                                                       //
 tooltip = 'Change this number to the number of Historical Value Lines you would like to see on the chart'                      //
 )                                                                                                                              // 
show_expansion_guide_lines = input.bool(                                                                                        //
 defval = true,                                                                                                                 //
 title = 'Show Expansion Guidelines on chart',                                                                                  //
 group = 'Line Settings',                                                                                                       //
 tooltip='Unchecking this box will hide the Red and Green Expansion Guides on the chart.'                                       //
 )                                                                                                                              //
value_line_width_settings = input.int(                                                                                          //  
 defval = 2,                                                                                                                    //
 title = 'Set Value Line Width',                                                                                                //
 group = 'Line Settings',                                                                                                       //
 tooltip = 'Use this option to set the width of the Forex master Pattern Value Line (default is 1, max is 8)',                  //
 minval = 1,                                                                                                                    //
 maxval = 8                                                                                                                     //
 )                                                                                                                              //
value_line_length_settings = input.int(                                                                                         //  
 defval = 500,                                                                                                                  //
 title = 'Set Value Line Length',                                                                                               //
 group = 'Line Settings',                                                                                                       //
 tooltip = 'Use this option to set the lenth of the Forex master Pattern Value Line (default is 100, max is 100)',              //
 minval = 1,                                                                                                                    //
 maxval = 500                                                                                                                   //
 )                                                                                                                              //
only_show_last_value_line = input.bool(                                                                                         //
 defval = false,                                                                                                                //
 title = 'Only show last Value Line on Chart?',                                                                                 //
 group = 'Line Settings',                                                                                                       //
 tooltip = 'If box is checked only most recent Value Line will be visible, even if most recent box is not in the same location' //                                                                                                                
 )                                                                                                                              // 
showOnlyLastBox = input.bool(                                                                                                   //
 defval = false,                                                                                                                //
 title = 'show last box only',                                                                                                  //
 group = 'Box Settings',                                                                                                        //
 tooltip = 'If box is checked only the most recent contraction box will be shown on the chart'                                  //      
 )                                                                                                                              //
show_Expansion_Area = input.bool(                                                                                               //
 defval = false,                                                                                                                //
 title = 'Show Expansion Area (coming soon)',                                                                                   //
 group = 'Expansion Area Settings (coming Soon!)',                                                                              //
 tooltip = 'This feature is not implemented yet'                                                                                //
 )                                                                                                                              //
show_expansion_guidelines = input.bool(                                                                                         //
 defval = false,                                                                                                                //
 title = 'Show Expansion GuideLines on Chart (coming soon)',                                                                    //
 group = 'Expansion Area Settings (coming Soon!)',                                                                              //
 tooltip = 'This feature is not implemented yet'                                                                                //
 )                                                                                                                              //
//END Get User Inputs - Line Settings===========================================================================================//
//BEGIN Get User Inputs - BARS==================================================================================================//
//BEGIN Get User Inputs - BAR COLORS                                                                                            //
color_code_candles = input.bool(                                                                                                //
 defval=true,                                                                                                                   //
 title = 'Color Code the Candles',                                                                                              //
 tooltip = 'Turn on Color Coded Candles. Expansion. Contraction, Bullish and Bearish Candles will be shaded as listed below.',  //
 group = 'Candle Colors'                                                                                                        // 
 )                                                                                                                              //
inside_bar_color = input.color(                                                                                                 //  
 defval = color.white,                                                                                                        //
 title = 'Contraction Candles',                                                                                                 //
 tooltip = 'This is the color of the Strat Inside Bar - otherwise known as 1',                                                  //
 group = 'Candle Colors',                                                                                                       //
 inline = 'inside outside',                                                                                                     //
 confirm = false)                                                                                                               //
outside_bar_color = input.color(                                                                                                //
 defval = color.yellow,                                                                                                       //
 title = 'Expansion Candles',                                                                                                   //
 tooltip = 'This is the color of the Strat Outside Bar - otherwise known as 3',                                                 //
 group = 'Candle Colors',                                                                                                       //
 inline = 'inside outside',                                                                                                     //
 confirm = false)                                                                                                               //
twoup_bar_color = input.color(                                                                                                  //
 defval = color.lime,                                                                                                         //
 title = 'Bullish Candle',                                                                                                      // 
 tooltip = 'This is the color of the Strat 2 UP Bar',                                                                           //
 group = 'Candle Colors',                                                                                                       // 
 inline = 'twobars',                                                                                                            //
 confirm = false)                                                                                                               //
twodown_bar_color = input.color(                                                                                                //
 defval = color.maroon,                                                                                                       //
 title = 'Bearish Candle',                                                                                                      //
 tooltip = 'This is the color of the Strat 2 DOWN Bar',                                                                         //
 group = 'Candle Colors',                                                                                                       //
 inline = 'twobars',                                                                                                            //
 confirm = false)                                                                                                               //
bearish_engulfing_bar_color = input.color(                                                                                      //
 defval = color.new(color.fuchsia, 0),                                                                                        //
 title = 'Bearish Engulfing Candle',                                                                                            //
 tooltip = 'This is the color of a Bearish Engulfing Candle',                                                                   //
 group = 'Candle Colors',                                                                                                       //
 inline = 'engulfing',                                                                                                          //
 confirm = false)                                                                                                               //
bullish_engulfing_bar_color = input.color(                                                                                      //
 defval = color.new(color.blue, 0),                                                                                           //
 title = 'Bullish Engulfing Candle',                                                                                            //
 tooltip = 'This is the color of a Bullish Engulfing Candle',                                                                   //
 group = 'Candle Colors',                                                                                                       //
 inline = 'engulfing',                                                                                                          //
 confirm = false)                                                                                                               //
//END Get User Inputs - BAR COLORS                                                                                              //
//BEGIN Get User Inputs - ENGULFING BARS========================================================================================// 
show_engulfing_patterns = input.bool(                                                                                           //
 defval=true,                                                                                                                   //
 title = 'Show Engulfing Patterns?',                                                                                            //
 group = 'Engulfing Patterns'                                                                                                   //
 )                                                                                                                              //
show_bullish_engulfing_patterns = input.bool(                                                                                   //
 defval=true,                                                                                                                   //
 title ='Show Bullish Engulfing Candles',                                                                                       //
 group = 'Engulfing Patterns')                                                                                                  //
show_bearish_engulfing_patterns = input.bool(                                                                                   // 
 defval=true,                                                                                                                   //
 title ='Show Bearish Engulfing Candles',                                                                                       //
 group = 'Engulfing Patterns')                                                                                                  //
//END Get User Inputs - ENGULFING BARS==========================================================================================//
//BEGIN STRAT SCENARIO INDENTIFIERS=============================================================================================//
atr = ta.atr(14)                                                                                                                //
bar_green = close >= open                                                                                                       //
bar_red = close < open                                                                                                          //
bar_inside = (high <= high[1]) and (low >= low[1])                                                                              //
bar_twoup = (high > high[1]) and (low >= low[1])                                                                                //
bar_twodown = (high <= high[1]) and (low < low[1])                                                                              //
bar_outside = (high > high[1]) and (low < low[1])                                                                               //
bar_openTime = time                                                                                                             //
bar_lowPrice = low                                                                                                              //
bar_highPrice = high                                                                                                            //
bar_two_up_green = bar_twoup and bar_green                                                                                      //
bar_two_up_red = bar_twoup and bar_red                                                                                          //
bar_two_down_red = bar_twodown and bar_red                                                                                      //
bar_inside_green = bar_inside and bar_green                                                                                     // 
bar_outside_green = bar_outside and bar_green                                                                                   //
bar_outside_red = bar_outside and bar_red                                                                                       //
bar_continuation_green = open[1] <= low and bar_green                                                                           //
//END STRAT SCENARIO INDENTIFIERS===============================================================================================//
//BEGIN BEARISH ENGULFING DEFINITION+===========================================================================================//
bar_bearish_engulfing =                                                                                                         //
//CLOSE Price of the CURRENT Engulfing candle /session must be (less than) the OPEN Price of PREVIOUS session                   //
 close < open[1]                                                                                                                //
//OPEN Price of the CURRENT Engulfing candle /session must be (greater than) the CLOSE Price of PREVIOUS session                //                                                                                              
 and open > close[1]                                                                                                            //
//Previous Session (before the engulfing candle) - the candle /session being Engulfed MUST be a GREEN candle /session           //
 and (close[1] >= open[1])                                                                                                      //
//OPEN and CLOSE of the CURRENT Engulfing Session is (greater than or equal to) the previous candle /session being Engulfed and //
//is LARGER by a factor of 2 - (or basically twice as big) - ENGULFING CANDLE MUST BE RED [open - close = RED]                  //
 and (open - close) >= ((close[1] - open[1]) * 6)                                                                               //
//CURRENT Engulfing candle /session needs to be (greater than) the atr                                                          // 
 and (open - close) >= atr                                                                                                      //
//END BEARISH ENGULFING DEFINITION==============================================================================================//
//BEGIN BULLISH ENGULFING DEFINITION============================================================================================//
bar_bullish_engulfing =                                                                                                         //
 close > open[1]                                                                                                                //
 and open < close[1]                                                                                                            // 
 and (close[1] <= open[1])                                                                                                      //
 and (close - open) >= ((open[1] - close[1]) * 6)                                                                               //
 and (close - open) >= atr                                                                                                      // 
//END BULLISH ENGULFING DEFINITION==============================================================================================//
//Begin Bar Colors==============================================================================================================//
//Expansion Candle also known as Strat 3 Outside Bar                                                                            //
barcolor(                                                                                                                       //
 not bar_bearish_engulfing                                                                                                      //
 and not bar_bullish_engulfing                                                                                                  //
 and color_code_candles                                                                                                         //
 and (high > high[1]                                                                                                            //
 and low < low[1]) ?                                                                                                            //                       
 color.new(outside_bar_color, 0) : na, title = '3 Outside Bar')                                                                 //
barcolor(                                                                                                                       //
 not bar_bullish_engulfing                                                                                                      //
 and not bar_bearish_engulfing                                                                                                  //
 and color_code_candles                                                                                                         //
 and (high > high[1]                                                                                                            //
 and low >= low[1]) ?                                                                                                           //           
 color.new(twoup_bar_color, 0) : na, title = '2 up')                                                                            //
barcolor(                                                                                                                       //
 not bar_bullish_engulfing                                                                                                      //
 and not bar_bearish_engulfing                                                                                                  //
 and color_code_candles                                                                                                         //
 and (high <= high[1]                                                                                                           //
 and low < low[1]) ?                                                                                                            //              
 color.new(twodown_bar_color, 0) : na, title = '2 down')                                                                        //
barcolor(                                                                                                                       //
 not bar_bullish_engulfing                                                                                                      //
 and not bar_bearish_engulfing                                                                                                  // 
 and color_code_candles                                                                                                         //
 and (high <= high[1]                                                                                                           //
 and low >= low[1]) ?                                                                                                           // 
 color.new(inside_bar_color, 0) : na, title = '1 Inside Bar')                                                                   //
barcolor(                                                                                                                       //
 bar_bullish_engulfing                                                                                                          //
 and show_bullish_engulfing_patterns                                                                                            //
 and show_engulfing_patterns                                                                                                    //
 and color_code_candles ?                                                                                                       //                    
 color.new(bullish_engulfing_bar_color, 0) : na, title = 'Bullish Engulfing')                                                   // 
barcolor(                                                                                                                       //
 bar_bearish_engulfing                                                                                                          //
 and show_bearish_engulfing_patterns                                                                                            //
 and show_engulfing_patterns                                                                                                    //
 and color_code_candles ?                                                                                                       // 
 color.new(bearish_engulfing_bar_color, 0) : na, title = 'Bearish Engulfing')                                                   // 
//bear_candle = open > close                                                                                                    //
//bull_candle = close > open                                                                                                    //
//plotcandle(bull_candle ? open : na, bull_candle ? high: na, bull_candle ? low: na, bull_candle ? close: na,                   //
// wickcolor=color.new(color.lime, 0),                                                                                          //
// bordercolor=color.new(color.lime, 0)                                                                                         //
// )                                                                                                                            // 
//plotcandle(bear_candle ? open: na, bear_candle ? high: na, bear_candle ? low: na, bear_candle ? close: na,                    //
// wickcolor=color.new(color.red, 0),                                                                                           //
// bordercolor=color.new(color.red, 0)                                                                                          //
// )                                                                                                                            //
//End Bar Colors================================================================================================================//
//                                                                                                                              //
//BEGIN CONTRACTION BOXES=======================================================================================================//
//showOnlyLastBox = input.bool(false, title = 'show last box only') //is above in global inputs leaving here for                //
//standalone box script if required                                                                                             //
// variables                                                                                                                    //
var box myBox = na                                                                                                              //
                                                                                                                                
var float boxHigh = na                                                                                                          //
var float boxLow = na                                                                                                           //

varip int barIndex = 1                                                                                                          //
varip bool f = false                                                                                                            //
//
oneone = request.security(syminfo.tickerid, valueline_timeframe, bar_inside) // not recommended as it can cause issues          //   
if oneone == true
    1
else 
    na
//
if oneone and oneone[1] and not oneone[2] and barstate.isconfirmed                                                                            //
    boxHigh := high[1] // was high[1]
    boxLow := low[1] // was high[1]
    f := true

    if showOnlyLastBox
        box.delete(id=myBox[1])

    myBox := box.new(bar_index-1, high, bar_index, low, bgcolor=color.new(#405fcf, 50), border_width=2) // high and low were [1]
    barIndex := barIndex+1

else if oneone and oneone[1] and oneone[2] and barstate.isconfirmed                                                                           //
    box.set_right(myBox[1], bar_index)
    barIndex := barIndex+1
    
else if oneone[2] and oneone[1] and not oneone and barstate.isconfirmed                                                                       //
    box.set_right(myBox[1], bar_index)
    barIndex := barIndex
    
else if not oneone[1] and not oneone                                                                                            //
    f := false
//END CONTRACTION BOXES=========================================================================================================//
//lines                                                                                                                         //
//midline                                                                                                                       //
//EmaCross = ta.crossover(shortest, short)   (future use)                                                                       //
var float middleBody = na
//midline = line.new(bar_index[1], middleBody, bar_index+value_line_length_settings, middleBody, width = value_line_width_settings) //, extend=extend.right)

//if oneone and oneone[1] and show_lines and not only_show_last_value_line
//    middleBody := (((high + high[1]) / 2) + ((low + low[1]) / 2)) / 2 //was (open + close) / 2 or (high + low) / 2
//    midline = line.new(bar_index[1], middleBody, bar_index+value_line_length_settings, middleBody, width = value_line_width_settings) //, extend=extend.right)
    
//else 
//    if oneone and oneone[1] and show_lines and only_show_last_value_line

//        middleBody := (((high + high[1]) / 2) + ((low + low[1]) / 2)) / 2 //was (open + close) / 2 or (high + low) / 2
//    midline = line.new(bar_index[1], middleBody, bar_index+value_line_length_settings, middleBody, width = value_line_width_settings) //, extend=extend.right)
//    line.delete(midline[2])

    
//NotValid = not oneone
//if NotValid
//    middleBody := na
//Value Line
var line [] value_line_array = array.new_line()
var line value_line_01 = na
if oneone and oneone[1] and show_lines and show_valuelines
    middleBody := (((high + high[1]) / 2) + ((low + low[1]) / 2)) / 2 //was (open + close) / 2 or (high + low) / 2
    value_line_01 := line.new(bar_index[1], middleBody, bar_index+value_line_length_settings, middleBody, color = color.new(color.blue, 0), width = value_line_width_settings)
    array.push(value_line_array, value_line_01)

    if array.size(value_line_array) > total_vl_to_show
        line.delete(array.shift(value_line_array))

//plot(middleBody, color=color.lime, style=plot.style_linebr, trackprice=true)
//END MIDLINE SCRIPT============================================================================================================//
//BEGIN ENGULFING CANDLE ALERTS=================================================================================================//
alertcondition(                                                                                                                 //
 bar_bullish_engulfing,                                                                                                         //
 title = 'Bullish Engulfing Alert',                                                                                             //
 message = 'Bullish Engulfing Pattern Identified'                                                                               //
 )                                                                                                                              //
alertcondition(                                                                                                                 //
 bar_bearish_engulfing,                                                                                                         //
 title = 'Bearish Engulfing Alert',                                                                                             //
 message = 'Bearish Engulfing Pattern Identified'                                                                               //
 )                                                                                                                              //
//END ENGULFING CANDLE ALERTS===================================================================================================//
//BEGIN ENGULFING CANDLE PLOTS==================================================================================================//
//plotshape(series, title, style, location, color, offset, text, textcolor, editable, size, show_last, display) → void=========+//
//show_engulfing_patterns and show_bullish_engulfing_patterns ?                                                                 //                                                                   
plotshape(not show_engulfing_patterns or not show_bullish_engulfing_patterns ? na :                                             //
 bar_bullish_engulfing,                                                                                                         //
 title = 'Bullish Engulfing Plot',                                                                                              //
 style = shape.arrowup,                                                                                                         //
 location = location.belowbar,                                                                                                  //  
 color = color.new(color.blue,0),                                                                                             //
 size = size.large,                                                                                                             //
 show_last = 2000)                                                                                                              // 
 //show_engulfing_patterns and show_bearish_engulfing_patterns ?                                                                //        
plotshape(not show_engulfing_patterns or not show_bearish_engulfing_patterns ? na :                                             //
 bar_bearish_engulfing,                                                                                                         //
 title = 'Bearish Engulfing Plot',                                                                                              //
 style = shape.arrowdown,                                                                                                       //
 location = location.abovebar,                                                                                                  // 
 color = color.new(color.fuchsia,0),                                                                                          //
 size = size.large,                                                                                                             //
 show_last = 2000)                                                                                                              //
//END ENGULFING CANDLE PLOTS====================================================================================================//
//
//
mom_len = input.int(12, minval=1, title="Length")
mom_src = input(close, title="Source")
mom = mom_src - mom_src[mom_len]
bullish_momentum = mom > mom[1] //and mom > 0.00
bearish_momentum = mom < mom[1] //and mom < 0.00
bullish_reversal = mom[3] > mom[2] and mom[2] < mom[1]
bearishreversal = mom[3] <mom[2] and mom[2] > mom[1]
//                   TDI
TDI_GRP_01 = 'Traders Dynamic Index Settings' 
// Core indicator inputs
rsiPeriod = input.int(21, minval = 1, title = "RSI Period", group = TDI_GRP_01)
bandLength = input.int(34, minval = 1, title = "Band Length", group = TDI_GRP_01)
lengthtradesl = input.int(2, minval = 1, title = "Fast MA on RSI", group = TDI_GRP_01)
lengthrsipl = input.int(7, minval = 0, title = "Slow MA on RSI", group = TDI_GRP_01)
tdi_src = input.source(close, title = 'TDI Source', group = TDI_GRP_01)                                                        

r_1 = ta.rsi(tdi_src, rsiPeriod)                           // RSI of Close
ma_1 = ta.sma(r_1, bandLength)                             // Moving Average of RSI [current]
offs_1 = (1.6185 * ta.stdev(r_1, bandLength))              // Offset
up_1 = ma_1 + offs_1                                       // Upper Bands
dn_1 = ma_1 - offs_1                                       // Lower Bands
mid_1 = (up_1 + dn_1) / 2                                  // Average of Upper and Lower Bands
slowMA_1 = ta.sma(r_1, lengthrsipl)                        // Moving Average of RSI 2 bars back
fastMA_1 = ta.sma(r_1, lengthtradesl)                      // Moving Average of RSI 7 bar

// Overlay False plots
//plot(up_1, title = "Upper Band", color = #1976d2, linewidth = 2)     
//plot(dn_1, title = "Lower Band", color = #1976d2, linewidth = 2)      
//plot(mid_1, title = "Middle Band", color = #fbc02d, linewidth = 2)    
//plot(fastMA_1, title = "Fast MA", color = #388e3c, linewidth = 2)     
//plot(slowMA_1, title = "Slow MA", color = #b71c1c, linewidth = 2)    
//hline(20, title = "Extremely Oversold", color = #5d606b )           
//hline(30, title = "Highly Oversold", color = #787b86 )              
//hline(40, title = "Oversold", color = #b2b5be )                     
//hline(50, title = "Midline", color = #d1d4dc )                      
//hline(60, title = "Overbought", color = #b2b5be )                   
//hline(70, title = "Highly Overbought", color = #787b86 )            
//hline(80, title = "Extremely Overbought", color = #5d606b )         
bullishmove = fastMA_1 > up_1 and fastMA_1 > 68
bearishmove = fastMA_1 < dn_1 and fastMA_1 < 32
//plotarrow(bullishmove and bullish_momentum ? high : na, colorup = color.lime)
plotshape(bullishmove and bullish_momentum ? high : na, style = shape.arrowup, color = color.new(color.lime, 0), size = size.normal, location = location.abovebar)
//plotarrow(bearishmove and bearish_momentum ? low : na, colordown = color.new(#FF0000, 0))
plotshape(bearishmove and bearish_momentum ? low : na, style = shape.arrowdown, color = color.new(#FF0000, 0), size = size.normal, location = location.belowbar)
//Bearish Reversal Line
var line [] reversal_line_bearish_array = array.new_line()
var line reversal_line_bearish = na
if (bullishmove[1] and bullish_momentum[1]) and not (bullishmove and bullish_momentum) and show_lines
    reversal_line_bearish := line.new(bar_index, high, bar_index+3, high, color = color.new(color.red, 0), width = 2)
    array.push(reversal_line_bearish_array, reversal_line_bearish)

    if array.size(reversal_line_bearish_array) > 10
        line.delete(array.shift(reversal_line_bearish_array))

//Bullish Reversal Line
var line [] reversal_line_bullish_array = array.new_line()
var line reversal_line_bullish = na
if (bearishmove[1] and bearish_momentum[1]) and not (bearishmove and bearish_momentum) and show_lines
    reversal_line_bullish := line.new(bar_index, low, bar_index+3, low, color = color.new(color.lime, 0), width = 2)
    array.push(reversal_line_bullish_array, reversal_line_bullish)

    if array.size(reversal_line_bullish_array) > 10
        line.delete(array.shift(reversal_line_bullish_array))

//BEGIN Definitions=============================================================================================================// 
bull_price = high                                                                                                               //
bullish_break =                                                                                                                 // 
 bull_price > high[1]                                                                                                           //
 and bull_price > high[2]                                                                                                       //
 and bull_price > high[3]                                                                                                       //
 and bull_price > high[4]                                                                                                       // 
 and bull_price > high[5]                                                                                                       //
 and bull_price > high[6]                                                                                                       //
 and bull_price > high[7]                                                                                                       //
 and bull_price > high[8]                                                                                                       //
 and bull_price > high[9]                                                                                                       //                  
 and bull_price > high[10]                                                                                                      //
 and bull_price > high[11]                                                                                                      //
 and bull_price > high[12]                                                                                                      //
 and bull_price > high[13]                                                                                                      //
 and bull_price > high[14]                                                                                                      //
 and bull_price > high[15]                                                                                                      //
 and bull_price > high[16]                                                                                                      //
 and bull_price > high[17]                                                                                                      //
 and bull_price > high[18]                                                                                                      //
 and bull_price > high[19]                                                                                                      //
 and bull_price > high[20]                                                                                                      //
 and bull_price > high[21]                                                                                                      //
 //and price > high[22]                                                                                                         //
 //and price > high[23]                                                                                                         //
 //and price > high[24]                                                                                                         //
 //and price > high[25]                                                                                                         //
 //and price > high[26]                                                                                                         //
//                                                                                                                              //
price = close                                                                                                                   //
bearish_break =                                                                                                                 // 
 price < low[1]                                                                                                                 //
 and price < low[2]                                                                                                             //
 and price < low[3]                                                                                                             //
 and price < low[4]                                                                                                             //
 and price < low[5]                                                                                                             //
 and price < low[6]                                                                                                             //
 and price < low[7]                                                                                                             //
 and price < low[8]                                                                                                             //
 and price < low[9]                                                                                                             //
 and price < low[10]                                                                                                            //
 and price < low[11]                                                                                                            //
 and price < low[11]                                                                                                            //
 and price < low[12]                                                                                                            //
 and price < low[13]                                                                                                            //
 and price < low[14]                                                                                                            //
 and price < low[15]                                                                                                            //
 and price < low[16]                                                                                                            //
 and price < low[17]                                                                                                            //
 and price < low[18]                                                                                                            //
 and price < low[19]                                                                                                            //
 and price < low[20]                                                                                                            //
 and price < low[21]                                                                                                            //
 //and price < low[22]                                                                                                          //
 //and price < low[23]                                                                                                          //
 //and price < low[24]                                                                                                          //
 //and price < low[25]                                                                                                          //
 //and price < low[26]                                                                                                          //
//                                                                                                                              //                      
bearish_signal = (bearish_break[1] and not bearish_break)                                                                       //
bullish_signal = (bullish_break[1] and not bullish_break)                                                                       //
//                                                                                                                              //
var line bullishline = na                                                                                                       //
if barstate.isconfirmed and bullish_signal and show_lines and show_expansion_guide_lines //bullish_break                        //
    bullishline := line.new(                                                                                                    //
     x1=bar_index[1],                                                                                                           //
     y1=high[1],                                                                                                                //
     x2=bar_index+50,                                                                                                           //
     y2=high[1],                                                                                                                //
     color = color.new(color.red, 0),                                                                                         //
     extend = extend.none                                                                                                       //
     )                                                                                                                          // 
    line.delete(bullishline[1])                                                                                                 //
//PLOTSHAPES BEARISH============================================================================================================//
//                                                                                                                              //
var line bearishline = na                                                                                                       //
if barstate.isconfirmed and bearish_signal and show_lines and show_expansion_guide_lines// bearish_break                        //
    bearishline := line.new(                                                                                                    //
     bar_index[1],                                                                                                              //
     low[1],                                                                                                                    //
     bar_index+50,                                                                                                              //
     low[1],                                                                                                                    //
     color = color.new(color.green, 0),                                                                                       //
     extend = extend.none                                                                                                       //
     )                                                                                                                          //
    line.delete(bearishline[1])                                                                                                 //  
//END Script====================================================================================================================// 
