0bps

Strategy vault / Machine learning

Comprehensive Futures Automated Trading Strategy for Both Long and Short

This strategy is an innovative Comprehensive Futures Automated Trading Strategy for Both Long and Short . It integrates SuperTrend, QQE and Trend Indicator A-V2 to automatically discover trading signals and make…

Author
ChaoZhang
Complexity
Intermediate · 87 lines
Parameters
10
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

This strategy is an innovative Comprehensive Futures Automated Trading Strategy for Both Long and Short. It integrates SuperTrend, QQE and Trend Indicator A-V2 to automatically discover trading signals and make long/short trades. This strategy aims to identify main market trends and achieve steady profits with good risk control.

Strategy Principle

The strategy consists of three main parts:

  1. SuperTrend indicator determines the main market trend. When price breaks above the up trendline, it indicates an uptrend. When price breaks below the down trendline, it indicates a downtrend.

  2. QQE indicator combines RSI to identify overbought/oversold status. Dynamic overbought/oversold levels are calculated based on RSI average and standard deviation. RSI above upper level indicates overbought signal and RSI below lower level indicates oversold signal.

  3. Trend Indicator A-V2 judges the trend by comparing fast and slow EMA lines. When fast EMA is higher than slow EMA, it sends a buy signal.

When judging market direction, long signals are triggered when SuperTrend shows uptrend, QQE not oversold and A-V2 buy signal occurs. Short signals are triggered when opposite conditions occur.

Advantages

  1. Using multiple indicators improves reliability and reduces false signals.

  2. Automated signal discovery without manual interference reduces human errors.

  3. Organic combination of indicators provides effective risk control while discovering trading opportunities.

  4. Customizable parameters to meet users' needs.

  5. Support both long-only and long/short trading for flexibility.

Risks and Solutions

  1. Indicators may generate false signals under extreme market conditions. Fine-tune parameters to minimize such cases.

  2. Transaction costs and slippage could erode profits. Optimize with stop loss/take profit.

  3. Inadequate parameter setup leads to poor performance. Try different values to find optimal configuration.

Optimization Directions

  1. Increase machine learning to auto optimize parameters based on historical data.

  2. Incorporate more market micro-structure factors like volume to discover better signals.

  3. Implement high frequency trading techniques to auto submit orders.

Conclusion

The strategy combines indicators to assess market structure and achieves steady profits under risk control. It considers both trend direction and overbought/oversold status for nuanced trading decisions. Much room remains for parameter optimization, logic improvements and execution enhancements to further lift strategy performance.

Parameters

NameDefaultWhat it controls
v_input_1trueOne-sided
v_input_29ST ATR Period
v_input_33.9ST ATR Multiplier
v_input_4_hl20ST Source: hl2 | high | low | open | close | hlc3 | hlcc4 | ohlc4
v_input_56QQE RSI Length
v_input_65QQE RSI Smoothing
v_input_73QQE Fast Factor
v_input_83QQE Thresh-hold
v_input_9_close0QQE RSI Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_1052TIA-V2 EMA Period

Source Pine Script

/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//author:Lu Zhenxing, graduated from Furong Chinese High School, earned a master's degree from Yuda University of Science and Technology
//Reference Materials : QQE MOD By:Mihkel00 ,SuperTrend By:KivancOzbilgic , TrendIndicator A-V2 By:Dziwne

strategy("Comprehensive trading strategy", shorttitle="Comprehensive Strategy", overlay=true)

// Add one-sided or long-short parameters
OnlyLong = input(true, title="One-sided")

// SuperTrend Parameters
PeriodsST = input(9, title="ST ATR Period")
MultiplierST = input(3.9, title="ST ATR Multiplier")
srcST = input(hl2, title="ST Source")

atrST = atr(PeriodsST)
upST = srcST - (MultiplierST * atrST)
upST := close[2] > upST[1] ? max(upST, upST[1]) : upST
dnST = srcST + (MultiplierST * atrST)
dnST := close[2] < dnST[1] ? min(dnST, dnST[1]) : dnST
trendST = 1
trendST := nz(trendST[1], trendST)
trendST := trendST == -1 and close[2] > dnST[1] ? 1 : trendST == 1 and close[2] < upST[1] ? -1 : trendST

// QQE Parameters
RSI_PeriodQQE = input(6, title='QQE RSI Length')
SFQQE = input(5, title='QQE RSI Smoothing')
QQE = input(3, title='QQE Fast Factor')
ThreshHoldQQE = input(3, title="QQE Thresh-hold")
srcQQE = input(close, title="QQE RSI Source")

Wilders_PeriodQQE = RSI_PeriodQQE * 2 - 1

RsiQQE = rsi(srcQQE, RSI_PeriodQQE)
RsiMaQQE = ema(RsiQQE, SFQQE)
AtrRsiQQE = abs(RsiMaQQE[1] - RsiMaQQE)
MaAtrRsiQQE = ema(AtrRsiQQE, Wilders_PeriodQQE)
darQQE = ema(MaAtrRsiQQE, Wilders_PeriodQQE) * QQE

basisQQE = sma(RsiMaQQE - 50, 50)
devQQE = 0.35 * stdev(RsiMaQQE - 50, 50)
upperQQE = basisQQE + devQQE
lowerQQE = basisQQE - devQQE

qqeCondition = RsiMaQQE[1] - 50 > upperQQE[1] ? true : RsiMaQQE[1] - 50 < lowerQQE[1] ? false : na

// Trend Indicator A-V2 Parameters
ma_periodA_V2 = input(52, title="TIA-V2 EMA Period")
oA_V2 = ema(open, ma_periodA_V2)
cA_V2 = ema(close, ma_periodA_V2)
trendIndicatorAV2Condition = cA_V2[1] >= oA_V2[1] ? true : false

// Comprehensive trading logic
longCondition = trendST == 1 and qqeCondition and trendIndicatorAV2Condition
shortCondition = trendST == -1 and not qqeCondition and not trendIndicatorAV2Condition

// Open/close logic for long positions
if (OnlyLong)
    if (longCondition)
        strategy.entry("Buy", strategy.long)        
    else
        strategy.close("Buy")

// The logic of doing both long and short positions
if (not OnlyLong)
    if (longCondition)
        strategy.entry("Buy", strategy.long)
    else if (shortCondition)
        strategy.entry("Sell",strategy.short)

    // Add long and short closing logic
    if (not longCondition)
        strategy.close("Buy")
    if (not shortCondition)
        strategy.close("Sell")

// Visual Signal
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition and not OnlyLong, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-18. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Comprehensive-Futures-Automated-Trading-Strategy-for-Both-Long-and-Short.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open