The resource loading... loading...

Lorenzian Classification Multi-Timeframe Target Strategy

Author: ChaoZhang, Date: 2024-07-31 11:49:32
Tags: EMACIHTFTA

EMA1 - EMA2|, length)) * 100. 3. Lorenzian line = EMA3 + CI.

The strategy calculates the Lorenzian line on both the current timeframe and a higher timeframe to provide a multi-dimensional market perspective. Trading signals are based on price crossovers with the Lorenzian line and are confirmed through a lookback mechanism. A buy signal is triggered when the price crosses above the Lorenzian line and the lowest price within the lookback period is below the Lorenzian line; the sell signal works in the opposite manner.

The strategy also introduces a target price mechanism, determining exit points based on user-defined target percentages. Additionally, it implements dynamic stop-losses to control risk.

Strategy Advantages

  1. Multi-timeframe Analysis: By combining Lorenzian lines from current and higher timeframes, the strategy captures more comprehensive market trends, reducing false signals.

  2. Dynamic Trend Identification: The Lorenzian Classification method quickly adapts to market changes, providing sensitive trend identification capabilities.

  3. Signal Confirmation Mechanism: Using a lookback period to confirm trading signals effectively reduces the probability of erroneous trades.

  4. Target Price Optimization: By setting target percentages, the strategy can maximize profits in favorable market conditions.

  5. Risk Management: Introduction of dynamic stop-loss mechanisms effectively controls risk for each trade.

  6. Visualization and Statistics: The strategy provides intuitive chart displays and trade statistics, facilitating analysis and optimization of strategy performance.

  7. Flexibility: Multiple adjustable parameters allow traders to optimize the strategy according to different market conditions and personal preferences.

Strategy Risks

  1. Parameter Sensitivity: The strategy’s performance is highly dependent on the choice of input parameters. Inappropriate parameter settings may lead to overtrading or missing important opportunities.

  2. Market Condition Dependency: In choppy markets, the strategy may generate frequent false signals, resulting in consecutive losses.

  3. Slippage Risk: In rapidly fluctuating markets, actual execution prices may differ significantly from signal prices.

  4. Over-optimization Risk: Excessive adjustment of parameters to fit historical data may lead to overfitting, affecting future live trading performance.

  5. Technical Failures: Reliance on complex technical indicator calculations means system failures or data errors could lead to incorrect trading decisions.

To mitigate these risks, it is recommended to:

  • Conduct thorough historical backtesting and forward testing.
  • Use appropriate position sizing and risk control measures.
  • Regularly review and adjust strategy parameters to adapt to changing market conditions.
  • Implement robust error handling and monitoring mechanisms.

Strategy Optimization Directions

  1. Dynamic Parameter Adjustment: Implement an adaptive parameter adjustment mechanism to automatically adjust EMA length and threshold based on market volatility.

  2. Additional Filters: Introduce extra technical or fundamental indicators as filters to improve signal quality.

  3. Machine Learning Integration: Utilize machine learning algorithms to optimize parameter selection and signal generation processes.

  4. Multi-asset Correlation Analysis: Consider data from multiple related assets to provide a more comprehensive market perspective.

  5. News Event Integration: Add news event analysis functionality to adjust strategy behavior during important economic data releases.

  6. Volatility Adjustment: Dynamically adjust target percentages and stop-loss levels based on market volatility.

  7. Enhanced Risk Management: Implement more sophisticated position management and risk control strategies, such as volatility-based position sizing.

These optimization directions aim to enhance the strategy’s adaptability and stability, enabling it to maintain good performance under various market conditions.

Conclusion

The Lorenzian Classification Multi-Timeframe Target Strategy is a comprehensive trading system that combines advanced technical analysis methods with intelligent risk management mechanisms. Through multi-timeframe analysis, dynamic trend identification, and target price optimization, this strategy has the potential to achieve consistent trading performance across various market conditions. However, it also faces challenges such as parameter sensitivity and market dependency. Through continuous optimization and risk management, traders can fully leverage the strategy’s advantages while effectively controlling potential risks. Future development should focus on improving the strategy’s adaptability and intelligence to suit constantly changing market environments.


