Strategy vault / Trend following
Williams R Crossover Strategy with Moving Average Filter
This strategy utilizes the Williams %R crossover signals and adds a moving average filter to create a flexible short-term trading system. It can capture overbought and oversold situations clearly, while the MA filter…
Overview
This strategy utilizes the Williams %R crossover signals and adds a moving average filter to create a flexible short-term trading system. It can capture overbought and oversold situations clearly, while the MA filter avoids market noise for higher stability.
Strategy Logic
Calculate Williams %R and 200-period simple moving average (MA).
Go long when %R crosses above -50 level by a threshold and close is above MA.
Go short when %R crosses below -50 level by a threshold and close is below MA.
If long, close position when close reaches take profit (entry price + take profit pips) or stop loss level (entry price - stop loss pips).
If short, close position when close reaches take profit (entry price - take profit pips) or stop loss level (entry price + stop loss pips).
The strategy capitalizes on the overbought/oversold nature of Williams %R, and combines MA trend filter for more reliable signals. The stop loss/take profit logic is simple and clear. Overall it is a complete short-term system.
Advantage Analysis
Williams %R effectively identifies overbought/oversold levels with clear signals.
MA filter adds trend bias to avoid whipsaws.
Customizable parameters for flexibility.
Trailing stop loss locks in most profits.
Simple clear logic, easy to understand and implement. Good for short-term trading.
Applicable to multiple products with flexibility.
Risk Analysis
Williams %R has lagging effect, may miss some opportunities.
MA filter also has some lag.
Strict overbought/oversold rules may miss some trends.
Stop loss too tight may be stopped out by whipsaws.
Stop loss too wide may limit profits.
Parameters need tuning for different market environments.
Optimization Directions
Optimize parameters for higher win rate.
Add other filters like MACD, KDJ etc.
Try different MA types like exponential MA.
Add trend bias, only trade in trend direction.
Optimize stop loss strategies like dynamic stops, chandelier exits etc.
Try position sizing like fixed fractional, Martingale etc.
Utilize machine learning for better parameter optimization.
Conclusion
This strategy combines Williams %R overbought/oversold signals with MA trend filter into a simple short-term system. It has clear entry signals and stop loss/take profit logic. Further improvements can be made through parameter tuning, indicator selection, stop loss management etc for more robustness. Easy to implement and expand on, this strategy is well suited for short-term traders.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | Williams %R Length |
| v_input_2 | 10 | Cross Threshold (Pips) |
| v_input_3 | 30 | Take Profit (Pips) |
| v_input_4 | 20 | Stop Loss (Pips) |
Source Pine Script
/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Williams %R Cross Strategy with MA Filter", overlay=true)
// User Inputs
wrLength = input(14, title="Williams %R Length")
crossPips = input(10, title="Cross Threshold (Pips)")
takeProfitPips = input(30, title="Take Profit (Pips)")
stopLossPips = input(20, title="Stop Loss (Pips)")
// Calculate Williams %R
wrHigh = ta.highest(high, wrLength)
wrLow = ta.lowest(low, wrLength)
wr = (wrHigh - close) / (wrHigh - wrLow) * -100
// Calculate 200-period Simple Moving Average
ma200 = ta.sma(close, 200)
// Entry Conditions
enterLong = ta.crossover(wr, -50 - crossPips) and close > ma200
enterShort = ta.crossunder(wr, -50 + crossPips) and close < ma200
// Exit Conditions
exitLong = close >= (strategy.position_avg_price + (takeProfitPips / syminfo.mintick)) or close <= (strategy.position_avg_price - (stopLossPips / syminfo.mintick))
exitShort = close <= (strategy.position_avg_price - (takeProfitPips / syminfo.mintick)) or close >= (strategy.position_avg_price + (stopLossPips / syminfo.mintick))
// Order Management
if enterLong
strategy.entry("Long", strategy.long)
if enterShort
strategy.entry("Short", strategy.short)
if exitLong
strategy.close("Long")
if exitShort
strategy.close("Short")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-19. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Williams-R-Crossover-Strategy-with-Moving-Average-Filter.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Bollinger Bands and RSI Trend Following StrategyPine Script · Trend following · 1h
- Dual ATR Channel Trend Following StrategyPine Script · Trend following · 15m
- Dual MA Crossover Trend Tracking StrategyPine Script · Trend following · 1h
- Dual Moving Average Convergence Trend Tracking StrategyPine Script · Trend following · 1d
- Dual Moving Average Crossover Strategy with Stop Loss and Take ProfitPine Script · Trend following · 4h
- Dual SMA Crossover StrategyPine Script · Trend following · 5m