Indicator · Pine Script v5 · On the chart

Mc War v3

by tuanmcwar

Mc War v3 is a price-chart indicator that finds swing highs and lows over a user-set lookback and draws upper and lower order-block zones as boxes.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code245
Settings25inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago31 Aug 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

245 lines of Pine Script v5 from Mcwar-v3.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Mcwar-v3.pine
// @version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/


indicator('Mc War v3', overlay=true, max_lines_count=100)

//Cài đặt
//-----------------------------------------------------------------------------{
length   = input.int(30, 'Swing', minval = 3 , group = 'OB')
showBear = input.int(5, 'Số OB trên', minval = 0, group = 'OB')
showBull = input.int(5, 'Số OB dưới', minval = 0, group = 'OB')
useBody  = input(false, 'Thu gọn OB không nên dùng', group = 'OB')

//Style
bearCss      = input(color.new(#ff9800, 90), 'OB trên', group = 'Style')
bearBreakCss = input(color.new(#ff1100, 100), 'OB trên Break', group = 'Style')



bullCss      = input(color.new(#ff9800, 90), 'OB dưới', group = 'Style')
bullBreakCss = input(color.new(#ff1100, 100), 'OB dưới Break', group = 'Style')





//-----------------------------------------------------------------------------}

//-----------------------------------------------------------------------------{
type ob
    float top = na
    float btm = na
    int   loc = bar_index
    bool  breaker = false
    int   break_loc = na
    

type swing
    float y = na
    int   x = na
    bool  crossed = false


//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
swings(len)=>
    var os = 0
    var swing top = swing.new(na, na)
    var swing btm = swing.new(na, na)
    
    upper = ta.highest(len)
    lower = ta.lowest(len)

    os := high[len] > upper ? 0 
      : low[len] < lower ? 1 : os

    if os == 0 and os[1] != 0
        top := swing.new(high[length], bar_index[length])
    
    if os == 1 and os[1] != 1
        btm := swing.new(low[length], bar_index[length])

    [top, btm]

method notransp(color css) => color.rgb(color.r(css), color.g(css), color.b(css))

method display(ob id, css, break_css)=>
    if id.breaker
        box.new(id.loc, id.top, id.break_loc, id.btm, css.notransp()
          , bgcolor = css
          , xloc = xloc.bar_time)

        box.new(id.break_loc, id.top, time+1, id.btm, na
          , bgcolor = break_css
          , extend = extend.right
       
          , xloc = xloc.bar_time)
        // vien ob chưa dùng
        // line.new(id.loc, id.top, id.break_loc, id.top, xloc.bar_time, color = css.notransp())
        // line.new(id.loc, id.btm, id.break_loc, id.btm, xloc.bar_time, color = css.notransp())
        // line ob bị phá
        // line.new(id.break_loc, id.top, time+1, id.top, xloc.bar_time, extend.right, break_css.notransp(), line.style_dashed)
        // line.new(id.break_loc, id.btm, time+1, id.btm, xloc.bar_time, extend.right, break_css.notransp(), line.style_dashed)
    else
        box.new(id.loc, id.top, time, id.btm, na
          , bgcolor = css
          , extend = extend.right
       
          , xloc = xloc.bar_time)
        
        // line.new(id.loc, id.top, time, id.top, xloc.bar_time, extend.right, css.notransp())
        // line.new(id.loc, id.btm, time, id.btm, xloc.bar_time, extend.right, css.notransp())

//-----------------------------------------------------------------------------}

n = bar_index

[top, btm] = swings(length)
max = useBody ? math.max(close, open) : high
min = useBody ? math.min(close, open) : low

//-----------------------------------------------------------------------------}
// OB trên
//-----------------------------------------------------------------------------{
var bullish_ob = array.new<ob>(0)
bull_break_conf = 0

if close > top.y and not top.crossed
    top.crossed := true

    minima = max[1]
    maxima = min[1]
    loc = time[1]

    for i = 1 to (n - top.x)-1
        minima := math.min(min[i], minima)
        maxima := minima == min[i] ? max[i] : maxima
        loc := minima == min[i] ? time[i] : loc

    bullish_ob.unshift(ob.new(maxima, minima, loc))

if bullish_ob.size() > 0
    for i = bullish_ob.size()-1 to 0
        element = bullish_ob.get(i)
    
        if not element.breaker 
            if math.min(close, open) < element.btm
                element.breaker := true
                element.break_loc := time
        else
            if close > element.top
                bullish_ob.remove(i)
            else if i < showBull and top.y < element.top and top.y > element.btm 
                bull_break_conf := 1

//-----------------------------------------------------------------------------}
// OB dưới
//-----------------------------------------------------------------------------{
var bearish_ob = array.new<ob>(0)
bear_break_conf = 0

if close < btm.y and not btm.crossed
    btm.crossed := true

    minima = min[1]
    maxima = max[1]
    loc = time[1]

    for i = 1 to (n - btm.x)-1
        maxima := math.max(max[i], maxima)
        minima := maxima == max[i] ? min[i] : minima
        loc := maxima == max[i] ? time[i] : loc

    bearish_ob.unshift(ob.new(maxima, minima, loc))

if bearish_ob.size() > 0
    for i = bearish_ob.size()-1 to 0
        element = bearish_ob.get(i)

        if not element.breaker 
            if math.max(close, open) > element.top
                element.breaker := true
                element.break_loc := time
        else
            if close < element.btm
                bearish_ob.remove(i)
            else if i < showBear and btm.y > element.btm and btm.y < element.top 
                bear_break_conf := 1


//-----------------------------------------------------------------------------}
// Order Blocks
//-----------------------------------------------------------------------------{
for bx in box.all
    bx.delete()

for l in line.all
    l.delete()

if barstate.islast
    //Bullish
    if showBull > 0
        for i = 0 to math.min(showBull-1, bullish_ob.size())
            get_ob = bullish_ob.get(i)
            get_ob.display(bullCss, bullBreakCss)

    //Bearish
    if showBear > 0

        for i = 0 to math.min(showBear-1, bearish_ob.size())
            get_ob = bearish_ob.get(i)
            get_ob.display(bearCss, bearBreakCss)

//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}

//logo
title = input.string('MC War', 'Tittle', group='Tên')
c_title = input.color(color.new(color.yellow, 20), 'Title Color', group='Tên')
s_title = input.string('large', 'Title Size', options=['tiny', 'small', 'normal', 'large', 'huge', 'auto'], group='Tên')
a_title = input.string('center', 'Title Alignment', options=['center', 'left', 'right'], group='Tên')

//phụ đề
subtitle = input.string('Nguyễn Thanh Tuấn', group='Phụ đề')
c_subtitle = input.color(color.new(color.yellow, 40), 'Subitle Color', group='Phụ đề')
s_subtitle = input.string('normal', 'Subtitle Size', options=['tiny', 'small', 'normal', 'large', 'huge', 'auto'], group='Phụ đề')
a_subtitle = input.string('center', 'Subtitle Alignment', options=['center', 'left', 'right'], group='Phụ đề')

//Ngày giờ
symInfoCheck = input.bool(title='Ngày - Mả - TF', defval=true,group='Ngày giờ')
c_symInfo = input.color(color.new(color.yellow, 40), 'Subitle Color', group='Ngày giờ')
s_symInfo = input.string('normal', 'Subtitle Size', options=['tiny', 'small', 'normal', 'large', 'huge', 'auto'], group='Ngày giờ')
a_symInfo = input.string('left', 'Subtitle Alignment', options=['center', 'left', 'right'], group='Ngày giờ')



symInfo = syminfo.ticker + ' | ' + timeframe.period + (timeframe.isminutes ? 'M' : na)
date = str.tostring(dayofmonth(time_close)) + '/' + str.tostring(month(time_close)) + '/' + str.tostring(year(time_close))
//canh chỉnh
textVPosition = input.string('top', 'Trục X', options=['top', 'middle', 'bottom'], group='Vị trí tên')
textHPosition = input.string('right', 'Trục Y', options=['left', 'center', 'right'], group='Vị trí tên')

symVPosition = input.string('bottom', 'Trục X', options=['top', 'middle', 'bottom'], group='Vị trí ngày')
symHPosition = input.string('right', 'Trục Y', options=['left', 'center', 'right'], group='Vị trí ngày')
// nền
c_bg = input.color(color.new(color.blue, 100), 'Background', group='background')



textWatermark = table.new(textVPosition + '_' + textHPosition, 1, 3)
table.cell(textWatermark, 0, 0, title, 0, 0, c_title, a_title, text_size=s_title, bgcolor=c_bg)
table.cell(textWatermark, 0, 1, subtitle, 0, 0, c_subtitle, a_subtitle, text_size=s_subtitle, bgcolor=c_bg)



symWatermark = table.new(symVPosition + '_' + symHPosition, 5, 5)
if symInfoCheck == true
    table.cell(symWatermark, 0, 1, symInfo, 0, 0, c_symInfo, a_symInfo, text_size=s_symInfo, bgcolor=c_bg)
    table.cell(symWatermark, 0, 0, date, 0, 0, c_symInfo, a_symInfo, text_size=s_symInfo, bgcolor=c_bg)

Overview

Mc War v3 limits how many bearish and bullish blocks stay visible and can use candle bodies instead of wicks for zone edges. Broken blocks are recolored and extended to the right. Separate inputs control zone colors plus an on-chart title, subtitle, and symbol-timeframe label. It does not generate entries or exits.

Details

Published by

tuanmcwar on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Swingint30length
Số OB trênint5showBear
Số OB dướiint5showBull
Thu gọn OB không nên dùngboolfalseuseBody
OB trêncolorcolor.new(#ff9800, 90)bearCss
OB trên Breakcolorcolor.new(#ff1100, 100)bearBreakCss
OB dướicolorcolor.new(#ff9800, 90)bullCss
OB dưới Breakcolorcolor.new(#ff1100, 100)bullBreakCss
TittlestringMC Wartitle
Title Colorcolorcolor.new(color.yellow, 20)c_title
Title Sizestringlarges_title
Title Alignmentstringcentera_title
Show all 25 settings
SettingTypeDefaultVariable
subtitlestringNguyễn Thanh Tuấnsubtitle
Subitle Colorcolorcolor.new(color.yellow, 40)c_subtitle
Subtitle Sizestringnormals_subtitle
Subtitle Alignmentstringcentera_subtitle
Ngày - Mả - TFbooltruesymInfoCheck
Subitle Colorcolorcolor.new(color.yellow, 40)c_symInfo
Subtitle Sizestringnormals_symInfo
Subtitle Alignmentstringlefta_symInfo
Trục XstringtoptextVPosition
Trục YstringrighttextHPosition
Trục XstringbottomsymVPosition
Trục YstringrightsymHPosition
Backgroundcolorcolor.new(color.blue, 100)c_bg
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows

DE-tracker

by Allen1212
303 stars

This indicator plots labels on the TradingView price chart to mark ARK Invest's buy and sell trades for the DE stock. Buy transactions appear in green with X1 or X2 multipliers showing the number of ARK ETFs involved on the same day; sells appear in red. The m

Indicator v4 Support & resistanceSMC / ICT / price action
Updated 2 years ago · None stated GitHub repository of DE-tracker

This Pine Script indicator plots a ZigZag on the price chart. It identifies reversal points when price moves more than a set percentage from the last pivot. The script calculates forecasts using zigzag data and labels detected geometric patterns including harm

Indicator v4 TrendSupport & resistance

Golden Bullet Strategy

by TradersPost
228 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

Open Source Fractal

by cantolab
183 stars

This indicator implements the Fractal Model concept to plot market structure shifts, liquidity sweeps, and Change in State of Delivery (CISD) levels. It overlays custom higher-timeframe candle previews, open prices, and time markers directly on the price chart

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MIT GitHub repository of Open Source Fractal

Swing Failure Signals

by Ganador1
154 stars

This indicator calculates pivot highs and pivot lows to detect liquidity sweeps and Swing Failure Patterns. It identifies when price breaks past recent key swing highs or lows within a configurable historical window, then looks for a quick reversal or change i

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · Apache-2.0 GitHub repository of Swing Failure Signals

More SMC / ICT scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers