Half Cup [LuxAlgo]The  Half Cup  indicator detects and displays patterns with the shape of a  Half Cup , initiating a channel. From this channel, breakouts are detected and highlighted with dots.
Users can control the shape of the  Half Cup  and the channel length through various settings.
Do note that the displayed half cups are displayed retrospectively, making them subject to backpainting.
🔶  USAGE 
  
The idea behind the indicator is derived from the  Cup & Handle  pattern, which requires waiting for the pattern full completion.
Our  Half Cup  publication aims to find opportunities when the potential cup is only formed halfway. 
  
In this example, a green dot shows the first breakout of the upper channel extremity. A few bars later, the price went under it, after which it returned above, triggering a second green dot. Both triggers were good opportunities in this case, and the price rose afterward.
The  Half Cup  pattern can be the start of a potential complete  Cup & Handle  (As in the example above, a complete  Cup  pattern (without the  Handle ) is shown, manually drawn with dashed lines).
  
Every green/red dot, whether on a bullish or bearish pattern, points to a breakout respectively above/below the channel.
  
Besides drawing patterns and the corresponding breakouts, the  Half Cup  indicator can also provide insights into trends and potential opportunities in the long run. 
🔶  DETAILS 
🔹  Validation 
  
Several criteria must be fulfilled before a visible pattern on the chart is drawn.
Calculations are done beforehand to know where the  Half Cup  pattern would be positioned.
The pattern's bottom and top edges are checked for the number of bars whose closing price is outside the half-cup area. When the number of breakouts above/below is equal to or lower than the user-defined settings ( Max % Breaks Top/Bottom ), the pattern is drawn together with a brighter-colored channel next to it.
Dots highlighting the channel's breakout can be drawn from that moment until the end of both channel lines. 
🔹  Positioning 
  
Users can adjust the following settings to fit their needs:
 
 % Broadness: Moves the Top/Bottom line (bullish or bearish) diagonally upwards/downwards.
 Vertical Shift: Shifts the entire pattern up/down.
 Channel Length: Sets the line length of the channel.
 
Note that adjusting the position of the pattern will change the validation; the script will be rerun to check if patterns are still valid or if new patterns can be drawn. Some patterns may disappear, while new ones may appear.
Before adjusting the position, the user can set  Max % Breaks Top/Bottom  at 100%. When the positioning is set,  Max % Breaks Top/Bottom  can be set as desired.
🔹  Updated Drawings 
  
The  Half Cup  pattern is always drawn retrospectively (that is it is subject to backpainting), the channel is drawn from the bar from where the pattern is detected. Every breakout of the channel will remain visible as dots. 
When a new  swing high/low  is found while the previous  swing low/high  remains the same, the pattern is updated to minimize clutter. The dots of earlier drawings will remain visible (to ensure no repainting occurs), but the color becomes faded, as such bright dots are associated with patterns that are visible on the chart, while faded dots are from removed/updated patterns.
🔶  SETTINGS 
 
 Swing Length: Period used for the swing detection, with higher values returning longer-term Swing Levels.
 
🔹  Validation 
 
 Max % Breaks Bottom: Allowed maximum amount of bars where the closing price is below the bottom of the  Half Cup  pattern against the total width of the pattern (bars).
 Max % Breaks Top: Allowed maximum amount of bars where the closing price is above the top of the  Half Cup  pattern against the total width of the pattern (bars).
 
🔹  Positioning 
 
 % Broadness: Moves the Top/Bottom line (bullish or bearish) diagonally upwards/downwards.
 Vertical Shift: Shifts the entire pattern up/down.
 Channel Length: Sets the line length of the channel.
CUP
Cup & HandleHi, here is my take on  'Cup & Handle' 
Pivot Points - ph   (highest points in a certain period) are stored in an array
When there is a new ph , previous ph's are compared to the latest one.
A temporary test line is drawn between these 2 points.
The script checks if a close (between these 2 points) doesn't break above this test line.
(test line is deleted afterwards)
If it doesn't, and the '% max breaks' are not breached, 2 circle shaped lines are drawn 
(Top & Bottom line of the cup) which forms the Cup, together with the Handle.
The red box (Handle) is the maximum 33-50% retracement (% of cup height)
-> Only the latest pattern is shown, enabling 'Show Cup labels' shows the position of cup patterns in history.
They can be visualised by using 'Bar Replay'
'% max breaks' -> 'maximum highs/lows breaking through the Top/Bottom line
 (% of bars between left & right extreme points of the Cup)
 Settings: 
- 'Left', 'Right' -> regulates Pivot Point values
- 'PP back'       -> max lookback for Pivot High
More explanation can be found in following print screens, 
or by checking the tooltips in the settings
  
  
  
  
Cheers!
Cup FinderHello All, 
This script finds the Cups and you can use it while analysing the symbols. it creates circle and channel for the potential Cups and checks the number of bars included by the channel, if included bars is equal or greater than the value you set then it shows the cup.
The Options:
  "Number for Bars to search"  : Maximum length of a Cup
 "Channel Width of the Cup"  : Tate by the channel width of highest/lowest levels in last 300 bars, by default it's 5%
 "Check for Breakout"  : if there is Cup then it checks Close or High/Low is used a source for breaokuts, usuful while cheking historical bars
"Contained Bar Rate %" : after channel is created the script checks number of bars included by the channel of the Cup, you can set rate of included bars by this option
"S how Channels of Cups ": if you enable this option then you can see the channels around the Cups and set it as you wish
and there are some other options for labeling/removing old Cups and for coloring
Here you can see how channel looks like:
Cup with different colors:
 P.S. This is an experimental work and sorry for no explanation in the script. 
in the future if I have time I will try to write a script for Cup&Handle
This script is also an example to calculate and draw circles :) 
 Enjoy!
Code for Cup With Handle calculations (using Pine)Cup with Handle formation calculations using Pine. 
First of all, ignore all other lines in the example chart except the two FAT lines. The two fat lines are the ones that define the Cup With handle or in the example chart: a Reversed Cup With Handle.
 Note:  Handle does not always develop and sometimes the final target price is reached without forming any handle.
This script can calculate both  Cup With Handle  ( CH ) and  Reversed Cup With Handle  ( RCH ). Just order the input values accordingly.
For more information about Cup With Handle, use google:
www.google.se
The script  need two input parameters : The highest price in the Cup formation and the lowest price in the cup formation or vice versa for the Reversed Cup formation.
Best regards,
/Hull, 2015.05.20.16:31




