This project, `sma`, serves as a practical demonstration of how to build a custom Simple Moving Average (SMA) indicator in MQL5 using the **KnitPkg for MetaTrader** package manager. It showcases the integration of core KnitPkg libraries, specifically `@douglasrechia/calc` for mathematical operations and `@douglasrechia/bar` for robust bar data access, to create modular and maintainable trading solutions. It is **not** meant to be a production-grade trading system, but rather an **educational example** of how to reuse packages from the community or your own library.
The indicator calculates and displays a Simple Moving Average based on a user-defined period and a specified price type (typically close price). It leverages the `ITimeSeries` interface and the `TimeSeriesArray` class from `@douglasrechia/bar` to provide a standardized, object-oriented approach to feeding price data into the SMA calculation, ensuring data is always presented in a series-ordered fashion (newest element at index 0).
***Simple Moving Average (SMA) Calculation**: Implements the SMA indicator using the `douglasrechia::SMA` function from the `@douglasrechia/calc` package.
***Type-Safe Time Series Data Access**: Demonstrates the use of the `ITimeSeries<T>` interface and `TimeSeriesArray<T>` class (from `@douglasrechia/bar`) for flexible and series-ordered access to price data, where `ValueAtShift(0)` always refers to the most recent data point.
***Modular and Maintainable Code**: Presents a project structure that promotes code reusability and simplifies maintenance by separating concerns into distinct libraries.
***MetaTrader 5 Integration**: A fully functional MQL5 indicator ready to be compiled and used within the MetaTrader 5 terminal.
2.**KnitPkg CLI**: The KnitPkg package manager for MetaTrader. If you don't have it, you can install it by following the instructions in the [main KnitPkg repository](https://github.com/knitpkg-dev/knitpkg-mt.git).
This project is released under the **MIT License**. See the `LICENSE` file for the full text.
## Disclaimer
*The author provides this code **as‑is**, for **educational purposes only*.
No warranty, express or implied, is given. The author assumes **no liability** for any damages, losses, or legal consequences that may arise from using, modifying, or distributing this software. Use it at your own risk.*