Skip to main content

EMA Bands Strategy for Crypto Trading Automation with MIRRORPIP

What is the EMA Bands Strategy?

The EMA Bands Strategy is an advanced trend-following TradingView Pine Script strategy designed to identify market breakouts using Exponential Moving Average (EMA) bands. It is fully compatible with MIRRORPIP, allowing traders to automate entries, exits, reversals, and risk management across multiple crypto exchanges directly from TradingView. This strategy creates a dynamic price channel using:
  • EMA High Band
  • EMA Low Band
The area between these two EMAs forms a trend-detection zone. Whenever price breaks out of this zone, the strategy generates automated trading signals that can be executed through MIRRORPIP on supported crypto exchanges.

Why Use EMA Bands?

Traditional moving average strategies often suffer from excessive noise and false signals during sideways markets. The EMA Bands Strategy solves this by creating a buffer zone between the EMA High and EMA Low lines, helping traders: ✅ Capture strong trending moves ✅ Avoid unnecessary entries inside consolidation zones ✅ Automatically reverse positions when trend direction changes ✅ Apply custom Take Profit (TP), Stop Loss (SL), and Trailing Stop Loss (TSL) ✅ Fully automate trading using TradingView alerts and MIRRORPIP

How the EMA Bands Strategy Works

The strategy plots two separate EMA lines:

EMA High Band

Calculated using candle highs. Acts as the upper breakout level.

EMA Low Band

Calculated using candle lows. Acts as the lower breakout level. Together they create a trading band that helps determine trend direction.

Long Entry Conditions

A Buy (Long) position is triggered when:
  1. Price closes above the EMA High Band.
  2. The candle closes outside the upper band.
  3. A bullish breakout is confirmed.

Long Stop Loss

The default stop loss is: EMA Low Band This means the trade remains active until price invalidates the bullish structure.

Short Entry Conditions

A Sell (Short) position is triggered when:
  1. Price closes below the EMA Low Band.
  2. The candle closes outside the lower band.
  3. A bearish breakout is confirmed.

Short Stop Loss

The default stop loss is: EMA High Band This allows the strategy to stay aligned with the prevailing bearish trend.

Exit and Reverse Logic

The EMA Bands Strategy follows an Exit and Reverse (SAR) model.

Example

Suppose the strategy is currently Long. If price closes below the EMA Low Band:
  • Existing Long position is closed.
  • New Short position is immediately opened.
Similarly: If the strategy is currently Short and price closes above the EMA High Band:
  • Existing Short position is closed.
  • New Long position is immediately opened.
This ensures the strategy always stays aligned with the latest market direction.

Custom Risk Management Features

While the default strategy uses EMA Bands as dynamic stop levels, MIRRORPIP’s EMA Bands Strategy includes advanced risk management controls. Users can configure:

Take Profit (TP)

Automatically close profitable positions once a target is reached. Supported modes:
  • Fixed Points
  • Percentage-Based Targets

Stop Loss (SL)

Protect capital by defining maximum acceptable loss. Supported modes:
  • Fixed Points
  • Percentage-Based Stops

Trailing Stop Loss (TSL)

Lock in profits while allowing winning trades to continue running. Supported modes:
  • Fixed Points
  • Percentage-Based Trailing Stops
These settings can be customized directly inside the strategy settings panel in TradingView.

Benefits of Using TP, SL and TSL

Fixed Take Profit

Suitable for:
  • Range-bound markets
  • Quick scalping setups
  • Defined reward targets

Percentage Take Profit

Suitable for:
  • Swing trading
  • Position trading
  • Volatile crypto assets

Fixed Stop Loss

Suitable when traders want exact risk control.

Percentage Stop Loss

Ideal for trading multiple assets with varying price ranges.

Trailing Stop Loss

Perfect for:
  • Trend-following strategies
  • Capturing large market moves
  • Maximizing winning trades

Multi-Exchange Compatibility

