Quadratic Fitting Trading Signals Strategy
This strategy fits a quadratic curve to high/low points of bars to generate trading signals when price breaks through the fitted lines. It attempts to identify key support/resistance levels mathematically for…
Overview
This strategy fits a quadratic curve to high/low points of bars to generate trading signals when price breaks through the fitted lines. It attempts to identify key support/resistance levels mathematically for breakout trading.
Strategy Logic
The key components and rules are:
Curve fitting on high/low points using quadratic regression.
Buy signal when close breaks above upper band.
Sell signal when close breaks below lower band.
N periods verification to avoid false breaks.
No fixed exit rules, optimize exits via backtesting.
The strategy tries to identify key prices mathematically and trade the breakouts, a typical breakout system.
Advantages
Compared to other breakout systems, the main advantages are:
Mathematical fitting is more objective than subjective judgment.
Novel approach combining technical analysis and statistical models.
Multi-period verification avoids false breaks.
Backtesting can optimize exits and holding period.
Easy to implement with flexible adjustments.
Model updates automatically without manual intervention.
Can test parameter robustness across products and timeframes.
Potential to optimize further with machine learning.
Overall novel approach with exploratory value.
Risks
However, the risks are:
Fitting performance depends on parameter tuning, overfitting risk.
Fitted lines lag, cannot completely avoid losses.
No volume confirmation, risk of being trapped.
Statistical arbitrage is challenging for persistent alpha.
Limited backtest period, need to verify robustness.
Multi-market adaptability requires validation.
Fixed size lacks dynamic adjustment.
Need strict evaluation of reward/risk ratios.
Enhancements
Based on the analysis, enhancements may involve:
Test parameter robustness across market regimes.
Add volume confirmation indicators.
Optimize entry/exit logic for higher quality signals.
Build dynamic position sizing models.
Incorporate stops to limit losses.
Optimize risk management strategies.
Rolling window backtest validation.
Evaluate multi-market stability.
Leverage machine learning for model optimization.
Conclusion
In summary, this strategy has some innovative value and experimentation merit. But the long-term viability of statistical arbitrage remains unproven. Comprehensive in-sample testing on robustness, risk/reward is key to prevent overfitting and maintain adaptability.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | true | ═══════════════ From ═══════════════ |
| v_input_2 | true | Month |
| v_input_3 | true | Day |
| v_input_4 | 2019 | Year |
| v_input_5 | true | ════════════════ To ════════════════ |
| v_input_6 | 31 | Month |
| v_input_7 | 12 | Day |
| v_input_8 | 9999 | Year |
| v_input_9 | true | ══════════════ Config ══════════════ |
| v_input_10 | 6 | p |
| v_input_11 | 30 | length |
Source Pine Script
/*backtest
start: 2023-08-23 00:00:00
end: 2023-09-22 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //
strategy(title = " Strategy Quadratic Semaphore ",
shorttitle = "SQS",
overlay = true,
precision = 8,
calc_on_order_fills = true,
calc_on_every_tick = true,
backtest_fill_limits_assumption = 0,
default_qty_type = strategy.fixed,
default_qty_value = 2,
initial_capital = 10000,
pyramiding=5,
currency = currency.USD,
linktoseries = true)
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //
backTestSectionFrom = input(title = "═══════════════ From ═══════════════", defval = true, type = input.bool)
FromMonth = input(defval = 1, title = "Month", minval = 1)
FromDay = input(defval = 1, title = "Day", minval = 1)
FromYear = input(defval = 2019, title = "Year", minval = 2014)
backTestSectionTo = input(title = "════════════════ To ════════════════", defval = true, type = input.bool)
ToMonth = input(defval = 31, title = "Month", minval = 1)
ToDay = input(defval = 12, title = "Day", minval = 1)
ToYear = input(defval = 9999, title = "Year", minval = 2014)
Config = input(title = "══════════════ Config ══════════════", defval = true, type = input.bool)
p = input(6)
length = input(30)
//
backTestPeriod() => (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
//
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ //
x1 = bar_index
x2 = sqrt(x1)
y = high
//
S11 = sum(x2,length) - sqrt(sum(x1,length)) / length
S12 = sum(x1*x2,length) - (sum(x1,length) * sum(x2,length)) / length
S22 = sum(sqrt(x2),length) - sqrt(sum(x2,length)) / length
Sy1 = sum (y*x1,length) - (sum(y,length) * sum(x1,length)) / length
Sy2 = sum (y*x2,length) - (sum(y,length) * sum(x2,length)) / length
//
max1 = sma(x1,length)
max2 = sma(x2,length)
may = sma(y,length)
b2 = ((Sy1 * S22) - (Sy2*S12))/(S22*S11 - sqrt(S12))
b3 = ((Sy2 * S11) - (Sy1 * S12))/(S22 * S11 - sqrt(S12))
b1 = may - b2*max1 - b3*max2
qr = b1 + b2*x1 + b3*x2
//
yl = low
//
Sy1l = sum(yl*x1,length) - (sum(yl,length) * sum(x1,length)) / length
Sy2l = sum(yl*x2,length) - (sum(yl,length) * sum(x2,length)) / length
//
mayl = sma(yl,length)
b2l = ((Sy1l * S22) - (Sy2l*S12))/(S22*S11 - sqrt(S12))
b3l = ((Sy2l * S11) - (Sy1l * S12))/(S22 * S11 - sqrt(S12))
b1l = mayl - b2l*max1 - b3l*max2
qrl = b1l + b2l*x1 + b3l*x2
//
period = round(p/2)+1
hh = qr[period]
ll = qrl[period]
countH = 0
countL = 0
buy=0
sell=0
//
for i = 1 to period-1
if qr[i]<hh
countH:=countH+1
if qrl[i]>ll
countL:=countL+1
for i = period+1 to p+1
if qr[i]<hh
countH:=countH+1
if qrl[i]>ll
countL:=countL+1
if countH==p
pivotH = high[period]
buy := 1
if countL==p
pivotL = low[period]
sell := 1
//
plotshape(buy == 1 , text='?', style=shape.arrowup, location=location.belowbar, color=#32CD32, textcolor=color.white, offset=0, transp=0,size=size.auto)
plotshape(sell == 1 , text='?', style=shape.arrowdown, location=location.abovebar, color=#FF0000, textcolor=color.white, offset=0, transp=0,size=size.auto)
//
if (backTestPeriod())
strategy.entry("long", true, 1, when = buy == 1)
strategy.entry("short", false, 1, when = sell == 1)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-23. 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 spread arbitrage engine with WebSocket order routing and leg-risk controls from strategies/Quadratic-Fitting-Trading-Signals-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
- The Triple Moving Average Channel Strategy for Patiently Mining Valuable Information from Candlestick LinesPine Script · Arbitrage · 1d
- Triple Moving Average Quantitative Trading Strategy 433095Pine Script · Arbitrage · 1d
- multiple auxiliary RSI indicator strategyPine Script · Arbitrage · 1d
- Dual Reversal Arbitrage StrategyPine Script · Arbitrage · 1h
- Oscillating Market Long StrategyPine Script · Arbitrage · 1d
- Comparative Relative Strength StrategyPine Script · Arbitrage · 1d