/*backtest
start: 2023-07-31 00:00:00
end: 2024-07-30 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Lorenzian Classification Strategy with Target and Multi-Timeframe", overlay=true)

// Input parameters
length = input.int(5, "Lorenzian Length", minval=1)
threshold = input.float(1.0, "Threshold", step=0.1)
lookback = input.int(3, "Lookback Candles", minval=1, maxval=20)
targetPercentage = input.float(1.5, "Target Percentage (%)", step=0.1) // Target percentage for exit
higherTimeframe = input.timeframe("D", "Higher Timeframe") // Higher timeframe for multi-timeframe analysis

// Lorenzian Classification calculation for current timeframe
ema1 = ta.ema(hlc3, length)
ema2 = ta.ema(ema1, length)
ema3 = ta.ema(ema2, length)

d = ema1 - ema2
ci = d / (0.015 * ta.ema(math.abs(d), length)) * 100

lorenzian = ema3 + ci

// Lorenzian Classification calculation for higher timeframe
hlc3_htf = request.security(syminfo.tickerid, higherTimeframe, (high + low + close)/3 )
ema1_htf = ta.ema(hlc3_htf, length)
ema2_htf = ta.ema(ema1_htf, length)
ema3_htf = ta.ema(ema2_htf, length)

d_htf = ema1_htf - ema2_htf
ci_htf = d_htf / (0.015 * ta.ema(math.abs(d_htf), length)) * 100

lorenzian_htf = ema3_htf + ci_htf

// Signal generation
crossUp = ta.crossover(close, lorenzian)
crossDown = ta.crossunder(close, lorenzian)

// Determine color based on price position relative to the line
lineColor = close > ema3 ? color.green : color.red
lineColorH = close > ema3_htf ? color.blue : color.red

// Plot the line with dynamic color
plot(ema3, color=lineColor, title="EMA3", linewidth=2)
plot(ema3_htf, color=lineColorH, title="EMA3 HTF", linewidth=2)

// Function to check for opposite movement
oppositeMove(isLong) =>
    if isLong
        lowest = ta.lowest(low, lookback)
        lowest < lorenzian[lookback]
    else
        highest = ta.highest(high, lookback)
        highest > lorenzian[lookback]

// Generate buy and sell signals
buySignal = crossUp and oppositeMove(true)
sellSignal = crossDown and oppositeMove(false)

// Calculate and manage target price
var float targetPrice = na
var float plotTargetPrice = na
var float entryPrice = na

// Variables to track trade outcomes
var int targetMet = 0
var int targetNotMet = 0
var int totalTrades = 0

if (buySignal)
    strategy.entry("Buy", strategy.long)
    entryPrice := close
    targetPrice := entryPrice * (1 + targetPercentage/100)
    plotTargetPrice := targetPrice
    totalTrades := totalTrades + 1

if (sellSignal)
    strategy.entry("Sell", strategy.short)
    entryPrice := close
    targetPrice := entryPrice * (1 - targetPercentage/100)
    plotTargetPrice := targetPrice
    totalTrades := totalTrades + 1

// Check if target price is met to exit
if (not na(targetPrice))
    if (strategy.position_size > 0 and high >= targetPrice) // Long position exit condition
        strategy.close("Buy")
        targetPrice := na
        entryPrice := na
        targetMet := targetMet + 1
    else if (strategy.position_size > 0 and low < entryPrice * (1 - targetPercentage/100)) // Stop loss for long
        strategy.close("Buy")
        targetPrice := na
        entryPrice := na
        targetNotMet := targetNotMet + 1
    
    if (strategy.position_size < 0 and low <= targetPrice) // Short position exit condition
        strategy.close("Sell")
        targetPrice := na
        entryPrice := na
        targetMet := targetMet + 1
    else if (strategy.position_size < 0 and high > entryPrice * (1 + targetPercentage/100)) // Stop loss for short
        strategy.close("Sell")
        targetPrice := na
        entryPrice := na
        targetNotMet := targetNotMet + 1

// Reset plotTargetPrice when position is closed
if (strategy.position_size == 0)
    plotTargetPrice := na

// Plot signals and target price
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.purple, style=shape.triangledown, size=size.small)
plot(plotTargetPrice, color=color.yellow, title="Target Price", style=plot.style_circles, linewidth=2)

// Add alerts
alertcondition(buySignal, title="Buy Signal", message="Lorenzian Buy Signal")
alertcondition(sellSignal, title="Sell Signal", message="Lorenzian Sell Signal")

// Calculate success percentage
successPercentage = totalTrades > 0 ? (targetMet / totalTrades) * 100 : 0

// Create a table to display trade outcomes
var table tradeStats = table.new(position.top_right, 2, 3, border_width=1)
table.cell(tradeStats, 0, 0, "Targets Met", bgcolor=color.new(color.green, 30))
table.cell(tradeStats, 1, 0, "Targets Missed", bgcolor=color.new(color.red, 30))
table.cell(tradeStats, 0, 1, str.tostring(targetMet), bgcolor=color.new(color.green, 30))
table.cell(tradeStats, 1, 1, str.tostring(targetNotMet), bgcolor=color.new(color.red, 30))
table.cell(tradeStats, 0, 2, "Success Rate", bgcolor=color.new(color.blue, 30))
table.cell(tradeStats, 1, 2, str.tostring(successPercentage, "#.##") + "%", bgcolor=color.new(color.blue, 30))

Related

More