The EMA Bands Strategy is fully compatible with MIRRORPIP’s automation engine. You can automate trades on more than 8 supported crypto exchanges including:
  • Binance
  • Coinswitch
  • Mudrex
  • Bybit
  • Delta Exchange
  • Shark Exchange
and other supported exchanges available on the MIRRORPIP platform.

TradingView Automation with MIRRORPIP

One of the biggest advantages of this strategy is that the MIRRORPIP integration code is already embedded inside the Pine Script. This means users do not need to write any Pine Script code manually. Simply configure the strategy and start automating.

How to Automate the EMA Bands Strategy

Step 1: copy this strategy source code

// 

//@version=5
strategy(" EMA Bands Strategy v1.0", shorttitle=" EMA Bands Strategy", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1, pyramiding = 0, initial_capital=300000, currency=currency.NONE, commission_value=0, commission_type=strategy.commission.percent, process_orders_on_close=false, calc_on_every_tick=true, calc_on_order_fills = false)

////======================================================
paraTradeMode = input.string(title='Trade Mode', defval='Both', options=['Both', 'LongOnly', 'ShortOnly'], group = "Trade Settings")
paraSystemMode = input.session(defval="Intraday", title="System Mode", options=["Intraday", "Positional"], group = "Trade Settings")
s = input.session(title='Intraday Start Session:', defval='0915-1445', group='Trade Settings')
e = input.session(title='Intraday End Session:', defval='1500-1515', group='Trade Settings')

paraEMA = input.int(20, "EMA Period : ", minval = 1, group = "EMA Settings")

paraTGTMode = input.string(defval="%", title="Target : ", options=["Off", "%", "Pts"], inline = "TGT", group = "Target Settings")
paraTGT1 = input.float(1, "T1 : ", minval = 0, inline = "TGT", group = "Target Settings")
paraTGT = input.float(2, "T2 : ", minval = 0.1, inline = "TGT", group = "Target Settings")

paraSLMode = input.string(defval="%", title="Stoploss : ", options=["Off", "%", "Pts"], inline = "SL", group = "Stoploss Settings")
paraSL = input.float(1, "Value : ", minval = 0.1, inline = "SL", group = "Stoploss Settings")

paraTSLMode = input.string(defval="%", title="Trail SL : ", options=["Off", "%", "Pts"], inline = "TSL", group = "TSL Settings")
paraTSL = input.float(0.50, "Value : ", minval = 0.1, inline = "TSL", group = "TSL Settings")

paraShowDashboard = input.bool(true, "Show Strategy Dashboard")
////======================================================

////======================================================
grpAlgo = "Algo Setup"
paraExchange = input.string(title='Exchange', defval='delta', group=grpAlgo)
paraCode = input.string(title='Code', defval='XXXXXX', group=grpAlgo)
paraQtyType = input.string(title="Quantity Type", defval='Fixed',options=['Fixed','Exposure'], group=grpAlgo)
paraQty = input.float(title='Quantity ', defval=1, minval=0, group=grpAlgo, tooltip='Qty in Lots for Futures')
paraT1Qty = input.float(title='Target-1 Exit Qty (%)', defval=0, minval=0, maxval = 100, group=grpAlgo, tooltip='Qty in Percentage')
paraMaxProfit = input.int(0, "Max Profit Per Trade", 0, group=grpAlgo, tooltip='Exit on Max. Profit in Rs.')
paraMaxLoss = input.int(0, "Max Loss Per Trade", 0, group=grpAlgo, tooltip='Exit on Max. Loss in Rs.')
////======================================================

////======================================================
EMAH = ta.ema(high, paraEMA)
EMAL = ta.ema(low, paraEMA)
////======================================================

////======================================================
FC = session.isfirstbar
LC = session.islastbar

st = paraSystemMode=="Positional" ? 1 : time(timeframe.period, s)  
et = paraSystemMode=="Intraday" and time(timeframe.period, e)

eBuy1 = (ta.crossover(close, EMAH) or (paraSystemMode=="Intraday" and st and not st[1] and close > EMAH)) and barstate.isconfirmed
eShort1 = (ta.crossunder(close, EMAL) or (paraSystemMode=="Intraday" and st and not st[1] and close < EMAL)) and barstate.isconfirmed

