#### DanielManahan

##### Member

I created a script but my only way to do this was to create six different plots for all six possible overlaps. Overlap_Trending up, Overlap Trending Down, Overlap Consolidation Expansion, Overlap Consolidation Contraction, no Overlap gap up, and no overlap gap down.

I want a single plot that handles all overlap conditions such that any gap up returns a zero and all others plots the amount of overlap

here is my code to show my progress so far. and again I just want the logic and math for the code to compare the current candle with the previous candle and return a value of the amount that both candles overlap one another and such that if they gap up or down that value must be zero as there is zero overlap.

thanks.

Input AverageRangeLength = 5;

Input AverageRangeMultiplier = 0.5;

def currentRange = high[0]-low[0];

def previousRange = high[1]-low[1];

def GapDown = if high[0]<low[1] then 1 else 0;

def GapUp = if low[0]>high[1] then 1 else 0;

def OverlapExpand = if high[0]>high[1] and low[0]<low[1] then 1 else 0;

def OverlapContract = if high[0]<high[1] and low[0]>low[1] then 1 else 0;

def OverlapUp = if high[0]>high[1] and low[0]>low[1] and low[0]<high[1] then 1 else 0;

def OverlapDown = if high[0]<high[1] and low[0]<low[1] and high[0]>low[1] then 1 else 0;

def smallerRange = if currentRange<previousRange

then currentRange else previousRange;

plot OLE = if OverlapExpand is true then smallerRange else 0;

plot OLC = if OverlapContract is true then smallerRange else 0;

plot OLD = if OverlapDown is true then high[0]-low[1] else 0;

plot OLU = if OverlapUp is true then high[1]-low[0] else 0;

plot GD = if GapDown is true then low[1]-high[0] else 0;

plot GU = if GapUp is true then low[0]-high[1] else 0;

plot AR = average(currentRange, AverageRangeLength)*AverageRangeMultiplier;

plot lineZERO = 0.0;