Strategy vault / Mean reversion
Simple Pivot Reversal Algorithmic Trading Strategy
This strategy performs reversal trading based on pivot point breakouts. It calculates the pivot high and pivot low over a specified period to determine the pivot levels. It goes short when the price breaks above the…

Overview
This strategy performs reversal trading based on pivot point breakouts. It calculates the pivot high and pivot low over a specified period to determine the pivot levels. It goes short when the price breaks above the pivot high, and goes long when the price breaks below the pivot low. This is a typical short-term mean reversion strategy.
Strategy Logic
The core logic of this strategy is to calculate the pivot high and low points. The formulas are:
Pivot High = Sum of highest high over the past N1 bars / N1
Pivot Low = Sum of lowest low over the past N2 bars / N2
Where N1 and N2 are parameters that define the number of bars used to calculate the pivot points.
After obtaining the pivot high/low levels, the trading rules are:
- Short when price breaks above pivot high
- Long when price breaks below pivot low
- Set stop loss after entry
So it realizes a short-term reversal strategy based on pivot point breakouts.
Advantage Analysis
The advantages of this simple strategy are:
- Simple logic, easy to understand and implement
- Suitable for high-frequency short-term trading
- Captures reversal after pivot breakouts
- Optimizable through parameter tuning
Risk Analysis
There are some risks:
- Failed reversal risk - The reversal after pivot breakout may fail and the trend continues
- Stop loss risk - The preset stop loss could be hit resulting in big loss
- Parameter risk - Inappropriate parameters greatly impacts results
These risks can be managed by parameter tuning, applying exit rules etc.
Optimization Directions
There is large room for optimization:
- Combine with other technical indicators to improve entry timing
- Add exit rules like trailing stop loss, profit-taking etc
- Dynamic adjustment of parameters to improve adaptiveness
- Parameter optimization to find the best parameter combinations
Summary
In summary, this is a very simple short-term pivot reversal strategy. Its advantages are simplicity and ability to capture reversals. But there are some risks that need to be addressed through optimization. Overall this serves as a good practice strategy for beginners and builds foundation for advanced strategies.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 4 | leftBars |
| v_input_2 | 2 | rightBars |
| v_input_3 | true | From Day |
| v_input_4 | true | From Month |
| v_input_5 | 2018 | From Year |
| v_input_6 | true | To Day |
| v_input_7 | true | To Month |
| v_input_8 | 9999 | To Year |
Source Pine Script
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Pivot Reversal Strategy - FIGS & DATES 2.0", overlay=true, pyramiding=0, initial_capital=10000, currency="USD", default_qty_type=strategy.percent_of_equity, default_qty_value=100.0, commission_value=0.075)
leftBars = input(4)
rightBars = input(2)
// backtesting date range
from_day = input(defval=1, title="From Day", minval=1, maxval=31)
from_month = input(defval=1, title="From Month", minval=1, maxval=12)
from_year = input(defval=2018, title="From Year", minval=1900)
to_day = input(defval=1, title="To Day", minval=1, maxval=31)
to_month = input(defval=1, title="To Month", minval=1, maxval=12)
to_year = input(defval=9999, title="To Year", minval=1900)
time_cond = true
swh = pivothigh(leftBars, rightBars)
swl = pivotlow(leftBars, rightBars)
middle = (swh+swl)/2
swh_cond = not na(swh)
hprice = 0.0
hprice := swh_cond ? swh : hprice[1]
le = false
le := swh_cond ? true : le[1] and high > hprice ? false : le[1]
if le and time_cond
strategy.entry("LONG", strategy.long, comment="LONG", stop=hprice + syminfo.mintick)
swl_cond = not na(swl)
lprice = 0.0
lprice := swl_cond ? swl : lprice[1]
se = false
se := swl_cond ? true : se[1] and low < lprice ? false : se[1]
if se and time_cond
strategy.entry("SHORT", strategy.short, comment="SHORT", stop=lprice - syminfo.mintick)
//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-17. 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/Simple-Pivot-Reversal-Algorithmic-Trading-Strategy.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
- A Trend Reversal Strategy Based on Moving Averages Price Patterns and VolumePine Script · Mean reversion · 1d
- Adaptive Trading Strategy Combining Dynamic Trend Reversal and Stochastic IndicatorPine Script · Mean reversion · 1d
- Advanced Fibonacci Retracement Trend Following and Reversal Trading StrategyPine Script · Mean reversion · 3h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h
- Dual factor Cycle Trading StrategyPine Script · Mean reversion · 1h