Bar Info
Menu
Debugging
Menu
Derivatives
Menu
Matrix Handling
Menu
Price Rounding
Menu
Regression Lines
Menu
Statistics
Menu
User Tracking
Menu
Example Strategies
Menu
Bar Overlap
Description:
Calculate the overlap of bar of most recent bar to the prior bar.
Syntax:
OverlapBase1();
OverlapBase0();
OverlapFull();
Notes:
There are different ways to calculate the overlap of two objects. You must determine which method is right for your specific task.
Which object is the overlap relative to?
///
/// Calculates the overlap with bar 1 as base bar.
///
private void OverlapBase1()
{
if (High[0] <= Low[1] || Low[0] >= High[1]) // no overlap
{
Value[0] = 0;
}
else if (High[0] < High[1])
{
if (Low[1] < Low[0]) // inside bar
Value[0] = (High[0] - Low[0]) / (High[1] - Low[1]);
else if (Low[1] == Low[0]) // inside bar even lows
Value[0] = (High[0] - Low[0]) / (High[1] - Low[1]);
else if (Low[0] < Low[1]) // low bar with overlap
Value[0] = (High[0] - Low[1]) / (High[1] - Low[1]);
}
else if (High[0] == High[1])
{
if (Low[1] < Low[0]) // inside bar even highs
Value[0] = (High[0] - Low[0]) / (High[1] - Low[1]);
else if (Low[1] == Low[0]) // equal bars
Value[0] = 1;
else if (Low[0] < Low[1]) // low bar with even highs
Value[0] = 1;
}
else if (High[0] > High[1])
{
if (Low[0] > Low[1]) // high bar with some overlap
Value[0] = (High[1] - Low[0]) / (High[1] - Low[1]);
else if (Low[0] == Low[1]) // high bar with even lows
Value[0] = 1;
else if (Low[0] < Low[1]) // outside bar
Value[0] = 1;
}
}
///
/// Calculates the overlap with bar 0 as base bar.
///
private void OverlapBase0()
{
if (High[0] <= Low[1] || Low[0] >= High[1]) // no overlap
{
Value[0] = 0;
}
else if (High[0] < High[1])
{
if (Low[1] < Low[0]) // inside bar
Value[0] = 1;
else if (Low[1] == Low[0]) // inside bar even lows
Value[0] = 1;
else if (Low[0] < Low[1]) // low bar with overlap
Value[0] = (High[0] - Low[1]) / (High[0] - Low[0]);
}
else if (High[0] == High[1])
{
if (Low[1] < Low[0]) // inside bar even highs
Value[0] = 1;
else if (Low[1] == Low[0]) // equal bars
Value[0] = 1;
else if (Low[0] < Low[1]) // low bar with even highs
Value[0] = (High[1] - Low[1]) / (High[0] - Low[0]);
}
else if (High[0] > High[1])
{
if (Low[0] > Low[1]) // high bar with some overlap
Value[0] = (High[1] - Low[0]) / (High[0] - Low[0]);
else if (Low[0] == Low[1]) // high bar with even lows
Value[0] = (High[1] - Low[1]) / (High[0] - Low[0]);
else if (Low[0] < Low[1]) // outside bar
Value[0] = (High[1] - Low[1]) / (High[0] - Low[0]);
}
}
///
/// Calculates the overlap with the highest point to the lowest point as the base.
///
private void OverlapFull()
{
if (High[0] <= Low[1] || Low[0] >= High[1]) // no overlap
{
Value[0] = 0;
}
else if (High[0] < High[1])
{
if (Low[1] < Low[0]) // inside bar
Value[0] = (High[0] - Low[0]) / (High[1] - Low[1]);
else if (Low[1] == Low[0]) // inside bar even lows
Value[0] = (High[0] - Low[0]) / (High[1] - Low[1]);
else if (Low[0] < Low[1]) // low bar with overlap
Value[0] = (High[0] - Low[1]) / (High[1] - Low[0]);
}
else if (High[0] == High[1])
{
if (Low[1] < Low[0]) // inside bar even highs
Value[0] = (High[0] - Low[0]) / (High[1] - Low[1]);
else if (Low[1] == Low[0]) // equal bars
Value[0] = 1;
else if (Low[0] < Low[1]) // low bar with even highs
Value[0] = (High[1] - Low[1]) / (High[0] - Low[0]);
}
else if (High[0] > High[1])
{
if (Low[0] > Low[1]) // high bar with some overlap
Value[0] = (High[1] - Low[0]) / (High[0] - Low[1]);
else if (Low[0] == Low[1]) // high bar with even lows
Value[0] = (High[1] - Low[1]) / (High[0] - Low[0]);
else if (Low[0] < Low[1]) // outside bar
Value[0] = (High[1] - Low[1]) / (High[0] - Low[0]);
}
}