Indicator · Pine Script v5 · On the chart

Mc War OB + EMA

by tuanmcwar· code credited to GainzAlgo

This price-chart indicator plots a 34-period EMA and an 89-period EMA and defines buy and sell conditions from their relationship to the prior close.

View on GitHub

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

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

ob_ema.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()
high_value = high
low_value = low
volume_value = volume

price_change = ((high_value - low_value) / high_value) * 100

//Functions



isUp(index) =>
    close[index] > open[index]  
isDown(index) =>
    close[index] < open[index]

//  volume lớn hơn cây trước 50%
volumeUp(index)=>
    volume[index]  >= 1.5* volume [index + 1 ] 
//  giá ema 34 > ema89    
emaUp(index) => 
    ema34[index + 1] > ema89[index + 1]

emaDown(index) => 
    ema34[index + 1] < ema89[index + 1]
 //  giá mở cửa không được lớn hơn 0,5% ema 34
openEmaup(index)=>
    close[index + 1]  < ema34 * 1.005

openEmadown(index)=>
    close[index + 1]  > ema34 * .995
// biên độ nến
rangeNen(index)=> 
    ((high[index + 1] - low[index + 1]) / high[index + 1]) * 100
        
        
isObUp(index) => 
    isDown(index + 1)  and isUp(index) and close[index] > high[index + 1]       and   volumeUp(index) and emaUp(index) and openEmaup(index) and rangeNen(index) > .5  and low[index] > low[index + 1]
   

isObDown(index) =>
       isUp(index + 1) and isDown(index) and high[index - 1] < low[index + 1]    and volumeUp(index) and emaDown(index) and openEmadown(index) and rangeNen(index) > .5 and high[index] < high [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 //////////////////

///////////////// Stacked OB + FVG //////////////////


Bearish = isFvgDown(0) and isObDown(1)
Bullish = isFvgUp(0) and isObUp(1)
plotshape(plotOBFVG and Bearish  , "Bearish OB+FVG Stack", style=shape.labeldown, location=location.abovebar, color=obfvgBearColor, size=size.small)
plotshape(plotOBFVG and  Bullish , "Bullish OB+FVG Stack", style=shape.labelup, location=location.belowbar, color=obfvgBullColor, size=size.small)

if (Bullish and barstate.isconfirmed)
    alert('Sell Signal Triggered: EMA 34 < EMA 89 and Open Price is not less than EMA 34 by more than 0.5%', alert.freq_once_per_bar_close)

if (Bearish and barstate.isconfirmed)
    alert('Sell Signal Triggered: EMA 34 < EMA 89 and Open Price is not less than EMA 34 by more than 0.5%', alert.freq_once_per_bar_close)
















// 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(plotOBFVG and isFvgUp(0) and isObUp(1)  , "Bullish OB+FVG Stack", style=shape.labelup, location=location.belowbar, color=obfvgBullColor, size=size.small)
// // plotshape(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 is built to draw bullish and bearish order-block boxes, optionally recolor blocks that price has broken, and mark cases where an order block coincides with a fair value gap. Settings control box count, border style and transparency, label appearance, and the OB plus FVG colors. The shown code does not define exits or risk rules.

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

Moving averages, SMC / ICT / price action

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

This indicator detects compressed corrective coils inside a higher-timeframe trend and signals when they resolve into clean directional breaks. It plots compression bands, fractal boxes, efficiency scores, and a light dashboard on the price chart. Signals clas

Indicator v6 Volatility & bandsSMC / ICT / price action
Updated yesterday · MIT GitHub repository of Compression Fractal Release [WavesUnchained]

MattSuite V3

by mmarbmatt
8 stars

MattSuite V3 is an overlay indicator that combines market-structure and trend tools on the price chart. It identifies bullish and bearish fair value gaps and estimates their strength, flags break of structure and change of character, and marks order blocks. It

Indicator v5 SMC / ICT / price actionVolatility & bands
Updated 1 year ago · None stated GitHub repository of MattSuite V3
6 stars

Capital41 Confluence Core plots an EMA or SMA on the price chart and combines its direction with RSI, Williams %R, and a liquidity-sweep check into long and short confluence signals. Signal strictness is Strict, Standard, or Loose, which changes how far the os

Indicator v6 Oscillators & momentumMoving averages
Updated 8 weeks ago · MIT GitHub repository of Capital41 Confluence Core

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

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