R2D2B2C2

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/search?q=cup+with...

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
Script de código aberto

Dentro do verdadeiro espírito TradingView, o autor deste script publicou ele como um script de código aberto, para que os traders possam compreender e checar ele. Um viva ao autor! Você pode usá-lo gratuitamente, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.

Quer usar esse script no gráfico?
study(title="Cup With Handle", shorttitle="CH/RCH", overlay=true)

// Inputs should be: The edges of the potential cup, and the bottom of that potential cup formation.
// Usually the highest and lowest values of price inside a cup with handle formation.
// This code can do both Cup with handle(CH) and Reversed Cup with handle (RCH). Just use the correct order of the inputs.
// For more info about Cup With Handle, use google:
// https://www.google.se/search?q=cup+with+handle+chart+pattern&biw=1858&bih=938&source=lnms&tbm=isch&sa=X&ei=r5VcVZS3JMKhsgHig4DYAg&ved=0CAYQ_AUoAQ
// Note: There is not always a defined handle. Sometimes the final target is reached immediately without any noticable "handle".
Cup_edge = input(title="Cup edge", type=float, defval=0.0, minval=0.0)
Cup_bottom = input(title="Cup bottom", type=float, defval=0.0, minval=0.0)

// simple function for fibonacci calculations, if ever needed. Can be ignored for CH/RCH.
fib1618(x) => x*1.618
fib0618(x) => x*0.618
fib0382(x) => x*0.382

// These below calculations are not used in this CH/RCH example, but I leave them in here in case for experimentations.

A = Cup_bottom
B = fib0618(Cup_edge - Cup_bottom) + A 
C = B - fib1618(Cup_edge - Cup_bottom) 
D = C - fib0382(C - B)
E = D - Cup_edge + Cup_bottom

// Experimental plotting of CH/RCH fibowaves.
//plot(B,title='B wave end', color=green,linewidth=2,offset=15) 
//plot(C,title='C wave end', color=blue,linewidth=2,offset=30) 
//plot(D,title='D wave end', color=purple,linewidth=2,offset=45) 
//plot(E,title='E wave end', color=red,linewidth=2,offset=60)

// This is what the example is going to plot. Simple Cup with Handle. Handle target and Final target.
Depth = Cup_edge - Cup_bottom
Handle = Cup_edge - (Depth*0.5)
Target = Cup_edge + (Depth*0.79)

// As the code below explains: blue is the final target price, red is the potential "handle" price.
plot(Handle, title='Handle', color=red, linewidth=2, offset=0 )
plot(Target, title='Target', color=blue, linewidth=2, offset=0 )
// Best regards, Hull