OPEN-SOURCE SCRIPT

Crypto Intraday Futures Strategy

//version=5
strategy("Crypto Intraday Futures Strategy", overlay=true, margin_long=100, margin_short=100, commission_type=strategy.commission.percent, commission_value=0.05, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// Input parameters
fast_length = input.int(9, "Fast EMA Length")
slow_length = input.int(21, "Slow EMA Length")
rsi_length = input.int(14, "RSI Length")
overbought = input.int(70, "Overbought Level")
oversold = input.int(30, "Oversold Level")
stop_loss = input.float(1.0, "Stop Loss (%)") / 100
take_profit = input.float(2.0, "Take Profit (%)") / 100
session_close = input.session("2300-0000", "Session Close Time")

// Calculate indicators
fast_ema = ta.ema(close, fast_length)
slow_ema = ta.ema(close, slow_length)
rsi = ta.rsi(close, rsi_length)

// Time condition for session close
is_session = time(timeframe.period, session_close)
close_time = not is_session[1] and is_session

// Trading conditions
ema_bullish = ta.crossover(fast_ema, slow_ema)
ema_bearish = ta.crossunder(fast_ema, slow_ema)
rsi_bullish = rsi < oversold
rsi_bearish = rsi > overbought

// Entry conditions
long_condition = ema_bullish and rsi_bullish
short_condition = ema_bearish and rsi_bearish

// Exit conditions
stop_level = strategy.position_avg_price * (1 - stop_loss)
take_level = strategy.position_avg_price * (1 + take_profit)

// Execute strategy
if close_time
strategy.close_all()

if long_condition and not close_time
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", "Long", stop=stop_level, limit=take_level)

if short_condition and not close_time
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", "Short", stop=stop_level, limit=take_level)

// Plotting
plot(fast_ema, color=color.blue, title="Fast EMA")
plot(slow_ema, color=color.orange, title="Slow EMA")
hline(overbought, "Overbought", color=color.red)
hline(oversold, "Oversold", color=color.green)

Disclaimer