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 ofCandleobjects) - 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
Timeproperty. This ensures that the most recent data is easily accessible at the beginning of the array. - Time Property: The
Timeproperty is measured in milliseconds since the Unix epoch. This allows for precise time tracking of each candle. - Data Integrity: Ensure that the
candlearray is populated with up-to-date and accurate market data for reliable analysis.
Sample Data Representation
Assuming you have the following candles (example data):
| Index | Time (ms) | Open | High | Low | Close | Volume |
|---|---|---|---|---|---|---|
| 0 | 557200 | 100.50 | 102.00 | 99.75 | 101.25 | 1500 |
| 1 | 553600 | 101.25 | 103.00 | 100.00 | 102.50 | 1200 |
| ... | ... | ... | ... | ... | ... | ... |
| 10 | 693200 | 95.00 | 96.50 | 94.25 | 95.75 | 1800 |
- Index
[0]: Most recent candle. - Index
[10]: Older candle.
Best Practices
- Data Updates: Regularly update the
candlearray to maintain the latest market information. - Thread Safety: If accessing the
candleproperty 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.