MainSignal = 0
BuySignal = paraTradeMode!="ShortOnly" and st and eBuy1 and barstate.isconfirmed and (nz(MainSignal[1]) <= 0)
ShortSignal = paraTradeMode!="LongOnly" and st and eShort1 and barstate.isconfirmed and (nz(MainSignal[1]) >= 0)
SellSignal = (((ShortSignal or eShort1) and barstate.isconfirmed) or et) and (nz(MainSignal[1]) == 1)
CoverSignal = (((BuySignal or eBuy1) and barstate.isconfirmed) or et) and (nz(MainSignal[1]) == -1)
MainSignal := BuySignal ? 1 : ShortSignal ? -1 : ((SellSignal and MainSignal[1] > 0) or strategy.position_size == 0) ? 0 : ((CoverSignal and MainSignal[1] < 0) or strategy.position_size == 0) ? 0 : MainSignal[1]
////======================================================

////======================================================
symbol = syminfo.ticker

eBuyPrice = ta.valuewhen(BuySignal, close, 0)
eShortPrice = ta.valuewhen(ShortSignal, close, 0)

LESym = str.tostring(syminfo.ticker) 
LXSym = str.tostring(syminfo.ticker) 
SESym = str.tostring(syminfo.ticker) 
SXSym = str.tostring(syminfo.ticker) 

var float BuyTradeQty = na
var float ShortTradeQty = na

BuyTradeQty := paraQty
ShortTradeQty := paraQty

if (paraQtyType=="Exposure")
    BuyTradeQty := paraQty / eBuyPrice
    BuyTradeQty := math.round(BuyTradeQty / syminfo.pointvalue) 
    ShortTradeQty := paraQty / eShortPrice
    ShortTradeQty := math.round(ShortTradeQty / syminfo.pointvalue) 

    if (BuyTradeQty < 0)
        BuyTradeQty := 1
    if (ShortTradeQty < 0)
        ShortTradeQty := 1

buyData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LESym + '", "order_type": "BUY", "instrument_type": "NA", "quantity": "' + str.tostring(BuyTradeQty) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'
sellData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LXSym + '", "order_type": "SELL", "instrument_type": "NA", "quantity": "' + str.tostring(BuyTradeQty) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'
shortData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SESym + '", "order_type": "SHORT", "instrument_type": "NA", "quantity": "' + str.tostring(ShortTradeQty) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'
coverData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SXSym + '", "order_type": "COVER", "instrument_type": "NA", "quantity": "' + str.tostring(ShortTradeQty) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'
////======================================================

////======================================================
if BuySignal and strategy.position_size < 0 
    strategy.entry('BUY', strategy.long, comment='Buy', qty=BuyTradeQty, alert_message="["+coverData+","+buyData+"]")
else if BuySignal and strategy.position_size == 0 
    strategy.entry('BUY', strategy.long, comment='Buy', qty=BuyTradeQty, alert_message="["+buyData+"]")

if ShortSignal and strategy.position_size > 0 
    strategy.entry('SHORT', strategy.short, comment='Short', qty=ShortTradeQty, alert_message="["+sellData+","+shortData+"]")
else if ShortSignal and strategy.position_size == 0 
    strategy.entry('SHORT', strategy.short, comment='Short', qty=ShortTradeQty, alert_message="["+shortData+"]")

var float BuyPrice = na
var float ShortPrice = na
var float BuyTGT = na
var float ShortTGT = na
var float BuyTGT1 = na
var float ShortTGT1 = na
var float BuySL = na
var float ShortSL = na
var float BuyTSL = na
var float ShortTSL = na

ut = (paraTGTMode != "Off")
us = (paraSLMode != "Off")

