This script strategy is the same as previous script from this page here. You can choose whether:
- To use the time frame function with a click of a button
- Easily choose your date frame from the pop-up calender
- Exact clock time available as well
Here is the code:
//@version=5
strategy("SpotDCABot[kriptos.my]", overlay=false, initial_capital=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=99, commission_type=strategy.commission.percent, commission_value=0.3)
// This bot is for TradeAdapter meant for Kucoin/Gate.io which does not have minimum order of 5 USDT
// The TF is 5mins
// Default capital is 100 USDT, with InitialBuy of 1.58 USDT for total of 6 positions including IB.
// Other settings are adjustable to achieve best settings
// This is improved version of code245
// Inputs
percentageDrop = input.float(2.6, title="Percentage Drop(%)", step=0.1) / 100
takeProfitPct = input.float(2.7, title="Take Profit Percentage (%)", step=0.1) / 100
stopLossPct = input.float(14.5, title="SL(%)", step=0.1) / 100
maxPositions = input.int(6, title="Max Positions[including Initial Buy]", minval=1)
priceDevMultiplier = input.float(1.5, title="Price Deviation Multiplier", minval=1.0, step=0.1)
multiplier = input.float(2, title="Multiplier", minval=1, step=0.1)
initialCapital = input.float(1.58, title="Initial Buy USDT", step=0.1)
// --- Time Control ---
useTimeFilter = input.bool(true, "Use Start/Stop Time?")
startTime = input.time(timestamp("2025-01-01T00:00:00"), "Start Time")
stopTime = input.time(timestamp("2027-01-01T00:00:00"), "Stop Time")
// Variables
var float averageEntry = na
var float totalPositionSize = 0
var float totalCost = 0
var int positionCount = 0
var float lastPositionSize = na // Track the last added position size
// Price Levels
dropLevel = na(averageEntry) or positionCount == 0 ? na : averageEntry * (1 - percentageDrop * math.pow(priceDevMultiplier, positionCount - 1))
takeProfitLevel = na(averageEntry) ? na : averageEntry * (1 + takeProfitPct)
stopLossLevel = na(averageEntry) ? na : averageEntry * (1 - stopLossPct)
inTimeRange = not useTimeFilter or (time >= startTime and time <= stopTime)
// Entry Condition
if na(averageEntry) and positionCount == 0 and inTimeRange
initialQty = initialCapital / close // Directly calculate without rounding
strategy.entry("Initial Buy", strategy.long, qty=initialQty)
averageEntry := close
totalPositionSize := initialQty
totalCost := initialQty * close
positionCount := 1
lastPositionSize := initialQty // Initialize the last position size
if not na(averageEntry) and close <= dropLevel and positionCount < maxPositions
newPositionSize = lastPositionSize * multiplier // Calculate based on the last position size
strategy.entry("Add Position", strategy.long, qty=newPositionSize)
totalCost := totalCost + newPositionSize * close
totalPositionSize := totalPositionSize + newPositionSize
averageEntry := totalCost / totalPositionSize
positionCount := positionCount + 1
lastPositionSize := newPositionSize // Update the last position size
// Take Profit Condition
if not na(averageEntry) and close >= takeProfitLevel
strategy.close("Initial Buy")
strategy.close("Add Position")
averageEntry := na
totalPositionSize := 0
totalCost := 0
positionCount := 0
lastPositionSize := na // Reset the last position size
// Stop-Loss Condition (Fixed)
if not na(averageEntry) and close <= averageEntry * (1 - stopLossPct)
strategy.close_all()
averageEntry := na
totalPositionSize := 0
totalCost := 0
positionCount := 0
lastPositionSize := na // Reset the last position size
Recommended setting:
- Candle TF 5minutes
- DCA Order Multiplier 2x
- Price Deviation Multiplier 1.5x
Code:248

No Comments