Certainly! Below is a basic but more robust Pine Script strategy for TradingView that provides buy and sell signals on a 15-minute timeframe, designed for Forex pairs. It uses a combination of Moving Averages and RSI for better accuracy, which is a common approach for such strategies.
You can customize parameters as needed.
//@version=5
strategy("Forex 15min MA + RSI Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Inputs
fastLength = input.int(9, title="Fast MA Length")
slowLength = input.int(21, title="Slow MA Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
// Apply only on 15-minute timeframe
is15min = timeframe.isintraday and timeframe.multiplier == 15
if not is15min
// Alert user to change timeframe
strategy.cancel_all()
label.new(bar_index, high, "Switch to 15-minute timeframe", style=label.style_label_down, color=color.red)
// Calculate Moving Averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// Calculate RSI
rsi = ta.rsi(close, rsiLength)
// Plot MAs
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.orange, title="Slow MA")
// Plot RSI on separate pane
rsiPlot = plot(rsi, title="RSI", color=color.purple)
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
// Entry Conditions
longCondition = ta.crossover(fastMA, slowMA) and rsi < rsiOversold
shortCondition = ta.crossunder(fastMA, slowMA) and rsi > rsiOverbought
// Exit Conditions: Opposite cross or RSI neutral zone
longExit = ta.crossunder(fastMA, slowMA) or rsi > 50
shortExit = ta.crossover(fastMA, slowMA) or rsi < 50
// Execute trades
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
if (longExit)
strategy.close("Long")
if (shortExit)
strategy.close("Short")
// Strategy info
strategy.exit("Exit Long", from_entry="Long", stop=close * 0.995, limit=close * 1.01)
strategy.exit("Exit Short", from_entry="Short", stop=close * 1.005, limit=close * 0.99)
How it works:
- Uses 9-period and 21-period SMA (Simple Moving Averages) crossover.
- Long Entry when fast MA crosses above slow MA and RSI is oversold (<30).
- Short Entry when fast MA crosses below slow MA and RSI is overbought (>70).
- Exits on opposite cross or when RSI reaches neutral zones.
- Includes stop loss and take profit orders (0.5% stop loss and 1% take profit, adjustable).
- Alerts user to switch to 15-minute timeframe if not already set.
To Use:
- Open TradingView.
- Create new Pine Script strategy.
- Paste the above code.
- Apply to a 15-minute chart of your desired Forex pair.
- Backtest and optimize parameters as needed.
If you'd like it more complex with other indicators or different exit rules, let me know!