1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
312 lines of Pine Script v5 from Mcwar-v1.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.
Mcwar-v1.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 v1', overlay=true, max_lines_count=100)
// Constants
color CLEAR = color.rgb(0,0,0,100)
// Inputs
swingSize = input.int(15, 'Swing Length')
bosConfType = input.string('Candle Close', 'BOS Confirmation', ['Candle Close', 'Wicks'])
choch = input.bool(true, 'Show CHoCH', tooltip='Renames the first counter trend BOS to CHoCH' )
showSwing = input.bool(false, 'Show Swing Points', tooltip='Show or hide HH, LH, HL, LL')
bosColor = input.color(color.new(color.yellow, 30), 'Color', group='BOS Settings')
bosStyle = input.string('Dashed', 'Line Style', ['Solid', 'Dashed', 'Dotted'], group='BOS Settings')
bosWidth = input.int(1, 'Width', minval=1, group='BOS Settings')
// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
//Finding high and low pivots
pivHi = ta.pivothigh(high, swingSize, swingSize)
pivLo = ta.pivotlow(low, swingSize, swingSize)
//Tracking the previous swing levels to determine hh lh hl ll
var float prevHigh = na
var float prevLow = na
var int prevHighIndex = na
var int prevLowIndex = na
//Tracking whether previous levels have been breached
var bool highActive = false
var bool lowActive = false
bool hh = false
bool lh = false
bool hl = false
bool ll = false
//Variable to track the previous swing type, used later on to draw 0.5 Retracement Levels (HH = 2, LH = 1, HL = -1, LL = -2)
var int prevSwing = 0
if not na(pivHi)
if pivHi >= prevHigh
hh := true
prevSwing := 2
else
lh := true
prevSwing := 1
prevHigh := pivHi
highActive := true
prevHighIndex := bar_index - swingSize
if not na(pivLo)
if pivLo >= prevLow
hl := true
prevSwing := -1
else
ll := true
prevSwing := -2
prevLow := pivLo
lowActive := true
prevLowIndex := bar_index - swingSize
//Generating the breakout signals
bool highBroken = false
bool lowBroken = false
//Tracking prev breakout
var int prevBreakoutDir = 0
float highSrc = bosConfType == 'Candle Close' ? close : high
float lowSrc = bosConfType == 'Candle Close' ? close : low
if highSrc > prevHigh and highActive
highBroken := true
highActive := false
if lowSrc < prevLow and lowActive
lowBroken := true
lowActive := false
// Visual Output
//Swing level labels
if hh and showSwing
label.new(bar_index - swingSize, pivHi, 'HH', color=CLEAR, style=label.style_label_down, textcolor=chart.fg_color)
if lh and showSwing
label.new(bar_index - swingSize, pivHi, 'LH', color=CLEAR, style=label.style_label_down, textcolor=chart.fg_color)
if hl and showSwing
label.new(bar_index - swingSize, pivLo, 'HL', color=CLEAR, style=label.style_label_up, textcolor=chart.fg_color)
if ll and showSwing
label.new(bar_index - swingSize, pivLo, 'LL', color=CLEAR, style=label.style_label_up, textcolor=chart.fg_color)
//Generating the BOS Lines
if highBroken
line.new(prevHighIndex, prevHigh, bar_index, prevHigh, color=bosColor, style=lineStyle(bosStyle), width=bosWidth)
label.new(math.floor(bar_index - (bar_index - prevHighIndex) / 2), prevHigh, prevBreakoutDir == -1 and choch ? 'CHoCHHHHH' : 'BOSSSSS', color=CLEAR, textcolor=bosColor, size=size.tiny)
prevBreakoutDir := 1
if lowBroken
line.new(prevLowIndex, prevLow, bar_index, prevLow, color=bosColor, style=lineStyle(bosStyle), width=bosWidth)
label.new(math.floor(bar_index - (bar_index - prevLowIndex) / 2), prevLow, prevBreakoutDir == 1 and choch ? 'CHoCHHHHH' : 'BOSSSSS', color=CLEAR, textcolor=bosColor, style=label.style_label_up, size=size.tiny)
prevBreakoutDir := -1
// ------------------------------------------Tên---------------------------------------------
// ------------------------------------------Tên---------------------------------------------
// ------------------------------------------Tên---------------------------------------------
// ------------------------------------------Tên---------------------------------------------
// ------------------------------------------Tên---------------------------------------------
// ------------------------------------------Tên---------------------------------------------
//text inputs
//title settings
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')
//subtitle settings
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ờ')
//symbol info
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))
//text positioning
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')
//symbol info positioning
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')
//cell size
width = input.int(0, 'Width', minval=0, maxval=0, group='cell size')
height = input.int(0, 'Height', minval=0, maxval=0, group='cell size')
c_bg = input.color(color.new(color.blue, 100), 'Background', group='background')
//text watermark creation
textWatermark = table.new(textVPosition + '_' + textHPosition, 1, 3)
table.cell(textWatermark, 0, 0, title, width, height, c_title, a_title, text_size=s_title, bgcolor=c_bg)
table.cell(textWatermark, 0, 1, subtitle, width, height, c_subtitle, a_subtitle, text_size=s_subtitle, bgcolor=c_bg)
//symbol info watermark creation
symWatermark = table.new(symVPosition + '_' + symHPosition, 5, 5)
if symInfoCheck == true
table.cell(symWatermark, 0, 1, symInfo, width, height, c_symInfo, a_symInfo, text_size=s_symInfo, bgcolor=c_bg)
table.cell(symWatermark, 0, 0, date, width, height, c_symInfo, a_symInfo, text_size=s_symInfo, bgcolor=c_bg)
// ------------------------------------OB----------------------------------------------------------
// ------------------------------------OB----------------------------------------------------------
// ------------------------------------OB----------------------------------------------------------
// ------------------------------------OB----------------------------------------------------------
// ------------------------------------OB----------------------------------------------------------
// ------------------------------------OB----------------------------------------------------------
// ------------------------------------OB----------------------------------------------------------
plotOB = input.bool(defval=true, title='OB', group='Order Blocks')
obBullColor = input.color(defval=color.new(color.green, 90), title='Bullish OB Color', inline='Set Custom Color', group='Order Blocks')
obBearColor = input.color(defval=color.new(color.red, 90), title='Bearish OB Color', inline='Set Custom Color', group='Order Blocks')
obBoxBorder = input.string(defval=line.style_solid, title='OB Box Border Style', options=[line.style_dashed, line.style_dotted, line.style_solid], group='Order Blocks')
obBorderTransparency = input.int(defval=1, title='OB Border Box transparent', minval=0, maxval=100, group='Order Blocks')
obMaxBoxSet = input.int(defval=1000000, title='Số lượng OB', minval=1, maxval=100000000, group='Order Blocks', tooltip='Nhỏ nhất = 1, Lớn nhất = 100000000')
filterMitOB = input.bool(defval=true, title='Chỉnh màu OB bị phá qua', group='Order Blocks')
mitOBColor = input.color(defval=color.new(color.gray, 90), title=' Chọn màu OB bị phá qua', group='Order Blocks')
plotLabelOB = input.bool(defval=false, title='OB Label', inline='OB label', group='Order Blocks')
obLabelColor = input.color(defval=color.gray, title='Color', inline='OB label', group='Order Blocks')
obLabelSize = input.string(defval=size.small, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], inline='OB label', group='Order Blocks')
bosBoxFlag = input.bool(title='MC War', defval=false, group='HIHI', tooltip='Độ đẹp trai của MC War')
bosBoxLength = input.int(title='Bao nhiêu điểm', defval=10, minval=10, maxval=100, group='HIHI',tooltip='Thanh điểm 10')
plotOBFVG = input.bool(defval=true, title='Đánh dấu có OB+FVG', group='OB Có FVG')
obfvgBullColor = input.color(defval=color.new(color.white, 0), title='Bullish OB+FVG Color', group='OB Có FVG', inline='OBFVG Color')
obfvgBearColor = input.color(defval=color.new(color.white, 0), title='Bearish OB+FVG Color', group='OB Có FVG', inline='OBFVG Color')
//Box Types
var int _ob = 1
var int _fvg = 2
var int _rjb = 3
var int _bos = 4
//Box Labels
var string _obLabel = "OB"
var string _fvgLabel = "FVG"
var string _rjbLabel = "RJB"
var string _bosLabel = "BoS"
var string _plus = "+"
var string _minus = "-"
var string _empty = ""
//Box Arrays
var box[] _bearBoxesOB = array.new_box()
var box[] _bullBoxesOB = array.new_box()
var box[] _bearBoxesFVG = array.new_box()
var box[] _bullBoxesFVG = array.new_box()
var box[] _bearBoxesRJB = array.new_box()
var box[] _bullBoxesRJB = array.new_box()
var box[] _bearBoxesBOS = array.new_box()
var box[] _bullBoxesBOS = array.new_box()
//Functions
isUp(index) =>
close[index] > open[index]
isDown(index) =>
close[index] < open[index]
isObUp(index) =>
isDown(index + 1) and isUp(index) and close[index] > high[index + 1]
isObDown(index) =>
isUp(index + 1) and isDown(index) and close[index] < low[index + 1]
isFvgUp(index) =>
(low[index] > high[index + 2])
isFvgDown(index) =>
(high[index] < low[index + 2])
//Function to Calculte Box Length
_controlBox(_boxes, _high, _low, _type) =>
if array.size(_boxes) > 0
for i = array.size(_boxes) - 1 to 0 by 1
_box = array.get(_boxes, i)
_boxLow = box.get_bottom(_box)
_boxHigh = box.get_top(_box)
_boxRight = box.get_right(_box)
if bosBoxFlag and _type == _bos
if na or (bar_index + bosBoxLength - 1 == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + bosBoxLength - 1)
else if (filterMitOB and _type == _ob)
if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)
else
if _type == _ob
box.set_bgcolor(_box, mitOBColor)
box.set_border_color(_box, mitOBColor)
else
if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)
//////////////////// Order Block //////////////////
//Bullish OB Box Plotting
if isObUp(1) and plotOB
_bullboxOB = box.new(left=bar_index - 2, top=high[2], right=bar_index, bottom=math.min(low[2], low[1]), border_color=color.new(obBullColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBullColor,
text=plotLabelOB ? _obLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
if array.size(_bullBoxesOB) > obMaxBoxSet
box.delete(array.shift(_bullBoxesOB))
array.push(_bullBoxesOB, _bullboxOB)
//Bearish OB Box Plotting
if isObDown(1) and plotOB
_bearboxOB = box.new(left=bar_index - 2, top=math.max(high[2], high[1]), right=bar_index, bottom=low[2], border_color=color.new(obBearColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBearColor,
text=plotLabelOB ? _obLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
if array.size(_bearBoxesOB) > obMaxBoxSet
box.delete(array.shift(_bearBoxesOB))
array.push(_bearBoxesOB, _bearboxOB)
if plotOB
_controlBox(_bearBoxesOB, high, low, _ob)
_controlBox(_bullBoxesOB, high, low, _ob)
///////////////// Stacked OB + FVG //////////////////
plotshape(plotOBFVG and isFvgDown(0) and isObDown(1), "Bearish OB+FVG Stack", style=shape.labeldown, location=location.abovebar, color=obfvgBearColor, size=size.small)
plotshape(plotOBFVG and isFvgUp(0) and isObUp(1), "Bullish OB+FVG Stack", style=shape.labelup, location=location.belowbar, color=obfvgBullColor, size=size.small)
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}
Overview
Mc War detects swing highs and lows using pivot calculations to label higher highs, lower highs, higher lows, and lower lows. The script draws lines and labels for Break of Structure (BOS) and Change of Character (CHoCH) upon breakout confirmation via close or wick. Settings allow full customization of swing lengths, line aesthetics, and order block colors.
Market structure pivot detection for HH, LH, HL, and LL
Break of Structure and Change of Character annotations
Customizable confirmation via candle closes or wicks
Configurable Order Block color and line styling settings
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Swing Length
int
15
swingSize
BOS Confirmation
string
Candle Close
bosConfType
Show CHoCH
bool
true
choch
Show Swing Points
bool
false
showSwing
Color
color
color.new(color.yellow, 30)
bosColor
Line Style
string
Dashed
bosStyle
Width
int
1
bosWidth
Tittle
string
MC War
title
Title Color
color
color.new(color.yellow, 20)
c_title
Title Size
string
large
s_title
Title Alignment
string
center
a_title
subtitle
string
Nguyễn Thanh Tuấn
subtitle
Show all 40 settings
Setting
Type
Default
Variable
Subitle Color
color
color.new(color.yellow, 40)
c_subtitle
Subtitle Size
string
normal
s_subtitle
Subtitle Alignment
string
center
a_subtitle
Ngày - Mả - TF
bool
true
symInfoCheck
Subitle Color
color
color.new(color.yellow, 40)
c_symInfo
Subtitle Size
string
normal
s_symInfo
Subtitle Alignment
string
left
a_symInfo
Trục X
string
top
textVPosition
Trục Y
string
right
textHPosition
Trục X
string
bottom
symVPosition
Trục Y
string
right
symHPosition
Width
int
0
width
Height
int
0
height
Background
color
color.new(color.blue, 100)
c_bg
OB
bool
true
plotOB
Bullish OB Color
color
color.new(color.green, 90)
obBullColor
Bearish OB Color
color
color.new(color.red, 90)
obBearColor
OB Box Border Style
string
line.style_solid
obBoxBorder
OB Border Box transparent
int
1
obBorderTransparency
Số lượng OB
int
1000000
obMaxBoxSet
Chỉnh màu OB bị phá qua
bool
true
filterMitOB
Chọn màu OB bị phá qua
color
color.new(color.gray, 90)
mitOBColor
OB Label
bool
false
plotLabelOB
Color
color
color.gray
obLabelColor
Size
string
size.small
obLabelSize
MC War
bool
false
bosBoxFlag
Bao nhiêu điểm
int
10
bosBoxLength
Đánh dấu có OB+FVG
bool
true
plotOBFVG
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.
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
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
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
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
Indicatorv6SMC / ICT / price actionSessions & time
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
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