Strategy Overview This strategy, named "Trendlines with Breaks Strategy [AlexGoldHunter]", is designed to identify and trade trendline breakouts. It uses pivot highs and lows to detect significant levels and calculates slopes to plot trendlines. The strategy places buy and sell orders based on these trendlines and triggers alerts for potential breakouts.
Inputs and Parameters Swing Detection Lookback (length): Defines the number of bars to look back for identifying pivot highs and lows.
Slope Multiplier (mult): Adjusts the steepness of the trendlines.
Slope Calculation Method (calcMethod): Determines how the slope is calculated (Atr, Stdev, or Linreg).
Backpainting (backpaint): Toggles the display of elements in the past, providing real-time information when disabled.
Style Settings Up Trendline Color (upCss): Color for upward trendlines (default: teal).
Down Trendline Color (dnCss): Color for downward trendlines (default: red).
Show Extended Lines (showExt): Option to show extended trendlines.
Calculations Pivot High (ph) and Pivot Low (pl): Identifies significant highs and lows based on the lookback period.
Slope Calculation: Determines the slope of trendlines using the selected calculation method.
Trendline Calculation: Updates the positions of the upper and lower trendlines based on the pivot points and slopes.
Plotting Upper and Lower Trendlines: Plots the calculated trendlines on the chart.
Breakout Labels: Adds labels "alex_buy_now" for upward trendline breaks and "alex_sell_now" for downward trendline breaks.
Strategy Conditions Buy Condition:
Triggers a buy order when the price breaks above the downward trendline.
Sell Condition:
Triggers a sell order when the price breaks below the upward trendline.
Alerts Upward Breakout Alert: Notifies when the price breaks above the downward trendline.
Downward Breakout Alert: Notifies when the price breaks below the upward trendline.
Example Code Explanation
//version=5 strategy("Trendlines with Breaks Strategy [AlexGoldHunter]", overlay=true)
// Input parameters length = input.int(14, title="Swing Detection Lookback") mult = input.float(1.0, title="Slope", minval=0, step=0.1) calcMethod = input.string('Atr', title="Slope Calculation Method", options=['Atr','Stdev','Linreg']) backpaint = input(true, tooltip='Backpainting offset displayed elements in the past. Disable backpainting to see real-time information returned by the indicator.')
This script effectively integrates the trendline detection, breakout identification, and automated trading into a single strategy, making it a powerful tool for technical traders on TradingView. If you have any questions or need further clarification, feel free to ask!
Follow Alexgoldhunter for more strategic ideas and minds