Indicator · Pine Script v5 · On the chart

Mc War OB + EMA

by tuanmcwar· code credited to GainzAlgo

Plots 34-period and 89-period exponential moving averages alongside Smart Money Concept order blocks directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code174
Settings16inputs
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

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

OB_EMA_hop_nhat.pine
// © GainzAlgo

//@version=5
// @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 OB + EMA', overlay=true, max_lines_count=100)
// EMA 
// len1 = input(34, title='EMA 34',group='EMA')
// len2 = input(89, title='EMA 89',group='EMA')
// len3 = input(200, title='EMA 200',group='EMA')


// M1 = ta.ema(close, len1)
// M2 = ta.ema(close, len2)
// M3 = ta.ema(close, len3)

// plot(M1, color=color.new(#eeff00, 20), linewidth=1)
// plot(M2, color=color.new(color.blue, 0), linewidth=3)
// plot(M3, color=color.new(#f8f8f8, 5), linewidth=4)

ema34 = ta.ema(close, 34)
ema89 = ta.ema(close, 89)
// isObUp(index) =>
//     isDown(index + 1) and isUp(index) and close[index] > high[index + 1] and   buySignal
 
// Điều kiện báo điểm mua
buySignal(index) =>  (ema34 > ema89 and  close[index - 1] >  ema89 and close[index - 1] <= ema34 * 1.001)
sellSignal(index) => ( ema34 < ema89  and  close[index - 1] < ema89 and close[index - 1] >= ema34 * 1.001)


// Vẽ EMA 34 và EMA 89 trên biểu đồ
plot(ema34, color=color.blue, title="EMA 34")
plot(ema89, color=color.red, title="EMA 89")



// // ---------------------------------------------------------------------------------------------- 
// // ---------------------------------------------------------------------------------------------- 
// // ---------------------------------------------------------------------------------------------- 
// // ---------------------------------------------------------------------------------------------- 
// // ---------------------------------------------------------------------------------------------- 
// // ---------------------------------------------------------------------------------------------- 
// // ---------------------------------------------------------------------------------------------- 

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.green, 0), title='Bullish OB+FVG Color', group='OB Có FVG', inline='OBFVG Color')
obfvgBearColor = input.color(defval=color.new(color.red, 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] and ema34[index] > ema89[index]              and            open[index ]  <= ema34 * 1.005   and     volume[index]  >= 1.5* volume [2] 
 
isObDown(index) =>
       isUp(index + 1) and isDown(index) and close[index] < low[index + 1] and ema34[index] < ema89[index]              and            open[index ]  >= ema34 * .995 and  volume[index]  >= 1.5* volume [2] 
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 //////////////////

///////////////// 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)


// plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="Buy")
// plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="sell Signal", text="sell")

Overview

Mc War OB + EMA visualizes bullish and bearish order block zones as customizable boxes, identifies confluence between order blocks and fair value gaps, and tracks mitigated blocks by recoloring broken zones. User settings control order block styling, label visibility, mitigation coloring, and box quantities.

Details

Published by

tuanmcwar on GitHub

Code credit

GainzAlgo, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

SMC / ICT / price action, Moving averages, Support & resistance

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
OBbooltrueplotOB
Bullish OB Colorcolorcolor.new(color.green, 90)obBullColor
Bearish OB Colorcolorcolor.new(color.red, 90)obBearColor
OB Box Border Stylestringline.style_solidobBoxBorder
OB Border Box transparentint1obBorderTransparency
Số lượng OBint1000000obMaxBoxSet
Chỉnh màu OB bị phá quabooltruefilterMitOB
Chọn màu OB bị phá quacolorcolor.new(color.gray, 90)mitOBColor
OB LabelboolfalseplotLabelOB
Colorcolorcolor.grayobLabelColor
Sizestringsize.smallobLabelSize
MC WarboolfalsebosBoxFlag
Show all 16 settings
SettingTypeDefaultVariable
Bao nhiêu điểmint10bosBoxLength
Đánh dấu có OB+FVGbooltrueplotOBFVG
Bullish OB+FVG Colorcolorcolor.new(color.green, 0)obfvgBullColor
Bearish OB+FVG Colorcolorcolor.new(color.red, 0)obfvgBearColor
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

HH-LL Buy/Sell + EMA

by vinitpatil519
5 stars

This overlay indicator classifies market structure with an ATR-based ZigZag that marks higher highs, higher lows, lower highs, and lower lows. A state machine plots buy and sell labels on the confirmation bar, not on the earlier pivot, and by default waits for

Indicator v5 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of HH-LL Buy/Sell + EMA

Imbalance + 3EMA

by linkcla
4 stars

This overlay indicator plots three exponential moving averages on the price chart and marks imbalance zones with boxes. Each EMA has its own length, color, and visibility toggle, with defaults of 10, 50, and 200. Fair value gaps are detected across three bars

Indicator v5 Moving averagesSMC / ICT / price action
Updated 2 years ago · None stated GitHub repository of Imbalance + 3EMA
4 stars

This indicator computes the Watchtower Axis as a 257-period weighted moving average of closing prices to establish the main trend baseline. It defines volatility gates using the highest high and lowest low over 463 periods, along with a 377-period exponential

Indicator v6 TrendMoving averages
Updated 10 months ago · MIT GitHub repository of Miela Labs | John Dee's Watchtower
3 stars

This indicator detects bearish M and bullish W chart formations on the price chart based on Steve Mauro's Beat The Market Maker (BTMM) methodology. It emphasizes second-leg entries confirmed by a clean close across the 13 EMA, volume filters, and minimum ATR p

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · None stated GitHub repository of BTMM M&W Pattern Detection

This indicator identifies Smart Money Concepts structure alongside a four-line moving average ribbon on the price chart. It detects swing highs and lows across a user-defined lookback period, generating price action labels such as higher highs, lower highs, hi

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · None stated GitHub repository of FluidTrades - SMC Lite + Moving Average Ribbon

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers