Breakout
Overview
A breakout occurs when a price crosses a prior maximum or minimum value of the series. Breakouts require a time period to specify.
For example, you could ask for a 20 breakout, which means the point where the price crosses the point where it becomes the maximum value
for the last 20 days (or more).
Calculation
The technical.mjs module in the davinci library provides methods for calculating a breakout. The simplest method, breakout, takes
an array of numbers, and a function (called a comparer) and returns the number of indexes in the array from the back of the list
for which the comparer is true.
The comparer is used to specify whether you are looking for a maximum, or a minimum. For instance, the following call to breakout
will take the final valule, 10, and search from the back of the array to the point where the comparer returns false. It will return
the number items from the back where this occurs. In the following example, the result will be 6.
An array with only one element will return 0.
let tc = await import('/lib/finance/technical/v1.0.0/technical.mjs');
let data = [1,3,7,4,7,12,6,5,9,8,7,10];
let breakout1 = tc.breakout(data, (current, prev)=>current>prev);
Try it!