Tyche Trading

Bar Overlap

Bar Info

Debugging

Derivatives

Matrix Handling

Price Rounding

Regression Lines

Statistics

User Tracking

Example Strategies

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?

				
					/// <summary>
/// Calculates the overlap with bar 1 as base bar.
/// </summary>
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;
	}
}

/// <summary>
/// Calculates the overlap with bar 0 as base bar.
/// </summary>
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]);
	}
}

/// <summary>
/// Calculates the overlap with the highest point to the lowest point as the base.
/// </summary>
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]);
	}
}