/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class Library // -------------------------------------- // Name: XCChartHelper // Description: Chart Helper Tools ... // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Imports ... #include "../Classes/x-saherelm.base.class.mq5" // // Implementation ... class XCChartHelper : public XCBase { // // Public ... public: // // // Constructor ... XCChartHelper(ulong _chartId = 0) { // // Normalize Chart ID ... mChartID = NormalizeChartId(_chartId); } // // Desconstructor ... ~XCChartHelper() { } // // Actioins ... /** * Redraw Specified Chart ... */ void Redraw() { ChartRedraw(mChartID); } /** * Chart Navigation ... * * @param position: ENUM_CHART_POSITION * @param shift: int * * @return ( bool ) */ bool Navigate( const ENUM_CHART_POSITION position, const int shift // ) { return (ChartNavigate(mChartID, position, shift)); } /** * Apply a Template to Chart ... * * @param filename: string file path ... * * @return ( bool ) */ bool ApplyTemplate(const string filename) const { return (ChartApplyTemplate(mChartID, filename)); } /** * Take an Screenshot of Chart ... * * @param filename: string file path ... * @param width: int ... * @param height: int ... * @param align_mode: ENUM_ALIGN_MODE ... * * @return ( bool ) */ bool ScreenShot( const string filename, const int width, const int height, const ENUM_ALIGN_MODE align_mode // ) const { return (ChartScreenShot(mChartID, filename, width, height, align_mode)); } /** * Writing parameters of chart to file ... **/ bool Save(const int file_handle) { // string work_str; int work_int; //--- check if (file_handle == INVALID_HANDLE || mChartID == -1) return (false); //--- write start marker - 0xFFFFFFFFFFFFFFFF if (FileWriteLong(file_handle, -1) != sizeof(long)) return (false); //--- write chart type if (FileWriteInteger(file_handle, Type(), INT_VALUE) != INT_VALUE) return (false); //--- write chart symbol work_str = Symbol(); work_int = StringLen(work_str); if (FileWriteInteger(file_handle, work_int, INT_VALUE) != INT_VALUE) return (false); if (work_int != 0) if (FileWriteString(file_handle, work_str, work_int) != work_int) return (false); //--- write period of chart if (FileWriteInteger(file_handle, Period(), INT_VALUE) != sizeof(int)) return (false); //--- write value of the "Mode" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_MODE), INT_VALUE) != sizeof(int)) return (false); //--- write value of the "Foreground" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_FOREGROUND), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "Shift" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHIFT), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ShiftSize" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHIFT), INT_VALUE) != sizeof(int)) return (false); //--- write value of the "AutoScroll" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_AUTOSCROLL), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "Scale" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SCALE), INT_VALUE) != sizeof(int)) return (false); //--- write value of the "ScaleFix" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SCALEFIX), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ScaleFix_11" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SCALEFIX_11), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "FixedMax" property if (FileWriteDouble(file_handle, ChartGetDouble(mChartID, CHART_FIXED_MAX)) != sizeof(double)) return (false); //--- write value of the "FixedMin" property if (FileWriteDouble(file_handle, ChartGetDouble(mChartID, CHART_FIXED_MIN)) != sizeof(double)) return (false); //--- write the "ScalePPB" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SCALE_PT_PER_BAR), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "PointsPerBar" property if (FileWriteDouble(file_handle, ChartGetDouble(mChartID, CHART_POINTS_PER_BAR)) != sizeof(double)) return (false); //--- write value of the "ShowOHLC" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_OHLC), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ShowLineBid" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_BID_LINE), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ShowLineAsk" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_ASK_LINE), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ShowLastLine" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_LAST_LINE), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ShowPeriodSep" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_PERIOD_SEP), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ShowGrid" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_GRID), CHAR_VALUE) != sizeof(char)) return (false); //--- write value of the "ShowVolumes" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_VOLUMES), INT_VALUE) != sizeof(int)) return (false); //--- write value of the "ShowObjectDescr" property if (FileWriteInteger(file_handle, (int)ChartGetInteger(mChartID, CHART_SHOW_OBJECT_DESCR), CHAR_VALUE) != sizeof(char)) return (false); //--- successful return (true); } // // Properties ... /** * Get Chart ID ... * * @return ( ulong ) */ ulong ChartId() { return mChartID; } /** * Get Object Type ... * * @return ( int ) **/ int Type() const { return (0x1111); } /** * Get Chart Mode ... * * @return ( ENUM_CHART_MODE ) **/ ENUM_CHART_MODE Mode() { return ((ENUM_CHART_MODE)ChartGetInteger(mChartID, CHART_MODE)); } /** * Get Chart Symbol ... * * @return ( string ) */ string Symbol() { return (ChartSymbol(mChartID)); } /** * Get Chart Period ... * * @return ( ENUM_TIMEFRAMES ) */ ENUM_TIMEFRAMES Period() { return (ChartPeriod(mChartID)); } /** * Count Chart Visible Bars ... * * @return ( int ) */ int VisibleBars() { return ((int)ChartGetInteger(mChartID, CHART_WIDTH_IN_BARS)); } /** * Get Chart First Visible Bars Index ... * * @return ( int ) */ int FirstVisibleBar() { return ((int)ChartGetInteger(mChartID, CHART_FIRST_VISIBLE_BAR)); } /** * Get Chart Last Visible Bars Index ... * * @return ( int ) */ int LastVisibleBar() { // int first = FirstVisibleBar(); int count = VisibleBars(); int result = first + count; return result; } /** * Get Chart's Specified SubWindows Minimum Price ... * * @param subWindow: int * @return ( double ) */ double PriceMin(int subWindow = 0) { // // Normalize Subwindow ... if (subWindow <= 0) { subWindow = 0; } // return (ChartGetDouble(mChartID, CHART_PRICE_MIN, subWindow)); } /** * Get Chart's Specified SubWindows Maximum Price ... * * @param subWindow: int * @return ( double ) */ double PriceMax(int subWindow = 0) { // // Normalize Subwindow ... if (subWindow <= 0) { subWindow = 0; } // return (ChartGetDouble(mChartID, CHART_PRICE_MAX, subWindow)); } /** * Get Chart Width in Pixel ... * * @param subWindow: int ... * * @return ( int ) */ int Width(int subWindow = 0) { // // Normalize Subwindow ... if (subWindow <= 0) { subWindow = 0; } // return (int)ChartGetInteger(mChartID, CHART_WIDTH_IN_PIXELS, subWindow); } /** * Get Chart Height in Pixel ... * * @param subWindow: int ... * * @return ( int ) */ int Height(int subWindow = 0) { // // Normalize Subwindow ... if (subWindow <= 0) { subWindow = 0; } // return (int)ChartGetInteger(mChartID, CHART_HEIGHT_IN_PIXELS, subWindow); } // // Protected ... protected: // // Private ... private: // // Props ... // ulong mChartID; // Chart ID ... }; //