Skip to main content

Mirrorpip Custom Levels Strategy: Automating Breakout Trades Around Key Price Levels

Introduction

The Mirrorpip Custom Levels Strategy is designed for traders who prefer making trading decisions based on their own market analysis rather than relying on technical indicators. Instead of using signals generated by indicators such as RSI, MACD, or Supertrend, this strategy allows traders to define specific price levels that they believe are important. Once these levels are configured, the strategy automatically enters, manages, and exits trades whenever the market interacts with those levels. This approach combines the flexibility of discretionary trading with the discipline and speed of automation. Whether you trade crypto, stocks, forex, indices, or commodities, the Custom Levels Strategy allows you to automate your own market view while eliminating emotional decision-making.

How the Strategy Works

The strategy revolves around two manually defined price levels:

Buy Level

A price level above which bullish momentum is expected.

Short Level

A price level below which bearish momentum is expected. The strategy continuously monitors these levels and automatically executes trades whenever breakout conditions are satisfied. The strategy will keep taking fresh trades if we continously hit SL and stop only after target is met once. This is useful when your Risk reward are abnormally high, as a trader you don’t mind loosing few times and finally winning big Here is the source code of the strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mirrorpip
 
//@version=6
strategy("MirrorPip Custom Levels Strategy v1.3", shorttitle="MirrorPip  Custom Levels", overlay=true, default_qty_type=strategy.fixed, process_orders_on_close=false, calc_on_every_tick=true, calc_on_order_fills=false, margin_long = 10, margin_short = 10)
 