if (strategy.position_size > 0 and strategy.position_size[1] <= 0)
    BuyPrice := strategy.position_avg_price
    if (paraSLMode=="%")
        BuySL := BuyPrice * (1-(paraSL/100))
    else if (paraSLMode=="Pts")
        BuySL := BuyPrice - (paraSL)

    if (paraTGTMode=="%")
        BuyTGT1 := BuyPrice * (1+(paraTGT1/100))
        BuyTGT := BuyPrice * (1+(paraTGT/100))
    else if (paraTGTMode=="Pts")
        BuyTGT1 := BuyPrice + (paraTGT1)
        BuyTGT := BuyPrice + (paraTGT)

if (strategy.position_size < 0 and strategy.position_size[1] >= 0)
    ShortPrice := strategy.position_avg_price
    if (paraSLMode=="%")
        ShortSL := ShortPrice * (1+(paraSL/100))
    else if (paraSLMode=="Pts")
        ShortSL := ShortPrice + (paraSL)

    if (paraTGTMode=="%")
        ShortTGT1 := ShortPrice * (1-(paraTGT1/100))
        ShortTGT := ShortPrice * (1-(paraTGT/100))
    else if (paraTGTMode=="Pts")
        ShortTGT1 := ShortPrice - (paraTGT1)
        ShortTGT := ShortPrice - (paraTGT)

if (paraTSLMode != "Off")
    if (strategy.position_size > 0 and strategy.position_size[1] > 0)
        if (paraTSLMode=="%")
            BuyTSL := high[1] * (1-(paraTSL/100))
        else
            BuyTSL := high[1] - paraTSL
        if (BuySL < BuyTSL)
            BuySL := BuyTSL
    if (strategy.position_size < 0 and strategy.position_size[1] < 0)
        if (paraTSLMode=="%")
            ShortTSL := low[1] * (1+(paraTSL/100))
        else
            ShortTSL := low[1] + paraTSL
        if (ShortSL > ShortTSL)
            ShortSL := ShortTSL

if (paraMaxProfit > 0)
    if (strategy.position_size > 0 and strategy.opentrades.profit(strategy.opentrades - 1) >= paraMaxProfit)
        strategy.close("BUY", immediately = true, alert_message="["+sellData+"]")
    if (strategy.position_size < 0 and strategy.opentrades.profit(strategy.opentrades - 1) >= paraMaxProfit)
        strategy.close("SHORT", immediately = true, alert_message="["+coverData+"]")

if (paraMaxLoss > 0)
    if (strategy.position_size > 0 and strategy.opentrades.profit(strategy.opentrades - 1) <= -(paraMaxLoss))
        strategy.close("BUY", immediately = true, alert_message="["+sellData+"]")
    if (strategy.position_size < 0 and strategy.opentrades.profit(strategy.opentrades - 1) <= -(paraMaxLoss))
        strategy.close("SHORT", immediately = true, alert_message="["+coverData+"]")

Pos_Size = math.abs(strategy.position_size)
T1ExQty = math.round(Pos_Size*(paraT1Qty/100))
TPsellData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LXSym + '", "order_type": "SELL", "instrument_type": "NA", "quantity": "' + str.tostring(T1ExQty) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'
TPcoverData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SXSym + '", "order_type": "COVER", "instrument_type": "NA", "quantity": "' + str.tostring(T1ExQty) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'

sellData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LXSym + '", "order_type": "SELL", "instrument_type": "NA", "quantity": "' + str.tostring(Pos_Size) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'
coverData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SXSym + '", "order_type": "COVER", "instrument_type": "NA", "quantity": "' + str.tostring(Pos_Size) + '", "tp": "0", "sl": "0", "code": "'+paraCode+'"}'

if ut == true and us == false
    if (strategy.position_size > 0)
        if (paraT1Qty > 0 and paraTGT1 > 0)
            strategy.exit(id="LongT1Exit", from_entry="BUY", qty = T1ExQty, limit=BuyTGT1, comment="TPSell", alert_message="["+TPsellData+"]", oca_name = "LX1")
        strategy.exit(id='LongExit', comment="Sell", from_entry='BUY', limit=BuyTGT, alert_message="["+sellData+"]")
    if (strategy.position_size < 0)
        if (paraT1Qty > 0 and paraTGT1 > 0)
            strategy.exit(id="ShortT1Exit", from_entry="SHORT", qty = T1ExQty, limit=ShortTGT1, comment="TPCover", alert_message="["+TPcoverData+"]", oca_name = "SX1")
        strategy.exit(id='ShortExit', comment="Cover", from_entry='SHORT', limit=ShortTGT, alert_message="["+coverData+"]")
