OPEN-SOURCE SCRIPT

HTF Triangle

HTF Triangle by ZeroHeroTrading aims at detecting ascending and descending triangles using higher time frame data, without repainting nor misalignment issues.

It addresses user requests for combining Ascending Triangle and Descending Triangle into one indicator.

Ascending triangles are defined by an horizontal upper trend line and a rising lower trend line. It is a chart pattern used in technical analysis to predict the continuation of an uptrend.

Descending triangles are defined by a falling upper trend line and an horizontal lower trend line. It is a chart pattern used in technical analysis to predict the continuation of a downtrend.

This indicator can be useful if you, like me, believe that higher time frames can offer a broader perspective and provide clearer signals, smoothing out market noise and showing longer-term trends.

You can change the indicator settings as you see fit to tighten or loosen the detection, and achieve the best results for your use case.

Features
  • It draws the detected ascending and descending triangles on the chart.
  • It supports alerting when a detection occurs.
  • It allows for selecting ascending and/or descending triangle detection.
  • It allows for setting the higher time frame to run the detection on.
  • It allows for setting the minimum number of consecutive valid higher time frame bars to fit the pattern criteria.
  • It allows for setting a high/low factor detection criteria to apply on higher time frame bars high/low as a proportion of the distance between the reference bar high/low and open/close.
  • It allows for turning on an adjustment of the triangle using highest/lowest values within valid higher time frame bars.


Settings
  • Ascending checkbox: Turns on/off ascending triangle detection. Default is on.
  • Descending checkbox: Turns on/off descending triangle detection. Default is on.
  • Higher Time Frame dropdown: Selects higher time frame to run the detection on. It must be higher than, and a multiple of, the chart's timeframe. Default is 5 minutes.
  • Valid Bars Minimum field: Sets minimum number of consecutive valid higher time frame bars to fit the pattern criteria. Default is 3. Minimum is 1.
  • High/Low Factor checkbox: Turns on/off high/low factor detection criteria. Default is on.
  • High/Low Factor field: Sets high/low factor to apply on higher time frame bars high/low as a proportion of the distance between the reference bar high/low and open/close. Default is 0. Minimum is 0. Maximum is 1.
  • Adjust Triangle checkbox: Turns on/off triangle adjustment using highest/lowest values within valid higher time frame bars. Default is on.


Detection Algorithm Notes
The detection algorithm recursively selects a higher time frame bar as reference. Then it looks at the consecutive higher time frame bars (as per the requested number of minimum valid bars) as follows:

Ascending Triangle
  • Low must be higher than previous bar.
  • Open/close max value must be lower than (or equal to) reference bar high.
  • When high/low factor criteria is turned on, high must be higher than (or equal to) reference bar open/close max value plus high/low factor proportion of the distance between reference bar high and open/close max value.

Descending Triangle
  • High must be lower than previous bar.
  • Open/close min value must be higher than (or equal to) reference bar low.
  • When high/low factor criteria is turned on, low must be lower than (or equal to) reference bar open/close min value minus high/low factor proportion of the distance between reference bar low and open/close min value.
ascending-triangleChart patternsdescending-triangleeducationalmultitimeframe

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


Also on:

Disclaimer