///////////////////////////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 XCHMA Oscillator Helper for Signal Providers // -------------------------------------------------------------------------- // // 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 // // Includes ... #include "..\Libraries\x-saherelm.log.lib.mq5" #include "..\Libraries\x-saherelm.common.lib.mq5" // // START Enum Definitions ... // // // XCHMA Oscillator Hot State Presentation ... enum ENUM_XCHMA_HOT_STATES { X_XCHMA_HOT_BULLISH = 1, X_XCHMA_HOT_NEUTURAL = 0, X_XCHMA_HOT_BEARISH = -1, }; // // XCHMA Oscillator Cycles State Presentation ... enum ENUM_XCHMA_CYCLE_STATES { X_XCHMA_FAST_CROSSED_OVER_SLOW = 2, X_XCHMA_FAST_OVER_SLOW = 1, X_XCHMA_NEUTURAL = 0, X_XCHMA_FAST_UNDER_SLOW = -1, X_XCHMA_FAST_CROSSED_UNDER_SLOW = -2, }; // // XCHMA Oscillator Buffer Lines ... enum ENUM_X_XCHMA_BUFFER_LINES { X_XCHMA_LC_FAST_LINE = 0, X_XCHMA_LC_SLOW_LINE = 1, X_XCHMA_LC_STATE_LINE = 6, X_XCHMA_MC_FAST_LINE = 2, X_XCHMA_MC_SLOW_LINE = 3, X_XCHMA_MC_STATE_LINE = 7, X_XCHMA_SC_FAST_LINE = 4, X_XCHMA_SC_SLOW_LINE = 5, X_XCHMA_SC_STATE_LINE = 8, X_XCHMA_HOT_STATE_LINE = 9, }; // // END Enum Definitions ... // // // START Inputs ... // input group "XCHMA Oscillator"; // // Commons ... input group "XCHMA Hot Areas"; input bool xCHMADrawHotAreas = false; // Draw Hot Areas Symbol; input uchar xCHMAHotBullishArrowCode = 228; // Hot Bullish Arrow Code; input color xCHMAHotBullishArrowColor = clrAqua; // Hot Bullish Arrow Color; input uchar xCHMAHotBearishArrowCode = 230; // Hot Bearish Arrow Code; input color xCHMAHotBearishArrowColor = clrFuchsia; // Hot Bearish Arrow Color; // // LC Inputs ... input group "XCHMA Long Cycle"; input group "XCHMA LC Market"; input int xCHMALcFastLength = 288; // Fast Length input int xCHMALcSlowLength = 576; // Slow Length input ENUM_MA_METHOD xCHMALcMethod = MODE_EMA; // Calculation Method input ENUM_APPLIED_PRICE xCHMALcAppliedTo = PRICE_CLOSE; // Applied To input group "XCHMA LC Style"; input int xCHMALcDrawWidth = 1; // Draw Width input ENUM_DRAW_TYPE xCHMALcDrawType = DRAW_LINE; // Draw Type input ENUM_LINE_STYLE xCHMALcDrawStyle = STYLE_DOT; // Draw Style input color xCHMALcFastColor = clrAqua; // Fast Color input color xCHMALcSlowColor = clrFuchsia; // Slow Color input group "XCHMA LC Drawings"; input bool xCHMALcDrawFast = true; // Draw Fast input bool xCHMALcDrawSlow = true; // Draw Slow input bool xCHMALcDrawCrosses = false; // Draw Cross Lines // // MC Inputs ... input group "XCHMA Medium Cycle"; input group "XCHMA MC Market"; input int xCHMAMcFastLength = 72; // Fast Length input int xCHMAMcSlowLength = 144; // Slow Length input ENUM_MA_METHOD xCHMAMcMethod = MODE_EMA; // Calculation Method input ENUM_APPLIED_PRICE xCHMAMcAppliedTo = PRICE_CLOSE; // Applied To input group "XCHMA MC Style"; input int xCHMAMcDrawWidth = 1; // Draw Width input ENUM_DRAW_TYPE xCHMAMcDrawType = DRAW_LINE; // Draw Type input ENUM_LINE_STYLE xCHMAMcDrawStyle = STYLE_DOT; // Draw Style input color xCHMAMcFastColor = clrLime; // Fast Color input color xCHMAMcSlowColor = clrRed; // Slow Color input group "XCHMA MC Drawings"; input bool xCHMAMcDrawFast = true; // Draw Fast input bool xCHMAMcDrawSlow = true; // Draw Slow input bool xCHMAMcDrawCrosses = false; // Draw Cross Lines // // SC Inputs ... input group "XCHMA Short Cycle"; input group "XCHMA SC Market"; input int xCHMAScFastLength = 7; // Fast Length input int xCHMAScSlowLength = 14; // Slow Length input ENUM_MA_METHOD xCHMAScMethod = MODE_EMA; // Calculation Method input ENUM_APPLIED_PRICE xCHMAScAppliedTo = PRICE_CLOSE; // Applied To input group "XCHMA SC Style"; input int xCHMAScDrawWidth = 1; // Draw Width input ENUM_DRAW_TYPE xCHMAScDrawType = DRAW_LINE; // Draw Type input ENUM_LINE_STYLE xCHMAScDrawStyle = STYLE_SOLID; // Draw Style input color xCHMAScFastColor = clrLightBlue; // Fast Color input color xCHMAScSlowColor = clrLightSalmon; // Slow Color input group "XCHMA SC Drawings"; input bool xCHMAScDrawFast = true; // Draw Fast input bool xCHMAScDrawSlow = true; // Draw Slow input bool xCHMAScDrawCrosses = false; // Draw Cross Lines // // END Inputs ... // // // START Definitions ... // int xCHMAHandler = INVALID_HANDLE; double xCHMALcFastBuffer[]; double xCHMALcSlowBuffer[]; double xCHMAMcFastBuffer[]; double xCHMAMcSlowBuffer[]; double xCHMAScFastBuffer[]; double xCHMAScSlowBuffer[]; // // END Definitions ... // // // START Handler Functions ... // // // Init Oscillators ... bool XCHMAInitHandlers() { // bool result = false; // // Initialize Indicator/Oscillator Handlers ... ResetLastError(); // // XCHMA Handler ... ArraySetAsSeries(xCHMALcFastBuffer, true); ArraySetAsSeries(xCHMALcSlowBuffer, true); ArraySetAsSeries(xCHMAMcFastBuffer, true); ArraySetAsSeries(xCHMAMcSlowBuffer, true); ArraySetAsSeries(xCHMAScFastBuffer, true); ArraySetAsSeries(xCHMAScSlowBuffer, true); xCHMAHandler = iCustom( _Symbol, _Period, "x-saherelm.xchma.oscillator", // // Inputs ... "", xCHMADrawHotAreas, xCHMAHotBullishArrowCode, xCHMAHotBullishArrowColor, xCHMAHotBearishArrowCode, xCHMAHotBearishArrowColor, // // Long Cycle ... "", "", xCHMALcFastLength, xCHMALcSlowLength, xCHMALcMethod, xCHMALcAppliedTo, "", xCHMALcDrawWidth, xCHMALcDrawType, xCHMALcDrawStyle, xCHMALcFastColor, xCHMALcSlowColor, "", xCHMALcDrawFast, xCHMALcDrawSlow, xCHMALcDrawCrosses, // // Medium Cycle ... "", "", xCHMAMcFastLength, xCHMAMcSlowLength, xCHMAMcMethod, xCHMAMcAppliedTo, "", xCHMAMcDrawWidth, xCHMAMcDrawType, xCHMAMcDrawStyle, xCHMAMcFastColor, xCHMAMcSlowColor, "", xCHMAMcDrawFast, xCHMAMcDrawSlow, xCHMAMcDrawCrosses, // // Short Cycle ... "", "", xCHMAScFastLength, xCHMAScSlowLength, xCHMAScMethod, xCHMAScAppliedTo, "", xCHMAScDrawWidth, xCHMAScDrawType, xCHMAScDrawStyle, xCHMAScFastColor, xCHMAScSlowColor, "", xCHMAScDrawFast, xCHMAScDrawSlow, xCHMAScDrawCrosses); if (xCHMAHandler == INVALID_HANDLE) { // LogMessage("failed to Initialize XCHMA Oscillator: " + (string)GetLastError()); return result; } // result = true; // return result; } // // Release Oscillators ... void XCHMAReleaseHandlers() { IndicatorRelease(xCHMAHandler); } // // Handle Reading Buffers ... void XCHMAReadBuffers( int xCHMAItemsPerTick // Number Of Reading Buffer Items Per Tick ) { // // XCHMA Long Cycle ... // // XCHMA Fast ... CopyBuffer( xCHMAHandler, X_XCHMA_LC_FAST_LINE, 0, xCHMAItemsPerTick, xCHMALcFastBuffer); // // XCHMA Slow ... CopyBuffer( xCHMAHandler, X_XCHMA_LC_SLOW_LINE, 0, xCHMAItemsPerTick, xCHMALcSlowBuffer); // // XCHMA Medium Cycle ... // // XCHMA Fast ... CopyBuffer( xCHMAHandler, X_XCHMA_MC_FAST_LINE, 0, xCHMAItemsPerTick, xCHMAMcFastBuffer); // // XCHMA Slow ... CopyBuffer( xCHMAHandler, X_XCHMA_MC_SLOW_LINE, 0, xCHMAItemsPerTick, xCHMAMcSlowBuffer); // // XCHMA Short Cycle ... // // XCHMA Fast ... CopyBuffer( xCHMAHandler, X_XCHMA_SC_FAST_LINE, 0, xCHMAItemsPerTick, xCHMAScFastBuffer); // // XCHMA Slow ... CopyBuffer( xCHMAHandler, X_XCHMA_SC_SLOW_LINE, 0, xCHMAItemsPerTick, xCHMAScSlowBuffer); } // // END Handler Funcions ... // // // START Signal Related Conditions ... // // // XCHMA Long Conditions ... bool XCHMAHasLongConditions( int xCHMAItemsPerTick // Number Of Reading Buffer Items Per Tick ) { // bool result = false; // return result; } // // XCHMA Short Conditions ... bool XCHMAHasShortConditions( int xCHMAItemsPerTick // Number Of Reading Buffer Items Per Tick ) { // bool result = false; // return result; } // // END Signal Related Conditions ... // // // START XCHMA Custom Functions ... // // // Long Cycle ... // // // Check LC is Peak ... bool XCHMAIsLCPeak() { // bool result = false; // // TODO: Complete this ... // return result; } // // Check LC is Vale ... bool XCHMAIsLCVale() { // bool result = false; // // TODO: Complete this ... // return result; } // // Check LC Fast Crossed Over Slow ... bool XCHMAIsLCFastCrossedOverSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsCrossOver( xCHMALcFastBuffer, xCHMALcSlowBuffer, bar_index); // return result; } // // Check LC Fast Over Slow ... bool XCHMAIsLCFastOverSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsOver( xCHMALcFastBuffer, xCHMALcSlowBuffer, bar_index); // return result; } // // Check LC Fast Crossed Under Slow ... bool XCHMAIsLCFastCrossedUnderSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsCrossUnder( xCHMALcFastBuffer, xCHMALcSlowBuffer, bar_index); // return result; } // // Check LC Fast Under Slow ... bool XCHMAIsLCFastUnderSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsUnder( xCHMALcFastBuffer, xCHMALcSlowBuffer, bar_index); // return result; } // // Medium Cycle ... // // // Check MC is Peak ... bool XCHMAIsMCPeak() { // bool result = false; // // TODO: Complete this ... // return result; } // // Check MC is Vale ... bool XCHMAIsMCVale() { // bool result = false; // // TODO: Complete this ... // return result; } // // Check MC Fast Crossed Over Slow ... bool XCHMAIsMCFastCrossedOverSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsCrossOver( xCHMAMcFastBuffer, xCHMAMcSlowBuffer, bar_index); // return result; } // // Check MC Fast Over Slow ... bool XCHMAIsMCFastOverSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsOver( xCHMAMcFastBuffer, xCHMAMcSlowBuffer, bar_index); // return result; } // // Check MC Fast Crossed Under Slow ... bool XCHMAIsMCFastCrossedUnderSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsCrossUnder( xCHMAMcFastBuffer, xCHMAMcSlowBuffer, bar_index); // return result; } // // Check MC Fast Under Slow ... bool XCHMAIsMCFastUnderSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsUnder( xCHMAMcFastBuffer, xCHMAMcSlowBuffer, bar_index); // return result; } // // Short Cycle ... // // // Check SC is Peak ... bool XCHMAIsSCPeak() { // bool result = false; // // TODO: Complete this ... // return result; } // // Check SC is Vale ... bool XCHMAIsSCVale() { // bool result = false; // // TODO: Complete this ... // return result; } // // Check SC Fast Crossed Over Slow ... bool XCHMAIsSCFastCrossedOverSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsCrossOver( xCHMAScFastBuffer, xCHMAScSlowBuffer, bar_index); // return result; } // // Check SC Fast Over Slow ... bool XCHMAIsSCFastOverSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsOver( xCHMAScFastBuffer, xCHMAScSlowBuffer, bar_index); // return result; } // // Check SC Fast Crossed Under Slow ... bool XCHMAIsSCFastCrossedUnderSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsCrossUnder( xCHMAScFastBuffer, xCHMAScSlowBuffer, bar_index); // return result; } // // Check SC Fast Under Slow ... bool XCHMAIsSCFastUnderSlow( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XCHMAIsValidBuffersSize(bar_index + 1)) { return result; } // result = IsUnder( xCHMAScFastBuffer, xCHMAScSlowBuffer, bar_index); // return result; } // // Utility Functions ... // // // Check all Buffers has valid Size ... bool XCHMAIsValidBuffersSize( int size // the size of buffers which min size for requirements ) { // bool result = false; // if ( size <= 0 || // ArraySize(xCHMALcFastBuffer) < size || ArraySize(xCHMALcSlowBuffer) < size || // ArraySize(xCHMAMcFastBuffer) < size || ArraySize(xCHMAMcSlowBuffer) < size || // ArraySize(xCHMAScFastBuffer) < size || ArraySize(xCHMAScSlowBuffer) < size // ) { result = false; } else { result = true; } // return result; } // // END XCHMA Custom Functions ... //