////======================================================
paraTradeMode = input.string(defval="all", title="Trade Type : ", options=["all", "long", "short"], group = "Trade Settings")
paraSystemMode = input.session(defval="Positional", 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')
 
paraBuyDT = input.time(timestamp("15 Apr 2026 09:15 +0530"), "Buy Start From", group = "Trade Settings")
paraBuyLevel = input.float(0, "Buy Level", minval = 0, inline = "R0", group = "Trade Settings", tooltip = "Set 0 to Start Long from Specified DateTime") 
paraShortDT = input.time(timestamp("15 Apr 2026 10:15 +0530"), "Short Start From", group = "Trade Settings")
paraShortLevel = input.float(0, "Short Level", minval = 0, inline = "R1", group = "Trade Settings", tooltip = "Set 0 to Start Short from Specified DateTime") 
 
paraEntryMode = input.string(defval="Close", title="Entry Mode", options=["HighLow", "Close"], group = "Trade Settings", inline = "R1")
 
paraISTTimeZoneMode = input.bool(true, "IST Timezone?", group = "Trade Settings")
 
paraTGTMode = input.string(defval="%", title="Target : ", options=["Off", "%", "Pts"], inline = "TGT", group = "Target Settings")
paraTGT1 = input.float(1, "T1 : ", minval = 0.1, 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(1, "Value : ", minval = 0.1, inline = "TSL", group = "TSL Settings")
paraTSLonT1 = input.bool(false, "Trail after T1?", 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)
paraSTAG = input.string(title='Strategy Tag', defval='PRO1', group=grpAlgo)
paraPriceType = input.string(title="Price Type", defval='market',options=['market','limit'], group=grpAlgo)
paraQtyType = input.string(title="Quantity Type", defval='Fixed',options=['Fixed','$'], group=grpAlgo)
paraQtyEn = input.float(title='Entry Qty.', defval=1, minval=0, group=grpAlgo, tooltip='Qty in Lots for Futures', inline = "Qty")
paraQtyEx = input.float(title='Exit Qty. ', defval=1, minval=0, group=grpAlgo, tooltip='Qty in Lots for Futures', inline = "Qty")
paraOptMode = input.bool(true, "Options Mode?", group=grpAlgo, inline = "AlgoOpt")
paraOptUnderlying = input.string('BTC', 'Underlying Scrip', group=grpAlgo, inline = "AlgoOpt")
paraOptExpiry = input.string("200925", "Expiry", group=grpAlgo, inline = "AlgoOpt")
paraOptSteps = input.int(1000, 'Strike: Steps (ATM)', group=grpAlgo, tooltip='Options Strikes Steps for ATM', inline = "AlgoOpt1")
paraOptMulti = input.int(0, 'Offset', group=grpAlgo, tooltip='Options Strikes Offset: 0: ATM / <0: ITM / >0: OTM', inline = "AlgoOpt1")
paraOptBuySellMode = input.string("Buyer", "Options Trade Mode", options=['Buyer','Seller'], group=grpAlgo)
// paraStag = input.string(title='Strategy Tag', defval='PRO1', group='AlgoFox Setup:')
// paraCode = input.string(title='Code', defval='XXXX', group='AlgoFox Setup:')
// paraProductType = input.string(title="Product Type", defval='NRML',options=['MIS','NRML','CNC'], group='AlgoFox Setup:')
// paraInstr = input.string(title='Instrument Type', defval='FUTIDX',options=['EQ','FUTIDX','OPTIDX','FUTSTK','OPTSTK','FUTCOM','FUTCUR'], group='AlgoFox Setup:')
// paraOptUnderlying = input.string(title='Options Underlying Scrip', defval='NIFTY', group='AlgoFox Setup:')
// paraOptExpiry = input.string(title='Options Expiry (Bridge)', defval='13JUN2024', group='AlgoFox Setup:')
// paraOptStrike = input.string(title='Options Strike (Bridge)', defval='22800', group='AlgoFox Setup:', inline = "OptStrike")
// paraOptStrikeMode = input.bool(title='Static ?', defval=true, group='AlgoFox Setup:', inline = "OptStrike")
// paraOptCEPE = input.string(title='Options CE/PE', defval='CE',options=['CE','PE'], group='AlgoFox Setup:')
// paraQtyType = input.string(title="Quantity Type", defval='Fixed',options=['Fixed','Exposure'], group='AlgoFox Setup:') 
// paraQty = input.int(title='Quantity ', defval=1, minval=1, group='AlgoFox Setup:', tooltip='Qty in Lots for Futures')
paraT1Qty = 0 //input.float(title='Target-1 Exit Qty (%)', defval=0, minval=0, maxval = 100, group='AlgoFox Setup:', tooltip='Qty in Percentage')
paraMaxProfit = 0 //input.int(0, "Max Profit Per Trade", 0, group='AlgoFox Setup:', tooltip='Exit on Max. Profit in Rs.')
paraMaxLoss = 0 //input.int(0, "Max Loss Per Trade", 0, group='AlgoFox Setup:', tooltip='Exit on Max. Loss in Rs.')
////======================================================
 
////======================================================
strategy.risk.allow_entry_in(paraTradeMode)
AlgoBuyCond = paraTradeMode != "short"
AlgoShortCond = paraTradeMode != "long"
 
FC = session.isfirstbar
LC = session.islastbar
 
IsCB = paraEntryMode == "Close"
st = paraSystemMode=="Positional" ? true : not na(time(timeframe.period, s))
et = paraSystemMode=="Intraday" and not na(time(timeframe.period, e))
if (paraISTTimeZoneMode)
    st := paraSystemMode=="Positional" ? true : not na(time(timeframe.period, s, "UTC+5:30"))
    et := paraSystemMode=="Positional" ? false : not na(time(timeframe.period, e, "UTC+5:30"))
 
BuyStartDTCond = time == paraBuyDT
ShortStartDTCond = time == paraShortDT
 
BuyDTCond = time >= paraBuyDT
ShortDTCond = time >= paraShortDT
 
eSignal = 0
eBuyPos = 0
eShortPos = 0
eBuy = st and paraBuyLevel > 0 and BuyStartDTCond
eShort = st and paraShortLevel > 0 and ShortStartDTCond
eSell = et
eCover = et
eSignal := eBuy ? 1 : eShort ? -1 : eSell and eSignal[1] > 0 ? 0 : eCover and eSignal[1] < 0 ? 0 : eSignal[1]
eBuyPos := eBuy ? 1 : eSell and eBuyPos[1] > 0 ? 0 : eBuyPos[1]
eShortPos := eShort ? -1 : eCover and eShortPos[1] < 0 ? 0 : eShortPos[1]
 
eBuyHigh = ta.valuewhen(eBuy, paraBuyLevel, 0)
eShortLow = ta.valuewhen(eShort, paraShortLevel, 0)
 
MainSignal = 0
var bool BuySignal = false
var bool ShortSignal = false
var bool SellSignal = false
var bool CoverSignal = false
 
if IsCB
    BuySignal := st and BuyDTCond and ((eBuyPos > 0 and close > eBuyHigh and close[1] < eBuyHigh and eBuyHigh > 0) or (BuyStartDTCond and paraBuyLevel==0)) and barstate.isconfirmed and (nz(MainSignal[1]) <= 0)
    ShortSignal := st and ShortDTCond and ((eShortPos < 0 and close < eShortLow and eShortLow > 0) or (ShortStartDTCond and paraShortLevel==0)) and barstate.isconfirmed and (nz(MainSignal[1]) >= 0)
    SellSignal := (((ShortSignal) and barstate.isconfirmed) or et) and (nz(MainSignal[1]) == 1)
    CoverSignal := (((BuySignal) and barstate.isconfirmed) or et) and (nz(MainSignal[1]) == -1)
    MainSignal := BuySignal ? 1 : ShortSignal ? -1 : SellSignal and MainSignal[1] > 0 ? 0 : CoverSignal and MainSignal[1] < 0 ? 0 : MainSignal[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]
else
    BuySignal := st[1] and eBuyPos[1] > 0 and high > eBuyHigh[1] and (nz(MainSignal[1]) <= 0)
    ShortSignal := st[1] and eShortPos[1] < 0 and low < eShortLow[1] and (nz(MainSignal[1]) >= 0)
    SellSignal := (ShortSignal or et) and (nz(MainSignal[1]) == 1)
    CoverSignal := (BuySignal or et) and (nz(MainSignal[1]) == -1)
    MainSignal := BuySignal ? 1 : ShortSignal ? -1 : SellSignal ? 0 : CoverSignal ? 0 : MainSignal[1]
////======================================================
 
////======================================================
symbol = syminfo.ticker
 
eBuyPrice = ta.valuewhen(BuySignal, close, 0)
eShortPrice = ta.valuewhen(ShortSignal, close, 0)
 
BATM = math.round(eBuyPrice/paraOptSteps)*paraOptSteps
SATM = math.round(eShortPrice/paraOptSteps)*paraOptSteps
LEStrike = BATM + (paraOptMulti * paraOptSteps)
SEStrike = SATM - (paraOptMulti * paraOptSteps)
 
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
var float SellTradeQty = na
var float CoverTradeQty = na
var float BuyRisk = na
var float ShortRisk = na
var float eBuySL = na
var float eShortSL = na
var float eBuyTGT = na
var float eShortTGT = na
var string QtySuffix = ""
 
BuyTradeQty := paraQtyEn
SellTradeQty := paraQtyEx
ShortTradeQty := paraQtyEn
CoverTradeQty := paraQtyEx
 
if (paraQtyType=="Exposure")
    BuyTradeQty := paraQtyEn / eBuyPrice
    BuyTradeQty := math.round(BuyTradeQty / syminfo.pointvalue) 
    ShortTradeQty := paraQtyEn / eShortPrice
    ShortTradeQty := math.round(ShortTradeQty / syminfo.pointvalue) 
 
    if (BuyTradeQty < 0)
        BuyTradeQty := 1
    if (ShortTradeQty < 0)
        ShortTradeQty := 1
 
    SellTradeQty := BuyTradeQty
    CoverTradeQty := ShortTradeQty
 
if (paraQtyType=="$")
    QtySuffix := "$"
 
buyData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LESym + '", "price_type": "' + paraPriceType + '", "order_type": "BUY", "instrument_type": "NA", "quantity": "' + str.tostring(BuyTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
sellData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LXSym + '", "price_type": "' + paraPriceType + '", "order_type": "SELL", "instrument_type": "NA", "quantity": "' + str.tostring(SellTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
shortData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SESym + '", "price_type": "' + paraPriceType + '", "order_type": "SHORT", "instrument_type": "NA", "quantity": "' + str.tostring(ShortTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
coverData = '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SXSym + '", "price_type": "' + paraPriceType + '", "order_type": "COVER", "instrument_type": "NA", "quantity": "' + str.tostring(CoverTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
 
if (paraOptMode)
    if (paraOptBuySellMode == "Seller")
        LEStrike := BATM - (paraOptMulti * paraOptSteps)
        SEStrike := SATM + (paraOptMulti * paraOptSteps)
 
        LESym := "P-" + paraOptUnderlying + "-" + str.tostring(LEStrike) + "-" + paraOptExpiry
        LXSym := "P-" + paraOptUnderlying + "-" + str.tostring(LEStrike[1]) + "-" + paraOptExpiry
        SESym := "C-" + paraOptUnderlying + "-" + str.tostring(SEStrike) + "-" + paraOptExpiry
        SXSym := "C-" + paraOptUnderlying + "-" + str.tostring(SEStrike[1]) + "-" + paraOptExpiry
 
        buyData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LESym + '", "price_type": "' + paraPriceType + '", "order_type": "SHORT", "instrument_type": "NA", "quantity": "' + str.tostring(BuyTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
        sellData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LXSym + '", "price_type": "' + paraPriceType + '", "order_type": "COVER", "instrument_type": "NA", "quantity": "' + str.tostring(SellTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
        shortData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SESym + '", "price_type": "' + paraPriceType + '", "order_type": "SHORT", "instrument_type": "NA", "quantity": "' + str.tostring(ShortTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
        coverData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SXSym + '", "price_type": "' + paraPriceType + '", "order_type": "COVER", "instrument_type": "NA", "quantity": "' + str.tostring(CoverTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
    else
        LESym := "C-" + paraOptUnderlying + "-" + str.tostring(LEStrike) + "-" + paraOptExpiry
        LXSym := "C-" + paraOptUnderlying + "-" + str.tostring(LEStrike[1]) + "-" + paraOptExpiry
        SESym := "P-" + paraOptUnderlying + "-" + str.tostring(SEStrike) + "-" + paraOptExpiry
        SXSym := "P-" + paraOptUnderlying + "-" + str.tostring(SEStrike[1]) + "-" + paraOptExpiry
 
        buyData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LESym + '", "price_type": "' + paraPriceType + '", "order_type": "BUY", "instrument_type": "NA", "quantity": "' + str.tostring(BuyTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
        sellData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + LXSym + '", "price_type": "' + paraPriceType + '", "order_type": "SELL", "instrument_type": "NA", "quantity": "' + str.tostring(SellTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
        shortData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SESym + '", "price_type": "' + paraPriceType + '", "order_type": "BUY", "instrument_type": "NA", "quantity": "' + str.tostring(ShortTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
        coverData := '{ "exchange": "' + paraExchange + '", "price": "' + str.tostring(close) + '", "chart_symbol": "' + SXSym + '", "price_type": "' + paraPriceType + '", "order_type": "SELL", "instrument_type": "NA", "quantity": "' + str.tostring(CoverTradeQty) + QtySuffix + '", "tp": "0", "sl": "0", "code": "'+paraCode+'", "stag": "'+paraSTAG+'"}'
////======================================================
 
////======================================================
var bool B_ReEntryOnSL_F = false
var bool S_ReEntryOnSL_F = false
 
lastClosedTrade = strategy.closedtrades - 1
lastPNL = strategy.closedtrades.profit(lastClosedTrade)
if strategy.position_size <= 0 and strategy.position_size[1] > 0 and lastPNL < 0
    B_ReEntryOnSL_F := true
if strategy.position_size >= 0 and strategy.position_size[1] < 0 and lastPNL < 0
    S_ReEntryOnSL_F := true
 
if (IsCB)
    if BuySignal and strategy.position_size < 0 and AlgoBuyCond
        strategy.entry('BUY', strategy.long, comment='Buy', qty=BuyTradeQty, alert_message="["+coverData+","+buyData+"]")
    else if BuySignal and strategy.position_size == 0 and AlgoBuyCond
        strategy.entry('BUY', strategy.long, comment='Buy', qty=BuyTradeQty, alert_message="["+buyData+"]")
    else if AlgoBuyCond and B_ReEntryOnSL_F and close > eBuyHigh and close[1] < eBuyHigh and st and strategy.position_size == 0 
        strategy.entry('BUY', strategy.long, comment='Buy', qty=BuyTradeQty, alert_message="["+buyData+"]")
 
    if ShortSignal and strategy.position_size > 0 and AlgoShortCond
        strategy.entry('SHORT', strategy.short, comment='Short', qty=ShortTradeQty, alert_message="["+sellData+","+shortData+"]")
    else if ShortSignal and strategy.position_size == 0 and AlgoShortCond
        strategy.entry('SHORT', strategy.short, comment='Short', qty=ShortTradeQty, alert_message="["+shortData+"]")
    else if AlgoShortCond and S_ReEntryOnSL_F and close < eShortLow and close[1] > eShortLow and st and strategy.position_size == 0 
        strategy.entry('SHORT', strategy.short, comment='Short', qty=ShortTradeQty, alert_message="["+shortData+"]")
else
    if eBuy and st and strategy.position_size < 0 and AlgoBuyCond
        strategy.entry('BUY', strategy.long, qty=BuyTradeQty, comment="Buy", stop=eBuyHigh, limit=eBuyHigh, alert_message="["+coverData+","+buyData+"]")
    if eBuy and st and strategy.position_size == 0 and AlgoBuyCond
        strategy.entry('BUY', strategy.long, qty=BuyTradeQty, comment="Buy", stop=eBuyHigh, limit=eBuyHigh, alert_message="["+buyData+"]")
    if (eBuyPos <= 0 or et or not st) 
        strategy.cancel("BUY")
    if AlgoBuyCond and B_ReEntryOnSL_F and close < eBuyHigh and st and strategy.position_size == 0 
        strategy.entry('BUY', strategy.long, qty=BuyTradeQty, comment="Buy", stop=eBuyHigh, limit=eBuyHigh, alert_message="["+buyData+"]")
 
    if eShort and st and strategy.position_size > 0 and AlgoShortCond
        strategy.entry('SHORT', strategy.short, qty=ShortTradeQty, comment="Short", stop=eShortLow, limit=eShortLow, alert_message="["+sellData+","+shortData+"]")
    if eShort and st and strategy.position_size == 0 and AlgoShortCond
        strategy.entry('SHORT', strategy.short, qty=ShortTradeQty, comment="Short", stop=eShortLow, limit=eShortLow, alert_message="["+shortData+"]")
    if (eShortPos >= 0 or et or not st)    
        strategy.cancel("SHORT")
    if AlgoShortCond and S_ReEntryOnSL_F and close > eShortLow and st and strategy.position_size == 0 
        strategy.entry('SHORT', strategy.short, qty=ShortTradeQty, comment="Short", stop=eShortLow, limit=eShortLow, 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
var bool BTSLFlag = false
var bool STSLFlag = false
 
ut = (paraTGTMode != "Off")
us = (paraSLMode != "Off")
 
if (strategy.position_size > 0 and strategy.position_size[1] <= 0)
 
    BuyPrice := strategy.position_avg_price
    BTSLFlag := false
    B_ReEntryOnSL_F := false
 
    if (paraSLMode=="%")
        BuySL := BuyPrice * (1-(paraSL/100))
    else if (paraSLMode=="Pts")
        BuySL := BuyPrice - (paraSL)
 
    BuyRisk := BuyPrice - BuySL
 
    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
    STSLFlag := false
    S_ReEntryOnSL_F := false
 
    if (paraSLMode=="%")
        ShortSL := ShortPrice * (1+(paraSL/100))
    else if (paraSLMode=="Pts")
        ShortSL := ShortPrice + (paraSL)
 
    ShortRisk := ShortSL - ShortPrice
 
    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 ((paraTSLonT1 and high[1] >= BuyTGT1) or not paraTSLonT1)
            BTSLFlag := true
        
        if (paraTSLMode=="%")
            BuyTSL := high[1] * (1-(paraTSL/100))
        else if (paraTSLMode=="Pts")
            BuyTSL := high[1] - paraTSL
 
        if (BuySL < BuyTSL and BTSLFlag)
            BuySL := BuyTSL
 
    if (strategy.position_size < 0 and strategy.position_size[1] < 0)
        if ((paraTSLonT1 and low[1] <= ShortTGT1) or not paraTSLonT1)
            STSLFlag := true
 
        if (paraTSLMode=="%")
            ShortTSL := low[1] * (1+(paraTSL/100))
        else if (paraTSLMode=="Pts")
            ShortTSL := low[1] + paraTSL
 
        if (ShortSL > ShortTSL and STSLFlag)
            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": "' + str.tostring(syminfo.prefix) + '","Close": ' + str.tostring(close) + ',"Ticker": "' + LXSym + '","OrderType": "SELL","ProductType": "' + paraProductType  + '","InstrumentType": "' + paraInstr + '","Quantity": '+str.tostring(T1ExQty)+', "Strategy": "'+paraStag+'", "Code": "'+paraCode+'"}'
TPcoverData = "" //'{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": ' + str.tostring(close) + ',"Ticker": "' + SXSym + '","OrderType": "COVER","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr + '","Quantity": '+str.tostring(T1ExQty)+', "Strategy": "'+paraStag+'", "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 (IsCB and SellSignal and (not ShortSignal or not AlgoShortCond))) and strategy.position_size > 0 
    strategy.cancel('LongExit')
    strategy.cancel('LongT1Exit')
    strategy.close(id='BUY', comment="Sell", alert_message="["+sellData+"]")
 
if (et or (IsCB and CoverSignal and (not BuySignal or not AlgoBuyCond))) 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')
////======================================================
 
////======================================================
plot(st and paraBuyLevel > 0 ? paraBuyLevel : na, "BuyLevel", color.green, style = plot.style_linebr)
plot(st and paraShortLevel > 0 ? paraShortLevel : na, "ShortLevel", color.red, style = plot.style_linebr)
 
plot((strategy.position_size > 0)?BuyPrice:na, color=color.fuchsia, linewidth=1, style=plot.style_linebr)
plot((strategy.position_size > 0)?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)?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, "Dashboard", text_color=txt_col, text_size=table_text_size, bgcolor=color.new(color.blue,80), tooltip=""
    table.cell(dashtable, 1, rowCtr, '', text_color=txt_col, text_size=table_text_size, bgcolor=color.new(color.blue,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 (not na(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 (not na(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="")
////======================================================

Core Trading Logic

Long Trade Setup

A long trade is triggered when price breaks above the user-defined Buy Level.

Example

Buy Level = 100,000 Current Price = 99,500 No Trade
Price Moves To: 100,100 Result: ✅ Long Position Opened
The strategy assumes buyers have gained control and upward momentum may continue.

Short Trade Setup

A short trade is triggered when price breaks below the user-defined Short Level.

Example

Short Level = 95,000 Current Price = 95,500 No Trade
Price Falls To: 94,900 Result: ✅ Short Position Opened
The strategy assumes sellers have gained control and downside momentum may continue.

Complete Freedom To Define Levels

Unlike indicator-based systems, traders have complete control over the trigger levels. These levels can be derived from:
  • Previous Swing Highs
  • Previous Swing Lows
  • Support Zones
  • Resistance Zones
  • Opening Range Highs
  • Opening Range Lows
  • Weekly Highs and Lows
  • Monthly Highs and Lows
  • Supply and Demand Areas
  • Psychological Round Numbers
  • Manual Price Action Analysis
This flexibility allows traders to adapt the strategy to virtually any trading methodology.

Breakout Confirmation Modes

The strategy supports multiple breakout confirmation techniques.

Candle Close Confirmation

The breakout is considered valid only when a candle closes beyond the selected level.

Example

Buy Level: 100,000 Candle High: 100,200 Candle Close: 99,950 Result: ❌ No Trade Next Candle Closes: 100,100 Result: ✅ Long Trade Triggered This mode helps reduce false breakouts and noise.

Intrabar Breakout Confirmation

The strategy can also trigger immediately when price crosses the level during the candle.

Example

Buy Level: 100,000 Price Touches: 100,001 Result: ✅ Trade Triggered Immediately This mode provides earlier entries but may produce more false breakout signals.

Separate Long and Short Levels

Users can define completely independent levels for bullish and bearish trades.

Example

Buy Level: 105,000 Short Level: 98,000 This creates a neutral zone where no trades are taken until one of the boundaries is broken. This approach is particularly useful for breakout traders waiting for price to escape a consolidation range.

Continuous Re-Entry Logic

One of the most unique features of the Mirrorpip Custom Levels Strategy is its Continuous Re-Entry Engine. Unlike traditional breakout systems that stop trading after a loss, this strategy continues taking valid breakout entries as long as stop losses are being triggered. The cycle only ends when a profit target is successfully achieved. This allows traders to stay engaged with important breakout levels until the market finally delivers the expected move.

Example

Buy Level: 100,000 Target: 2% Stop Loss: 1%

Trade 1

Price Breaks Above 100,000 Long Entry Triggered Price Reverses ❌ Stop Loss Hit

Trade 2

Price Again Breaks Above 100,000 Long Entry Triggered Price Reverses Again ❌ Stop Loss Hit

Trade 3

Price Again Breaks Above 100,000 Long Entry Triggered Price Reverses Again ❌ Stop Loss Hit

Trade 4

Price Breaks Above 100,000 Long Entry Triggered Price Continues Higher ✅ Target Achieved At this point the cycle ends. The strategy stops taking new entries because a successful target has been reached.

Why Continuous Re-Entry Is Powerful

Many major trends begin with multiple failed breakout attempts. Traditional traders often stop participating after one or two losses and miss the eventual winning move. This strategy removes emotional hesitation by continuously executing valid setups until the market finally confirms the breakout. Benefits include:
  • Consistent execution
  • No emotional bias
  • Capturing eventual trend expansion
  • Eliminating fear after losing trades
  • Higher participation during breakout phases

Target Management

The strategy supports predefined profit targets. Users can configure targets using:

Percentage Targets

Example: Target = 2% Entry = 100,000 Exit = 102,000

Fixed Point Targets

Example: Target = 1000 Points Entry = 100,000 Exit = 101,000 The strategy automatically exits the trade once the target level is reached.

Dual Target System

For advanced trade management, users can define:

Target 1 (T1)

Partial profit booking level.

Target 2 (T2)

Final profit objective. This allows traders to secure profits early while still participating in larger market moves.

Stop Loss Protection

Every trade can be protected using predefined stop losses.

Percentage Stop Loss

Example: 1% Entry = 100,000 Stop Loss = 99,000

Fixed Point Stop Loss

Example: 500 Points Entry = 100,000 Stop Loss = 99,500 This ensures risk is always controlled before a trade is initiated.

Trailing Stop Loss

The strategy supports dynamic trailing stop management. Rather than exiting immediately after reaching a target, traders can allow profits to run while protecting gains.

Example

Entry: 100,000 Price Rises: 101,000 Trailing Stop Adjusts Higher Price Rises: 102,500 Trailing Stop Adjusts Again Price Reverses Position Automatically Exits This feature helps maximize gains during strong trending markets.

Time-Based Activation

Users can specify the exact date and time from which the strategy becomes active. This is useful for:
  • Economic Events
  • CPI Releases
  • FOMC Meetings
  • Earnings Announcements
  • Market Open Breakouts
  • Weekly Breakout Strategies
The strategy ignores all price action before the selected activation time.

Trading Direction Controls

The strategy can be configured to trade:

Long Only

Capture bullish breakouts only.

Short Only

Capture bearish breakdowns only.

Both Directions

Trade all valid opportunities. This flexibility allows adaptation to changing market conditions.

Practical Example

Suppose Bitcoin is trading inside a consolidation range. Support: 100,000 Resistance: 105,000 Configuration: Buy Level = 105,000 Short Level = 100,000 Target = 3% Stop Loss = 1% Scenario 1 BTC closes above 105,000 ✅ Long Trade Triggered Scenario 2 Trade hits stop loss ❌ Strategy Re-enters on next valid breakout Scenario 3 Second breakout succeeds ✅ Target Achieved Strategy Stops Trading Cycle Completed This process ensures the trader remains involved until the breakout either succeeds or market conditions change.

Markets Suitable For This Strategy

The Custom Levels Strategy works effectively across:

Cryptocurrency Markets

  • BTCUSDT
  • ETHUSDT
  • SOLUSDT
  • XRPUSDT

Equity Markets

  • Stocks
  • Index Futures
  • ETFs

Forex Markets

  • EURUSD
  • GBPUSD
  • USDJPY
  • AUDUSD

Commodities

  • Gold
  • Silver
  • Crude Oil
Any liquid market that respects support and resistance structures can benefit from this strategy.

Mirrorpip Automation Setup

The strategy can be fully automated through Mirrorpip. Workflow: TradingView Strategy → TradingView Alert → Mirrorpip Webhook → Exchange Account → Trade Execution Once configured, Mirrorpip handles execution automatically while providing real-time monitoring and analytics. Users can track:
  • Win Rate
  • Maximum Drawdown
  • Sharpe Ratio
  • Profit Factor
  • Average Trade Duration
  • Equity Curve
  • Live Open Positions
All from a single unified dashboard.

Risk Management Considerations

Although the strategy automates breakout execution, proper risk management remains essential. Before deploying:
  • Use appropriate stop losses
  • Select meaningful breakout levels
  • Avoid excessive leverage
  • Test on historical data
  • Understand market volatility
Continuous re-entry can increase the number of trades during choppy conditions, making proper position sizing especially important.

Conclusion

The Mirrorpip Custom Levels Strategy is a powerful hybrid between discretionary trading and automation. Traders retain complete control over market analysis by defining their own buy and short levels, while Mirrorpip handles execution with speed and precision. The strategy’s most distinctive feature is its Continuous Re-Entry Engine, which keeps participating in valid breakout opportunities even after multiple stop losses and only stops once a profit target is successfully achieved. Combined with custom breakout levels, configurable targets, stop losses, trailing exits, dual-direction trading, and complete Mirrorpip automation, the strategy provides a highly flexible framework for traders who want to automate their own market insights while maintaining full control over the underlying logic.