HTF TriangleHTF 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
HTF Ascending TriangleHTF Ascending Triangle aims at detecting ascending triangles using higher time frame data, without repainting nor misalignment issues.
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.
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 triangle on the chart.
It supports alerting when a detection occurs.
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 factor detection criteria to apply on higher time frame bars high as a proportion of the distance between the reference bar high and open/close.
It allows for turning on an adjustment of the triangle using highest/lowest values within valid higher time frame bars.
Settings
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.
Valid Bars Minimum field: Sets minimum number of consecutive valid higher time frame bars to fit the pattern criteria.
High Factor checkbox: Turns on/off high factor detection criteria.
High Factor field: Sets high factor to apply on higher time frame bars high as a proportion of the distance between the reference bar high and close/open.
Adjust Triangle checkbox: Turns on/off triangle adjustment using highest/lowest values within valid higher time frame bars.
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:
Low must be higher than previous bar.
Open/close max value must be lower than reference bar high.
When high factor criteria is turned on, high must be higher than reference bar open/close max value plus high factor proportion of the distance between reference bar high and open/close max value.
PSv4.0 Limited Array Support Super HackThis is my "PSv4.0 Limited Array Support Super Hack", derived from MichelT's Workaround for Arrays in pine and Bubble sort script, except this utilizes line.new() to obtain one array with up to 100 indices. I provided functions that may be syntactically comparable in operation to the array class we should get with PSv5.0 when that arrives. I have no clue when that ETA shall be either, so your guess is as good as mine. Due to the complexity of the script, I would ONLY recommend this script's functions for reuse by advanced Pine programmers, not newcomers to Pine Script.
Notice: FYI, support for these functions will be limited to only errata with the included functions. Honestly, I don't have an abundance of time on a daily basis to assist members with incorporation into their newly developed scripts. I hope you will understand.
The intention of this script is to provide Pine developers with one large array having up to 100 indices until we have full native array support in the future. Availability of full use of the array is only obtained when bar_index is indicesCount-1, so bear that in mind. This script is so computationally expensive, I would only advise using it "as is" on 5Y and All Charts at it's current initial release. On smaller sampling rates such as 1D, 5D and 1M... it has a tendency to encounter runtime errors such as this message: "Calculation timed out. Remove the indicator and reapply it to the chart". I just switch to a larger sampling interval - 5Y or All. I believe this is occurring due mostly to prng() generating thousands of random floating point numbers, PLUS the overhead of using line.new() for something it wasn't originally intended for. It does also use 64 plots in full color, maxing out the plotting capabilities of Pine as well. With usage of the array functions alone in your code, I anticipate those scripts to be more server friendly.
Basically this scripts functionality, as is, generates 32 pseudorandom numbers per bar in a sky blue birds nest of random numbers. It then sorts them numerically and plots them once again in a visually stunning rainbow spectrum. You will notice the plot()s colors will invert when the sorting order is changed in Settings. I commented out a lot of plot()s because we are limited to a maximum of 64 plot()s. By commenting and uncommenting with highlighted text blocks and + , you may alter the scripts appearance when done properly.
Overall, I hope you find it useful with incorporating expected array functionality that will perpetuate the novel development of next generation indicators in Pine Script version 4.0 . Once again, check out MichelT's brilliantly crafted script mentioned above. You may be able to use both scripts incorporated into an all-in-one to have dual array support, BUT I have not tested this yet, be forewarned. I hope the community contribution of this script in open source is of some benefit to those who can utilize it properly. As always, I have included advanced Pine programming techniques that conform to proper "Pine Etiquette", so this script is more than just a complex array provision...
The comments section below is solely just for commenting and other remarks, ideas, compliments, etc... regarding only this indicator, not others. When available time provides itself, I will consider your inquiries, thoughts, and concepts presented below in the comments section, should you have any questions or comments regarding this indicator. When my indicators achieve more prevalent use by TV members, I may implement more ideas when they present themselves as worthy additions. As always, "Like" it if you simply just like it with a proper thumbs up, and also return to my scripts list occasionally for additional postings. Have a profitable future everyone!