if us == true and ut == false 
    if (strategy.position_size > 0)
        strategy.exit(id='LongExit', comment="Sell", from_entry='BUY', stop=BuySL, alert_message="["+sellData+"]")
    if (strategy.position_size < 0)
        strategy.exit(id='ShortExit', comment="Cover", from_entry='SHORT', stop=ShortSL, alert_message="["+coverData+"]")
if ut == true and us == true
    if (strategy.position_size > 0)
        if (paraT1Qty > 0 and paraTGT1 > 0)
            strategy.exit(id="LongT1Exit", from_entry="BUY", qty = T1ExQty, limit=BuyTGT1, stop=BuySL, comment="TPSell", alert_message="["+TPsellData+"]", oca_name = "LX1")
        strategy.exit(id='LongExit', comment="Sell", from_entry='BUY', limit=BuyTGT, stop=BuySL, alert_message="["+sellData+"]")
    if (strategy.position_size < 0)
        if (paraT1Qty > 0 and paraTGT1 > 0)
            strategy.exit(id="ShortT1Exit", from_entry="SHORT", qty = T1ExQty, limit=ShortTGT1, stop=ShortSL, comment="TPCover", alert_message="["+TPcoverData+"]", oca_name = "SX1")
        strategy.exit(id='ShortExit', comment="Cover", from_entry='SHORT', limit=ShortTGT, stop=ShortSL, alert_message="["+coverData+"]")

if (et or (SellSignal and (not ShortSignal))) and strategy.position_size > 0 
    strategy.cancel('LongExit')
    strategy.cancel('LongT1Exit')
    strategy.close(id='BUY', comment="Sell", alert_message="["+sellData+"]")

if (et or (CoverSignal and (not BuySignal))) and strategy.position_size < 0 
    strategy.cancel('ShortExit')
    strategy.cancel('ShortT1Exit')
    strategy.close(id='SHORT', comment="Cover", alert_message="["+coverData+"]")

if (strategy.position_size <= 0)
    strategy.cancel('LongExit')
    strategy.cancel('LongT1Exit')
if (strategy.position_size >= 0)
    strategy.cancel('ShortExit')
    strategy.cancel('ShortT1Exit')
////======================================================

////======================================================
//plotshape(BuySignal, style=shape.triangleup , location=location.belowbar, color=color.green, size=size.normal)
//plotshape(ShortSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.normal)
//plotshape(strategy.position_size>0?SellSignal:na, style=shape.triangledown , location=location.abovebar, color=color.green, size=size.small)
//plotshape(strategy.position_size<0?CoverSignal:na, style=shape.triangleup, location=location.belowbar, color=color.red, size=size.small)

plot(EMAH, "EMA-High", color.green, 1, plot.style_line)
plot(EMAL, "EMA-Low", color.red, 1, plot.style_line)

plot((strategy.position_size > 0)?BuyPrice:na, color=color.fuchsia, linewidth=1, style=plot.style_linebr)
plot((strategy.position_size > 0) and paraTGT1?BuyTGT1:na, color=color.blue, linewidth=1, style=plot.style_linebr)
plot((strategy.position_size > 0)?BuyTGT:na, color=color.blue, linewidth=1, style=plot.style_linebr)
plot((strategy.position_size > 0)?BuySL:na, color=color.orange, linewidth=1, style=plot.style_linebr)

plot((strategy.position_size < 0)?ShortPrice:na, color=color.fuchsia, linewidth=1, style=plot.style_linebr)
plot((strategy.position_size < 0) and paraTGT1?ShortTGT1:na, color=color.blue, linewidth=1, style=plot.style_linebr)
plot((strategy.position_size < 0)?ShortTGT:na, color=color.blue, linewidth=1, style=plot.style_linebr)
plot((strategy.position_size < 0)?ShortSL:na, color=color.orange, linewidth=1, style=plot.style_linebr)
////======================================================

