This is a simple strategy actually. Simple Moving Average (SMA) cross with options of Crossover or Crossunder. In spot market, usually crossover is used for momentum strategy. While Crossunder is also useful when you aim to place order at support on upgoing trend overall.

The pine script code as follows:
//@version=6
strategy("SMAC[kriptos.my]", overlay=true,
initial_capital=100,
default_qty_type=strategy.percent_of_equity,
default_qty_value=99,
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
// 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(false, 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")
Setting suggestion:
Pair ZILUSDT
Exchanger: Kucoin
Time frame: 1hour
*code268

No Comments