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 Closing Strength

**Description:**

1st Method: Calculate the closing percent of a given bar.

2nd Method: Uses an equation we (TycheTrading.io) developed for calculating the relative closing strength of each bar.

**Syntax:**

ClosingStrength(int bar);

**Arguments:**

bar: The bar that occured X number of bars ago.

` ````
```///
/// Calculates the closing strength of a bar.
///
/// The bar that occured n number of bars ago.
/// 0.9 = closing near high of bar, 0.1 = closing near low of bar.
/// The percent closing strength of requested bar.
private double ClosingStrength(int bar)
{
return (Close[bar] - Low[bar]) / (High[bar] - Low[bar]);
}
///
/// Calculates the closing strength of a bar based on closing direction, relative size, and wick size.
///
/// The bar that occured n number of bars ago.
///
/// With constants all set 1, -3 would be a strong bearish bar, and positive 3 would be a strong bullish bar.
/// Each variable can produce a value between 1 and -1 based on data of the provided bar.
///
/// The relative closing strength of the provided bar.
private double ClosingStrength(int bar)
{
double close = Close[bar];
double open = Open[bar];
double low = Low[bar];
double high = High[bar];
// constants
double C1 = 1;
double C2 = 1;
double C3 = 1;
double wickStrength;
double sizeStrength;
double closeStrength;
// lower wick minus upper wick divided by sum
if (close > open)
{
if (open - low > 0 || high - close > 0) // prevents dividing by zero error
wickStrength = ((open - low) - (high - close)) / ((open - low) + (high - close));
else
wickStrength = 0;
}
else
{
if (close - low > 0 || high - open > 0) // prevents dividing by zero error
wickStrength = ((close - low) - (high - open)) / ((close - low) + (high - open));
else
wickStrength = 0;
}
// bar body size divided by the average of the last n bars body size
int barCount = 5;
if (CurrentBar < bar + barCount) // prevents out of bounds error
barCount = CurrentBar - bar - 1;
double bodySizeSum = 0;
for (int i = 1; i <= barCount; i++)
bodySizeSum += Math.Abs(Close[bar + i] - Open[bar + i]);
double bodySizeAvg = bodySizeSum / barCount;
sizeStrength = (close - open) / bodySizeAvg;
if (sizeStrength > 1) // keeps sizeStrength within same relative range as other variables
sizeStrength = 1;
else if (sizeStrength < -1)
sizeStrength = -1;
// closing percent value of the bar relative to direction of close (bullish or bearish)
if (close > open)
closeStrength = (close - open) / (high - open);
else
closeStrength = (close - open) / (open - low);
return wickStrength * C1 + sizeStrength * C2 + closeStrength * C3;
}