/**
 * Pivot points are major support and resistance levels where there likely to be a retracement
 * of price used by traders to objectively determine potential entry and exit levels of underlying assets.
 * Pivot point breaks can be an entry marker, confirmation of trend direction
 * also confirmation of trend reversal -exit marker.
 * These retracement calculation is based on the last day trading data as we follow
 * the market open, high, low, close on every day.
 * You can also calculate these pivot level on weekly basis.
 * For weekly pivot you need to weekly high, low, and close prices.
 */ type PivotMode = 'classic' | 'woodie' | 'camarilla' | 'fibonacci' ; interface PivotValue { r6 ? : number ; r5 ? : number ; r4 ? : number ; r3 ? : number ; r2 : number ; r1 : number ; pp : number ; s1 : number ; s2 : number ; s3 ? : number ; s4 ? : number ; s5 ? : number ; s6 ? : number ; } export class Pivot { private calculator : ( h : number , l : number , c : number ) => PivotValue ; constructor ( private mode = 'classic' ) { switch ( this . mode ) { case 'classic' : this . calculator = this . classic ; break ; case 'camarilla' : this . calculator = this . camarilla ; break ; case 'woodie' : this . calculator = this . woodie ; break ; case 'fibonacci' : this . calculator = this . fibonacci ; break ; } } public nextValue ( h , l , c ) { return this . calculator ( h , l , c ) ; } private classic ( h , l , c ) { const pp = ( h + l + c ) / 3 ; const s1 = pp * 2 - h ; const s2 = pp - ( h - l ) ; const s3 = l - 2 * ( h - pp ) ; const r1 = pp * 2 - l ; const r2 = pp + ( h - l ) ; const r3 = h + 2 * ( pp - l ) ; return { r3 , r2 , r1 , pp , s1 , s2 , s3 } ; } private woodie ( h , l , c ) { const pp = ( h + l + 2 * c ) / 4 ; const r2 = pp + h - l ; const r1 = 2 * pp - l ; const s1 = 2 * pp - h ; const s2 = pp - h + l ; return { r2 , r1 , pp , s1 , s2 } ; } private camarilla ( h , l , c ) { const delta = ( h - l ) * 1.1 ; const pp = ( h + l + c ) / 3 ; const r5 = ( h / l ) * c ; const r4 = c + delta / 2 ; const r6 = r5 + 1.168 * ( r5 - r4 ) ; const r3 = c + delta / 4 ; const r2 = c + delta / 6 ; const r1 = c + delta / 12 ; const s1 = c - delta / 12 ; const s2 = c - delta / 6 ; const s3 = c - delta / 4 ; const s4 = c - delta / 2 ; const s5 = c - ( r5 - c ) ; const s6 = c - ( r6 - c ) ; return { r6 , r5 , r4 , r3 , r2 , r1 , pp , s1 , s2 , s3 , s4 , s5 , s6 } ; } private fibonacci ( h , l , c ) { const delta = h - l ; const pp = ( h + l + c ) / 3 ; const r3 = pp + delta ; const r2 = pp + delta * 0.618 ; const r1 = pp + delta * 0.382 ; const s1 = pp - delta * 0.382 ; const s2 = pp - delta * 0.618 ; const s3 = pp - delta ; return { r3 , r2 , r1 , pp , s1 , s2 , s3 } ; } }