This pine script strategy is actually similar to previous post on SMAC strategy, the only difference is that the order size is not cumulative/compounding from previous profitable (or loss) trade.
The advantage of using this script is that u do not need to worry about changing the startning date of trade, every trade is fixed at 100USDT (or wahatever amount you prefer) regardless whether the prvious trade made profit/loss.
The initial capital is purposely preset at 1000 USDT, to provide capital buffer in case the first trade made a loss. If the the amount of initial cap is put at 100USDT same as the order size of 100USDT, and the first trade made loss, the bot wont be able to place second order at 100USDT becasue the capital then has bcome lesser than 100USDT after a loss trade.
Beginner friendly. Because the strategy does not need you to change the date (to set starting date of bot trading), this is ideal for beginner user of pine script strategy.

The pine script as below”
//@version=6
strategy("[kriptos.my]SMAC strategy", overlay=true,
initial_capital=1000,
default_qty_type=strategy.cash,
default_qty_value=100,
pyramiding=1,
commission_type=strategy.commission.percent,
commission_value=0.22,
margin_long=100) // margin_long=100 enforces spot (no leverage)
// default setting is for ... ZILUSDT Kucoin TF 1hour
//code270
// 1 & 2. SMA Inputs
fastLen = input.int(41, title="Fast SMA Length", group="Moving Averages")
slowLen = input.int(155, title="Slow SMA Length", group="Moving Averages")
// 3. Cross & Trend Type
crossType = input.string("Crossover", title="Cross Type", options=["Crossover", "Crossunder"], group="Moving Averages")
slowSmaTrend = input.string("Uptrend", title="Slow SMA Trend Filter", options=["Uptrend", "Downtrend"], group="Moving Averages")
// 4 & 5. Risk Management & Trailing Inputs
tpPerc = input.float(9.4, title="Take Profit (%)", step=0.1, group="Risk Management")
rrRatio = input.float(1.3, title="Reward/Risk Ratio", step=0.1, group="Risk Management")
useTrailing = input.bool(false, title="Enable Trailing Profit", group="Risk Management")
trailPerc = input.float(0.4, title="Trailing Profit Offset (%)", step=0.1, group="Risk Management")
// 6. Time Filter (Date Range)
startTime = input.time(timestamp("2025-10-01T00:00:00"), title="Start Time", group="Time & Date Filter")
endTime = input.time(timestamp("2028-12-31T23:59:59"), title="End Time", group="Time & Date Filter")
// 7. Day Selection Filter
grpDays = "Trading Days"
tradeMon = input.bool(true, title="Monday", group=grpDays)
tradeTue = input.bool(true, title="Tuesday", group=grpDays)
tradeWed = input.bool(false, title="Wednesday", group=grpDays)
tradeThu = input.bool(true, title="Thursday", group=grpDays)
tradeFri = input.bool(false, title="Friday", group=grpDays)
tradeSat = input.bool(false, title="Saturday", group=grpDays)
tradeSun = input.bool(true, title="Sunday", group=grpDays)
// =========================================================================
// CALCULATIONS
// =========================================================================
// SMA calculations
fastSMA = ta.sma(close, fastLen)
slowSMA = ta.sma(close, slowLen)
// Determine the Slow SMA trend direction
slowSmaUp = slowSMA > slowSMA[1]
slowSmaDown = slowSMA < slowSMA[1]
// Evaluate the chosen trend condition
validTrend = slowSmaTrend == "Uptrend" ? slowSmaUp : slowSmaDown
// Cross condition based on user selection
isCross = crossType == "Crossover" ? ta.crossover(fastSMA, slowSMA) : ta.crossunder(fastSMA, slowSMA)
// Fixed Time Filter
inTimeWindow = time >= startTime and time <= endTime
// Day filters
dayAllowed = (dayofweek == dayofweek.monday and tradeMon) or
(dayofweek == dayofweek.tuesday and tradeTue) or
(dayofweek == dayofweek.wednesday and tradeWed) or
(dayofweek == dayofweek.thursday and tradeThu) or
(dayofweek == dayofweek.friday and tradeFri) or
(dayofweek == dayofweek.saturday and tradeSat) or
(dayofweek == dayofweek.sunday and tradeSun)
// Deriving the Stop Loss percentage using TP and RR Ratio
// SL% = TP% / RR
slPerc = tpPerc / rrRatio
// =========================================================================
// STRATEGY EXECUTION
// =========================================================================
// Spot Buy Condition (Long Only)
buyCondition = isCross and validTrend and inTimeWindow and dayAllowed
if (buyCondition and strategy.position_size == 0)
strategy.entry("Long", strategy.long)
// Take Profit, Stop Loss, and Trailing Stop execution
if (strategy.position_size > 0)
entryPrice = strategy.position_avg_price
// Calculate exact target prices for SL and TP
longTP = entryPrice * (1 + (tpPerc / 100))
longSL = entryPrice * (1 - (slPerc / 100))
if useTrailing
// Convert the 0.4% Trailing Offset into exact ticks for the asset
trailTicks = (entryPrice * (trailPerc / 100)) / syminfo.mintick
// Execute exit with the trailing profit parameters applied
strategy.exit("Exit Long", from_entry="Long", limit=longTP, stop=longSL, trail_points=0, trail_offset=trailTicks)
else
// Standard exit without trailing logic
strategy.exit("Exit Long", from_entry="Long", limit=longTP, stop=longSL)
// =========================================================================
// PLOTTING
// =========================================================================
plot(fastSMA, color=color.new(color.blue, 0), title="Fast SMA")
plot(slowSMA, color=slowSmaUp ? color.new(color.green, 0) : color.new(color.red, 0), title="Slow SMA")
*code270

No Comments