Skip to main content

Candle Property

The candle property is a static array of Candle objects that represent candlestick data. The candles are ordered in descending order by their Time property, meaning the most recent candle is at index [0], and older candles follow sequentially.

For example:

  • candle[0].Time (most recent candle)
  • candle[10].Time (older candle)

Candle Array Definition

public static Candle[] candle { get; set; } = Array.Empty<Candle>();
  • Type: Candle[] (Array of Candle objects)
  • Ordering: Descending by Time (most recent first)

Candle Class Structure

Each Candle object contains the following properties:

public class Candle
{
public double High { get; set; }
public double Open { get; set; }
public double Close { get; set; }
public double Low { get; set; }
public double Volume { get; set; }
public long Time { get; set; } // Timestamp in milliseconds
}

Property Descriptions

  • High (double): The highest price during the candle's time interval.
  • Open (double): The opening price at the start of the candle's time interval.
  • Close (double): The closing price at the end of the candle's time interval.
  • Low (double): The lowest price during the candle's time interval.
  • Volume (double): The trading volume during the candle's time interval.
  • Time (long): The timestamp representing the start of the candle's time interval, in milliseconds since the Unix epoch (January 1, 1970).

Usage Examples

Accessing the Most Recent Candle

// Access the most recent candle
Candle recentCandle = candle[0];

// Display candle information
Console.WriteLine($"Time: {recentCandle.Time}");
Console.WriteLine($"Open: {recentCandle.Open}");
Console.WriteLine($"High: {recentCandle.High}");
Console.WriteLine($"Low: {recentCandle.Low}");
Console.WriteLine($"Close: {recentCandle.Close}");
Console.WriteLine($"Volume: {recentCandle.Volume}");

Iterating Over Candles

// Iterate through all candles
foreach (Candle c in candle)
{
Console.WriteLine($"Time: {c.Time}, Open: {c.Open}, High: {c.High}, Low: {c.Low}, Close: {c.Close}, Volume: {c.Volume}");
}

Converting Timestamp to DateTime

To convert the Time property from milliseconds to a human-readable DateTime:

long timestamp = recentCandle.Time; // Time in milliseconds
DateTime dateTime = DateTimeOffset.FromUnixTimeMilliseconds(timestamp).UtcDateTime;

Console.WriteLine($"Candle Time (UTC): {dateTime}");

Important Notes

  • Descending Order: The candles are stored in descending order based on their Time property. This ensures that the most recent data is easily accessible at the beginning of the array.
  • Time Property: The Time property is measured in milliseconds since the Unix epoch. This allows for precise time tracking of each candle.
  • Data Integrity: Ensure that the candle array is populated with up-to-date and accurate market data for reliable analysis.

Sample Data Representation

Assuming you have the following candles (example data):

IndexTime (ms)OpenHighLowCloseVolume
0557200100.50102.0099.75101.251500
1553600101.25103.00100.00102.501200
.....................
1069320095.0096.5094.2595.751800
  • Index [0]: Most recent candle.
  • Index [10]: Older candle.

Best Practices

  • Data Updates: Regularly update the candle array to maintain the latest market information.
  • Thread Safety: If accessing the candle property from multiple threads, ensure proper synchronization to prevent data corruption.
  • Error Handling: Validate the array bounds when accessing elements to avoid IndexOutOfRangeException.

Conclusion

The candle property provides a structured and time-ordered collection of market data, essential for performing technical analysis, backtesting strategies, or visualizing price movements over time. By leveraging the Candle class properties, developers can gain insights into market trends and make informed decisions.