////======================================================
totalCols = 2
totalRows = 5 
stgTGTFlag = paraTGTMode != "Off"
stgSLFlag = paraSLMode != "Off"

if stgTGTFlag
    totalRows += 1
if stgSLFlag
    totalRows += 1

var dashtable = table.new(position.bottom_left, totalCols, totalRows,
  frame_color=color.new(#000000,0),
  frame_width=1,
  border_color=color.new(#000000,0),
  border_width=1)

cell_up = #237a27 //input.color(#237a27,'Buy Cell Color'  ,group='Style Settings')
cell_dn = color.red //input.color(color.red,'Sell Cell Color'  ,group='Style Settings')
cell_Neut = color.gray //input.color(color.gray,'Neut Cell Color'  ,group='Style Settings')
txt_col = color.white

table_text_size = size.small

openProfit = strategy.openprofit
lastProfit = strategy.closedtrades.profit(strategy.closedtrades-1)
openProfitColor = openProfit >= 0 ? cell_up : cell_dn
lastProfitColor = lastProfit >= 0 ? cell_up : cell_dn

rowCtr = 0
colCtr = 0

if (barstate.islast and paraShowDashboard)
    table.cell(dashtable, 0, rowCtr, "Mirrorpip Dashboard", text_color=txt_col, text_size=table_text_size, bgcolor=color.new(color.green,80), tooltip="")  
    table.cell(dashtable, 1, rowCtr, '', text_color=txt_col, text_size=table_text_size, bgcolor=color.new(color.green,80), tooltip="")
    table.merge_cells(dashtable, 0, 0, 1, 0)

    if strategy.position_size > 0
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "Buy",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_avg_price, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "Qty.",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_size, "#"),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
        if (stgTGTFlag)
            rowCtr += 1
            table.cell(dashtable, 0, rowCtr, "TGT",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
            if (BuyTGT1)
                table.cell(dashtable, 1, rowCtr, str.tostring(BuyTGT1, format.mintick) + "/"+ str.tostring(BuyTGT, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
            else    
                table.cell(dashtable, 1, rowCtr, str.tostring(BuyTGT, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
        if (stgSLFlag)
            rowCtr += 1
            table.cell(dashtable, 0, rowCtr, "SL",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
            table.cell(dashtable, 1, rowCtr, str.tostring(BuySL, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "P&L",text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(openProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip="")

    if strategy.position_size < 0
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "Short",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_avg_price, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "Qty.",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_size, "#"),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
        if (stgTGTFlag)
            rowCtr += 1
            table.cell(dashtable, 0, rowCtr, "TGT",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
            if (ShortTGT1)
                table.cell(dashtable, 1, rowCtr, str.tostring(ShortTGT1, format.mintick) + "/"+ str.tostring(ShortTGT, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
            else    
                table.cell(dashtable, 1, rowCtr, str.tostring(ShortTGT, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="")
        if (stgSLFlag)
            rowCtr += 1
            table.cell(dashtable, 0, rowCtr, "SL",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
            table.cell(dashtable, 1, rowCtr, str.tostring(ShortSL, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="")
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "P&L",text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(openProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip="")

    if strategy.position_size == 0
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "No Trade", text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
        table.cell(dashtable, 1, rowCtr, "Relax", text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
        table.cell(dashtable, 1, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
        if (stgTGTFlag)
            rowCtr += 1
            table.cell(dashtable, 0, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
            table.cell(dashtable, 1, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
        if (stgSLFlag)
            rowCtr += 1
            table.cell(dashtable, 0, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
            table.cell(dashtable, 1, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")
        table.cell(dashtable, 1, rowCtr, "",text_color=txt_col,text_size=table_text_size,bgcolor=cell_Neut,tooltip="")

    if strategy.position_size <= 0 and strategy.position_size[1] > 0
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "Exit Buy",text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(lastProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="")
    else if strategy.position_size >= 0 and strategy.position_size[1] < 0
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "Exit Short",text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(lastProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="")
    else    
        rowCtr += 1
        table.cell(dashtable, 0, rowCtr, "Last P&L",text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="")
        table.cell(dashtable, 1, rowCtr, str.tostring(lastProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="")
////======================================================

Step 2: Add the Strategy to Pine editor

Click on pine editor > click on create new strategy and empty the canvas and paste the above mentioned code and save it ⭐ Add to Favorite Indicators This ensures quick access from your TradingView account.

Step 3: Apply the Strategy to a Chart

Open any supported crypto trading pair. Examples:
  • BTCUSDT
  • ETHUSDT
  • SOLUSDT
  • XRPUSDT
Apply the EMA Bands Strategy to the chart. The EMA High and EMA Low bands will now be visible.

Step 4: Configure Your MIRRORPIP Code

Open: Settings → Inputs Locate the MIRRORPIP Integration Section. Paste your unique MIRRORPIP automation code into the designated field. This code links TradingView signals with your MIRRORPIP account.

Step 5: Configure TradingView Alerts

Create a new TradingView Alert. Copy and paste:

Webhook URL

Use the webhook URL provided by MIRRORPIP.

Alert Message

Use the exact strategy message provided by MIRRORPIP. This allows TradingView to send trade signals directly to the MIRRORPIP execution engine. Important: Incorrect alert messages may prevent trades from executing.

Step 6: Add the Trading Pair to MIRRORPIP Watchlist

Open your MIRRORPIP dashboard. Navigate to: Watchlist → Add Symbol Add the exact TradingView symbol being traded. Example:
  • BTCUSDT
  • ETHUSDT
  • SOLUSDT
This allows MIRRORPIP to correctly map TradingView alerts to your exchange account.

Step 7: Enable Automation

Once all settings are configured: ✅ Strategy Applied ✅ MIRRORPIP Code Added ✅ Alert Created ✅ Webhook Configured ✅ Symbol Added to Watchlist Your trading automation is now live. MIRRORPIP will automatically execute trades whenever the EMA Bands Strategy generates signals.

Example Trade

Long Example

  1. BTCUSDT closes above EMA High Band.
  2. Strategy enters Long.
  3. Stop Loss placed at EMA Low Band.
  4. Market continues higher.
  5. Take Profit target gets hit.
  6. Position closes automatically.

Short Example

  1. ETHUSDT closes below EMA Low Band.
  2. Strategy enters Short.
  3. Stop Loss placed at EMA High Band.
  4. Market continues lower.
  5. Trailing Stop follows price.
  6. Trade closes automatically when TSL is triggered.

Who Should Use This Strategy?

The EMA Bands Strategy is ideal for:

Trend Traders

Capture directional market moves with minimal complexity.

Swing Traders

Ride medium-term trends across major cryptocurrencies.

Automated Traders

Fully automate TradingView strategies using MIRRORPIP.

Quantitative Traders

Use systematic rule-based entries and exits without emotional decision making.

Important Notes

⚠️ A paid TradingView subscription is required to use webhook-based automation. ⚠️ Always test the strategy on paper trading before deploying significant capital. ⚠️ Different cryptocurrencies may require different EMA lengths and TP/SL settings. ⚠️ Past performance does not guarantee future results. ⚠️ Cryptocurrency markets are highly volatile and involve risk.

Conclusion

The EMA Bands Strategy combines trend-following logic, breakout confirmation, automatic reversal entries, and advanced risk management into a single automation-ready TradingView strategy. With built-in MIRRORPIP integration, traders can deploy the strategy across multiple crypto exchanges without writing code, creating alerts manually, or monitoring charts 24/7. Whether you’re a discretionary trader looking to automate your workflow or a systematic trader searching for a simple yet effective trend-following model, the EMA Bands Strategy offers a powerful framework for crypto trading automation through MIRRORPIP.