Wave Chart v1
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MNR_Anas

//@version=5
indicator("Wavechart v1", overlay=true ,max_lines_count=500,max_bars_back=5000)

////input
bars = input.int(7, minval=1, title="bars")             //range to plot in the graph
linecolor=input.color(color.red,title="line Color") 
bar_shift=input.int(0, title="bars_shift")              //Shift the bar that command to plot
bg=input.bool(false,title="highlight the bar that runs to plot")      //highlight the bar that runs to plot
showmessagebox=input.bool(true,title="Show MessageBox") 

/////

bars_calc=(bar_index+bar_shift)%bars+1

hbar=ta.highestbars(bars_calc)                          //bar that highest in range
lbar=ta.lowestbars(bars_calc)                           //bar that lowest in range

whigh=high[-hbar]                                       //value of height from habr
wlow=low[-lbar]                                         //value of low from lbar

var vx1=0, vx2=0
var px=0                                                //Previous x
var py=0.0                                              //Provious y
var vy1=0.0
var vy2=0.0

if(bars_calc==bars)                                     //Runs only when it's the last bar in the range. 
    
    if(hbar<lbar)                                       //If the highest point comes before the lowest point
        vx1:=bar_index[-hbar]
        vy1:=whigh
        vx2:=bar_index[-lbar]
        vy2:=wlow
    else                                                //If the Lowestest point comes before the lowest point
        vx1:=bar_index[-lbar]
        vy1:=wlow
        vx2:=bar_index[-hbar]
        vy2:=whigh
    
    if(px!=0 and py!=0)  
        line.new(x1=px, y1=py, x2=vx1, y2=vy1,color=linecolor,width=2)  //line between previous points
        
    line.new(x1=vx1, y1=vy1, x2=vx2, y2=vy2,color=linecolor,width=2)    //line between highest to lowest in range
    
    //remember last point 
    px:=vx2
    py:=vy2
    
bgcolor(bg? bars_calc==bars? (color.new(color.gray,70) ) :na:na )        //highlight the bar that runs to plot

// Message Box
if(showmessagebox)
    statusText = "This indicator has a mistake\nPlease use the new version (wavechart V2)"
    text_location = 0.0 
    l = label.new(bar_index,na) //label.new(bar_index, na)
    label.set_text(l, statusText)
    label.set_y(l,high)
    boxColor =  color.lime 
    label.set_color(l, color.red)
    label.set_size(l,size.huge)
    label.delete(l[1])