This is a tool to better visualize each order level for every safety order. It is a pine script that you can add on onto TradingView chart.
The components are:
- Drop down percentage (%)
- Price Deviation Multiplier (1x – 2x)
- Take Profit Percentage (%)
Recommended Settings:
- Pair: any
- Time frame: 8H, 12H, 1D

Code as below:
//@version=5
indicator(“DCAMartingaleVisualizer[kriptos.my]”, overlay=true)
// Recommended TF are 8h,12h,1D
// ori code 227
// === Inputs ===
priceDropPercent = input.float(4.2, title=”% Price Drop [Green line]”, step=0.1, minval=0.4) / 100
numSafetyOrders = input.int(7, title=”Safety Orders [excluding initial buy]”, minval=1, maxval=8)
multiplier = input.float(2, title=”Order Size Multiplier”, step=0.1, minval=1.0)
takeProfitPercent = input.float(2.1, title=”% Take Profit [Red line]”, step=0.1, minval=0.4) / 100
// === Entry Price from latest bar ===
entryPrice = close
// === Reset accumulators ===
totalCost = 0.0
totalQty = 0.0
orderQty = 1.0
// === Initialize line arrays only once ===
var line[] safetyLines = array.new_line()
var line tpLine = na
var line entryLine = na
// === Draw safety order lines ===
for i = 0 to numSafetyOrders – 1
priceLevel = entryPrice * math.pow(1 – priceDropPercent, i + 1)
totalCost += priceLevel * orderQty
totalQty += orderQty
if bar_index == ta.highest(bar_index, 1)
if array.size(safetyLines) < numSafetyOrders
array.push(safetyLines, line.new(0, priceLevel, bar_index, priceLevel, color=color.green, style=line.style_dotted))
else
line safetyLine = array.get(safetyLines, i)
line.set_xy1(safetyLine, 0, priceLevel)
line.set_xy2(safetyLine, bar_index, priceLevel)
orderQty *= multiplier
// === Calculate average entry and TP level ===
avgEntry = totalCost / totalQty
tpLevel = avgEntry * (1 + takeProfitPercent)
// === Draw Take Profit Line ===
if bar_index == ta.highest(bar_index, 1)
if na(tpLine)
tpLine := line.new(0, tpLevel, bar_index, tpLevel, color=color.red, style=line.style_solid, width=2)
else
line.set_xy1(tpLine, 0, tpLevel)
line.set_xy2(tpLine, bar_index, tpLevel)
// === Draw Entry Line (optional) ===
if bar_index == ta.highest(bar_index, 1)
if na(entryLine)
entryLine := line.new(0, entryPrice, bar_index, entryPrice, color=color.blue, style=line.style_dashed, width=1)
else
line.set_xy1(entryLine, 0, entryPrice)
line.set_xy2(entryLine, bar_index, entryPrice)
*code227

No Comments