Overview
A gap occurs when there is no overlap between the prices for an asset on one day, and the prices that were traded on the following day. For an asset that is trending up, this would mean that today's low is higher than yesterday's high.
Calculation
let price1 = {open:100,close:110,high:112,low:99};
let price2 = {open:116,close:115,high:117,low:115};
let gap=0;
if(price2.low > price1.high) gap = price2.low - price1.high;
if(price2.high < price1.low) gap = price2.high - price1.low;