This is a n improved version of previous post. This indicator has added Price Drop Mutiplier. It will give you more flexibility of determining next safety order level.

The follwing is the code:
//@version=5
indicator("DCAMartingaleVisualizerV2[kriptos.my]", overlay=true)
// Recommended TF are 12h,1D
// === Inputs ===
priceDropPercent = input.float(4.2, title="% Price Drop [Green line]", step=0.1, minval=0.1) / 100
takeProfitPercent = input.float(2.1, title="% Take Profit [Red line]", step=0.1, minval=0.1) / 100
priceDropMultiplier = input.float(1.3, title="Price Drop Multiplier (Step Scale)", step=0.1, minval=1.0) // NEW INPUT
numSafetyOrders = input.int(5, title="Safety Orders [excluding initial buy]", minval=1, maxval=20)
multiplier = input.float(2, title="Order Size Multiplier", step=0.1, minval=1.0)
// === Entry Price from latest bar ===
entryPrice = close
// === Reset accumulators ===
totalCost = 0.0
totalQty = 0.0
orderQty = 1.0
// Variables for Step Scale calculation
currentStepSize = priceDropPercent
accumulatedDrop = 0.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
// Calculate new price level based on Step Scale
accumulatedDrop += currentStepSize
priceLevel = entryPrice * (1 - accumulatedDrop)
// Calculate Martingale Volume
totalCost += priceLevel * orderQty
totalQty += orderQty
// Drawing Logic
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)
// Prepare for next iteration
orderQty *= multiplier // Volume Multiplier
currentStepSize *= priceDropMultiplier // Price Drop Multiplier (Scale step for next line)
// === 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)
Just copy and paste it on TradingView Indicator. Recommended Tf are 12h and 1D.

No Comments