Type/to search

Real-time Trendline Trading Based on Pivot Points and Slope

ATR
1
Follow
1802
Followers

img

Overview

This strategy uses pivot points (PivotHigh and PivotLow) to identify swing highs and lows in price and draws upward and downward trendlines based on these points. The slope of the trendlines is calculated using methods such as ATR (Average True Range), standard deviation, or linear regression, and then adjusted by a slope factor. When the price breaks through a trendline, the strategy generates a buy or sell signal.

Strategy Principle

  1. Use the ta.pivothigh() and ta.pivotlow() functions to detect swing highs (ph) and swing lows (pl) over a certain lookback period.
  2. Calculate the slope of the trendlines based on the selected calculation method (ATR, standard deviation, or linear regression) and adjust it by multiplying with a slope factor (mult).
  3. Using the slope and pivot point prices, calculate the current values of the upward trendline (upper) and downward trendline (lower).
  4. Determine if the current closing price has broken through a trendline: if the closing price is above the upward trendline, an upward breakout signal is generated; if the closing price is below the downward trendline, a downward breakout signal is generated.
  5. Plot the trendlines on the chart, with an option to extend the lines.
  6. Trade based on the breakout signals: go long on an upward breakout and go short on a downward breakout.

Strategy Advantages

  1. The strategy generates trading signals based on objective facts of price behavior (pivot points and trendlines), providing a degree of reliability and stability.
  2. The slope of the trendlines can be dynamically adjusted based on market volatility, adapting to different market conditions.
  3. Users can flexibly choose the slope calculation method and parameter settings to optimize strategy performance.
  4. The strategy provides both real-time and delayed signal modes to meet the needs of different users.
  5. The built-in alert function can help users timely capture trading opportunities.

Strategy Risks

  1. In choppy markets or when trends are unclear, the strategy may generate frequent false signals, leading to decreased profitability.
  2. The performance of the strategy depends on parameter settings; inappropriate parameters may cause the strategy to fail or generate excessive trades.
  3. In delayed signal mode, due to the existence of backtesting, actual trading results may differ from historical test results.

Strategy Optimization Directions

  1. Introduce more technical indicators or price behavior features, such as trading volume and volatility, to assist in confirming trendline breakout signals and improve signal quality.
  2. Filter trading signals by considering factors such as the duration and magnitude of trendline breakouts to reduce false signals.
  3. Optimize position management and risk control, such as dynamically adjusting position size based on trend strength or volatility, and setting reasonable stop-loss and take-profit levels.
  4. Optimize parameters using machine learning or optimization algorithms to find the best parameter combinations.

Summary

This strategy utilizes pivot points and trendline slopes to construct a real-time trendline trading system. By capturing trendline breakout events, the strategy can trade in the early stages of trend formation. Although the strategy has certain advantages, it is still necessary to be aware of its risks in choppy markets and further enhance the strategy's robustness and profitability by introducing more information, optimizing signal filtering, position management, and other methods.

Source
Pine
/*backtest
start: 2023-04-20 00:00:00
end: 2024-04-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(" only Ajay ", overlay=true)

//------------------------------------------------------------------------------
Strategy parameters
Strategy parameters
Swing Detection Lookback
Slope
Slope Calculation Method
backpaint
Show Extended Lines
Style
Up Trendline Color
Down Trendline Color
Comment
All comments (0)
No data
No data
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)