///////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 MA Trend Detector Indicator // ----------------------------------------------------- // Name: XTDMA // Description: detect trends based on MA's ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm XTDMA Indicator" #property strict // // START Constants ... // #define ShortName "XTDMA" // // END Constants ... // // // START Inputs ... // // input group "Long Cycle"; // input int lcFastLength = 9; // Fast Length input int lcSlowLength = 18; // Slow Length // input ENUM_MA_METHOD lcMethod = MODE_EMA; // Calculation Method input ENUM_APPLIED_PRICE lcAppliedTo = PRICE_CLOSE; // Calculation Price // input color lcFastColor = clrAqua; // Fast Color input color lcSlowColor = clrMagenta; // Slow Color // input bool lcDrawLines = false; // Draw Fast/Slow Lines input bool lcDrawCrosses = false; // Draw Cross Vertical Lines input bool lcDrawTrends = false; // Draw Trend State // input bool lcDrawSwings = false; // Draw Swing Points // input uchar lcTrendUpArrowCode = 233; // Trend UP Arrow Code input uchar lcTrendDownArrowCode = 234; // Trend Down Arrow Code // input uchar lcSwingsArrowCode = 108; // Swing Point Arrow Code // input group "Medium Cycle"; // input int mcFastLength = 9; // Fast Length input int mcSlowLength = 18; // Slow Length // input ENUM_MA_METHOD mcMethod = MODE_EMA; // Calculation Method input ENUM_APPLIED_PRICE mcAppliedTo = PRICE_CLOSE; // Calculation Price // input color mcFastColor = clrLime; // Fast Color input color mcSlowColor = clrRed; // Slow Color // input bool mcDrawLines = false; // Draw Fast/Slow Lines input bool mcDrawCrosses = false; // Draw Cross Vertical Lines input bool mcDrawTrends = false; // Draw Trend State // input uchar mcTrendUpArrowCode = 233; // Trend UP Arrow Code input uchar mcTrendDownArrowCode = 234; // Trend Down Arrow Code // input group "Short Cycle"; // input int scFastLength = 9; // Fast Length input int scSlowLength = 18; // Slow Length // input ENUM_MA_METHOD scMethod = MODE_EMA; // Calculation Method input ENUM_APPLIED_PRICE scAppliedTo = PRICE_CLOSE; // Calculation Price // input color scFastColor = clrLightBlue; // Fast Color input color scSlowColor = clrLightSalmon; // Slow Color // input bool scDrawLines = false; // Draw Fast/Slow Lines input bool scDrawCrosses = false; // Draw Cross Vertical Lines input bool scDrawTrends = false; // Draw Trend State // input uchar scTrendUpArrowCode = 233; // Trend UP Arrow Code input uchar scTrendDownArrowCode = 234; // Trend Down Arrow Code // // // input group "Current Cycle"; // // // input int ccFastLength = 9; // Fast Length // input int ccSlowLength = 18; // Slow Length // // // input ENUM_MA_METHOD ccMethod = MODE_EMA; // Calculation Method // input ENUM_APPLIED_PRICE ccAppliedTo = PRICE_CLOSE; // Calculation Price // // // input color ccFastColor = clrCadetBlue; // Fast Color // input color ccSlowColor = clrMediumVioletRed; // Slow Color // // // input bool ccDrawLines = false; // Draw Fast/Slow Lines // input bool ccDrawCrosses = false; // Draw Cross Vertical Lines // input bool ccDrawTrends = false; // Draw Trend State // // // input uchar ccTrendUpArrowCode = 233; // Trend UP Arrow Code // input uchar ccTrendDownArrowCode = 234; // Trend Down Arrow Code // // END Inputs ... // // // Includes Logging Library ... #include "../Libraries/x-saherelm.log.lib.mq5"; // // Include Common and Models Library ... #include "../Libraries/x-saherelm.common.lib.mq5"; // // Include Draw Library ... #include "../Libraries/x-saherelm.draw.lib.mq5"; // // START Buffers ... // #property indicator_chart_window // #property indicator_buffers 9 #property indicator_plots 8 // // LC Fast ... #define lcFastBufferIndex 0 double lcSlowBuffer[]; // #property indicator_style1 STYLE_SOLID #property indicator_width1 1 // // LC Slow ... #define lcSlowBufferIndex 1 double lcFastBuffer[]; // #property indicator_style2 STYLE_SOLID #property indicator_width2 1 // // // // LC Swings ... // #define lcSwingBufferIndex 8 // double lcSwingBuffer[]; // // MC Fast ... #define mcFastBufferIndex 2 double mcSlowBuffer[]; // #property indicator_style3 STYLE_DASHDOT #property indicator_width3 1 // // MC Slow ... #define mcSlowBufferIndex 3 double mcFastBuffer[]; // #property indicator_style4 STYLE_DASHDOT #property indicator_width4 1 // // SC Fast ... #define scFastBufferIndex 4 double scSlowBuffer[]; // #property indicator_style5 STYLE_DOT #property indicator_width5 1 // // SC Slow ... #define scSlowBufferIndex 5 double scFastBuffer[]; // #property indicator_style6 STYLE_DOT #property indicator_width6 1 // // // // CC Fast ... // #define ccFastBufferIndex 6 // double ccSlowBuffer[]; // // // #property indicator_style7 STYLE_DASH // #property indicator_width7 1 // // // // CC Slow ... // #define ccSlowBufferIndex 7 // double ccFastBuffer[]; // // // #property indicator_style8 STYLE_DASH // #property indicator_width8 1 // // END Buffers ... // // // START Global Definitions: Variables, Properties and etc ... // // // LC Handlers ... ENUM_TIMEFRAMES lcPeriod; int lcFastMaHandler = INVALID_HANDLE; int lcSlowMaHandler = INVALID_HANDLE; // int lcSwingHandler = INVALID_HANDLE; // // MC Handlers ... ENUM_TIMEFRAMES mcPeriod; int mcFastMaHandler = INVALID_HANDLE; int mcSlowMaHandler = INVALID_HANDLE; // // SC Handlers ... ENUM_TIMEFRAMES scPeriod; int scFastMaHandler = INVALID_HANDLE; int scSlowMaHandler = INVALID_HANDLE; // // CC Handlers ... // int ccFastMaHandler = INVALID_HANDLE; // int ccSlowMaHandler = INVALID_HANDLE; // // END Global Definitions: Variables, Properties and etc ... // // // START Event Handlers ... // // // Initialization ... int OnInit() { // // Validate Inputs ... if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // logTag = ShortName; drawPrefix = ShortName; // // Define Index Buffers ... DefineBuffers(); // // Set Indicator ShortName ... SetIndicatorName(); // // Define LC Handlers ... lcPeriod = GetFarestTimeFrame(); if (lcPeriod == _Period) { // LogMessage("invalid LC TimeFrame ..."); return INIT_FAILED; } // // LC Swing Handler ... // lcSwingHandler = iCustom( // _Symbol, // lcPeriod, // "x-saherelm.obd.indicator", // // // 5, // Market Length // 0, // Arrow Distrance from Price // lcSwingsArrowCode, // Swing High Arrow Code // lcSlowColor, // Swing High Arrow Color // lcSwingsArrowCode, // Swing Low Arrow Code // lcFastColor // Swing Low Arrow Color // ); // if (lcSwingHandler == INVALID_HANDLE) // { // // // LogMessage("LC OBD Indicator initialization failed ..."); // // // return INIT_FAILED; // } // // LC Fast Ma Handler ... lcFastMaHandler = iMA( _Symbol, lcPeriod, lcFastLength, 0, lcMethod, lcAppliedTo); if (lcFastMaHandler == INVALID_HANDLE) { // LogMessage("LC Ma Indicator initialization failed ..."); // return INIT_FAILED; } // // LC Slow Ma Handler ... lcSlowMaHandler = iMA( _Symbol, lcPeriod, lcSlowLength, 0, lcMethod, lcAppliedTo); if (lcSlowMaHandler == INVALID_HANDLE) { // LogMessage("LC Ma Indicator initialization failed ..."); // return INIT_FAILED; } // // Define MC Handlers ... mcPeriod = GetMediumTimeFrame(); if (mcPeriod == _Period) { // LogMessage("invalid MC TimeFrame ..."); return INIT_FAILED; } // // MC Fast Ma Handler ... mcFastMaHandler = iMA( _Symbol, mcPeriod, mcFastLength, 0, mcMethod, mcAppliedTo); if (mcFastMaHandler == INVALID_HANDLE) { // LogMessage("MC Ma Indicator initialization failed ..."); // return INIT_FAILED; } // // MC Slow Ma Handler ... mcSlowMaHandler = iMA( _Symbol, mcPeriod, mcSlowLength, 0, mcMethod, mcAppliedTo); if (mcSlowMaHandler == INVALID_HANDLE) { // LogMessage("MC Ma Indicator initialization failed ..."); // return INIT_FAILED; } // // Define SC Handlers ... scPeriod = _Period; // GetSmallestTimeFrame(); // if (scPeriod == _Period) // { // // // LogMessage("invalid SC TimeFrame ..."); // // return INIT_FAILED; // } // // SC Fast Ma Handler ... scFastMaHandler = iMA( _Symbol, scPeriod, scFastLength, 0, scMethod, scAppliedTo); if (scFastMaHandler == INVALID_HANDLE) { // LogMessage("SC Ma Indicator initialization failed ..."); // return INIT_FAILED; } // // SC Slow Ma Handler ... scSlowMaHandler = iMA( _Symbol, scPeriod, scSlowLength, 0, scMethod, scAppliedTo); if (scSlowMaHandler == INVALID_HANDLE) { // LogMessage("SC Ma Indicator initialization failed ..."); // return INIT_FAILED; } // // CC Fast Ma Handler ... // ccFastMaHandler = iMA( // _Symbol, // _Period, // ccFastLength, // 0, // ccMethod, // ccAppliedTo); // if (ccFastMaHandler == INVALID_HANDLE) // { // // // LogMessage("CC Ma Indicator initialization failed ..."); // // // return INIT_FAILED; // } // // CC Slow Ma Handler ... // ccSlowMaHandler = iMA( // _Symbol, // _Period, // ccSlowLength, // 0, // ccMethod, // ccAppliedTo); // if (ccSlowMaHandler == INVALID_HANDLE) // { // // // LogMessage("CC Ma Indicator initialization failed ..."); // // // return INIT_FAILED; // } // // Comment Period on Chart ... string comment = "XTDMA \n" + "LC Period: " + EnumToString(lcPeriod) + "\n" + "MC Period: " + EnumToString(mcPeriod) + "\n" + "SC Period: " + EnumToString(scPeriod) + "\n"; // Comment(comment); // // Init Succeed ... return INIT_SUCCEEDED; } // // DeInitialization ... void OnDeinit(const int reason) { // // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function // REASON_REMOVE 1 Program removed from a chart // REASON_RECOMPILE 2 Program recompiled // REASON_CHARTCHANGE 3 A symbol or a chart period is changed // REASON_CHARTCLOSE 4 Chart closed // REASON_PARAMETERS 5 Inputs changed by a user // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings // REASON_TEMPLATE 7 Another chart template applied // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value // REASON_CLOSE 9 Terminal closed // // Here we can handle De Initialization Reasons ... OnDeinitDrawLibrary(); // ChartRedraw(); // // Remove Comments ... Comment(""); } // // Calculations ... // // Calculating what we want ... int OnCalculate( // // total Candles on chart ... const int rates_total, // // total calculated Candles on charts ... const int prev_calculated, // // history of Candles Open Time ... const datetime &time[], // // history of Candles Open Price ... const double &open[], // // history of Candles High Price ... const double &high[], // // history of Candles Low Price ... const double &low[], // // history of Candles Close Price ... const double &close[], // // history of Tick Volumes on Candle ... const long &tick_volume[], // // history of Trade Volumes ... const long &volume[], // // history of Candles Spread Price ... const int &spread[]) { // // Prepare Buffers ... ArraySetAsSeries(time, true); ArraySetAsSeries(open, true); ArraySetAsSeries(high, true); ArraySetAsSeries(low, true); ArraySetAsSeries(close, true); ArraySetAsSeries(tick_volume, true); ArraySetAsSeries(volume, true); ArraySetAsSeries(spread, true); // // this counts Available Bars ... int limit; // // because in some cases we may have more than one input for // calculation and we must prevent any calculation // untill we pass the biggest input length, here we get max Input length // and then wait until pass it ... int maxLength = MathMax(0, lcFastLength); maxLength = MathMax(maxLength, lcSlowLength); // // Check Calculated Bars on Handlers ... // int lcSwingCalculatedBars = BarsCalculated(lcSwingHandler); int lcFastMaCalculatedBars = BarsCalculated(lcFastMaHandler); int lcSlowMaCalculatedBars = BarsCalculated(lcSlowMaHandler); int mcFastMaCalculatedBars = BarsCalculated(mcFastMaHandler); int mcSlowMaCalculatedBars = BarsCalculated(mcSlowMaHandler); int scFastMaCalculatedBars = BarsCalculated(scFastMaHandler); int scSlowMaCalculatedBars = BarsCalculated(scSlowMaHandler); // int ccFastMaCalculatedBars = BarsCalculated(ccFastMaHandler); // int ccSlowMaCalculatedBars = BarsCalculated(ccSlowMaHandler); // lcSwingCalculatedBars < maxLength || // ccFastMaCalculatedBars < maxLength || // ccSlowMaCalculatedBars < maxLength if ( lcFastMaCalculatedBars < maxLength || lcSlowMaCalculatedBars < maxLength || mcFastMaCalculatedBars < maxLength || mcSlowMaCalculatedBars < maxLength || scFastMaCalculatedBars < maxLength || scSlowMaCalculatedBars < maxLength) { return prev_calculated; } // limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated; // // Buffers Copy ... // int lcSwingCopied = CopyBuffer(lcSwingHandler, 0, 0, limit + 1, lcSwingBuffer); int lcFastCopiedMas = CopyBuffer(lcFastMaHandler, 0, 0, limit + 1, lcFastBuffer); int lcSlowCopiedMas = CopyBuffer(lcSlowMaHandler, 0, 0, limit + 1, lcSlowBuffer); int mcFastCopiedMas = CopyBuffer(mcFastMaHandler, 0, 0, limit + 1, mcFastBuffer); int mcSlowCopiedMas = CopyBuffer(mcSlowMaHandler, 0, 0, limit + 1, mcSlowBuffer); int scFastCopiedMas = CopyBuffer(scFastMaHandler, 0, 0, limit + 1, scFastBuffer); int scSlowCopiedMas = CopyBuffer(scSlowMaHandler, 0, 0, limit + 1, scSlowBuffer); // int ccFastCopiedMas = CopyBuffer(ccFastMaHandler, 0, 0, limit + 1, ccFastBuffer); // int ccSlowCopiedMas = CopyBuffer(ccSlowMaHandler, 0, 0, limit + 1, ccSlowBuffer); // lcSwingCopied <= 0 || // ccFastCopiedMas <= 0 || // ccSlowCopiedMas <= 0 if ( lcFastCopiedMas <= 0 || lcSlowCopiedMas <= 0 || mcFastCopiedMas <= 0 || mcSlowCopiedMas <= 0 || scFastCopiedMas <= 0 || scSlowCopiedMas <= 0) { return prev_calculated; } // // Main Loop ... for (int i = limit; i >= 0 && !IsStopped(); i--) { CalculateBuffers(i); } // return rates_total; } // // END Event Handlers ... // // // START Functions ... // // // Validate Input Args for Initialization ... bool ValidateInputs() { // bool result = false; // // Validate Args ... if (lcFastLength >= 5 && lcSlowLength >= 6 && lcSlowLength > lcFastLength) { result = true; } // return result; } // // Define Indexes and Styles ... void DefineBuffers() { // // LC Draw Type ... ENUM_DRAW_TYPE lcDrawType = lcDrawLines ? DRAW_LINE : DRAW_NONE; // // LC Fast Buffer ... string lcFastBufferLabel = "LC F " + "(" + (string)lcFastLength + ")"; ArraySetAsSeries(lcFastBuffer, true); SetIndexBuffer(lcFastBufferIndex, lcFastBuffer, INDICATOR_DATA); PlotIndexSetString(lcFastBufferIndex, PLOT_LABEL, lcFastBufferLabel); PlotIndexSetInteger(lcFastBufferIndex, PLOT_DRAW_BEGIN, lcFastLength); PlotIndexSetInteger(lcFastBufferIndex, PLOT_DRAW_TYPE, lcDrawType); PlotIndexSetInteger(lcFastBufferIndex, PLOT_LINE_COLOR, lcFastColor); // // LC Slow Buffer ... string lcSlowBufferLabel = "LC S " + "(" + (string)lcSlowLength + ")"; ArraySetAsSeries(lcSlowBuffer, true); SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer, INDICATOR_DATA); PlotIndexSetString(lcSlowBufferIndex, PLOT_LABEL, lcSlowBufferLabel); PlotIndexSetInteger(lcSlowBufferIndex, PLOT_DRAW_BEGIN, lcSlowLength); PlotIndexSetInteger(lcSlowBufferIndex, PLOT_DRAW_TYPE, lcDrawType); PlotIndexSetInteger(lcSlowBufferIndex, PLOT_LINE_COLOR, lcSlowColor); // // LC Swings ... // ArraySetAsSeries(lcSwingBuffer, true); // SetIndexBuffer(lcSwingBufferIndex, lcSwingBuffer, INDICATOR_CALCULATIONS); // // MC Draw Type ... ENUM_DRAW_TYPE mcDrawType = mcDrawLines ? DRAW_LINE : DRAW_NONE; // // MC Fast Buffer ... string mcFastBufferLabel = "MC F " + "(" + (string)mcFastLength + ")"; ArraySetAsSeries(mcFastBuffer, true); SetIndexBuffer(mcFastBufferIndex, mcFastBuffer, INDICATOR_DATA); PlotIndexSetString(mcFastBufferIndex, PLOT_LABEL, mcFastBufferLabel); PlotIndexSetInteger(mcFastBufferIndex, PLOT_DRAW_BEGIN, mcFastLength); PlotIndexSetInteger(mcFastBufferIndex, PLOT_DRAW_TYPE, mcDrawType); PlotIndexSetInteger(mcFastBufferIndex, PLOT_LINE_COLOR, mcFastColor); // // MC Slow Buffer ... string mcSlowBufferLabel = "MC S " + "(" + (string)mcSlowLength + ")"; ArraySetAsSeries(mcSlowBuffer, true); SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer, INDICATOR_DATA); PlotIndexSetString(mcSlowBufferIndex, PLOT_LABEL, mcSlowBufferLabel); PlotIndexSetInteger(mcSlowBufferIndex, PLOT_DRAW_BEGIN, mcSlowLength); PlotIndexSetInteger(mcSlowBufferIndex, PLOT_DRAW_TYPE, mcDrawType); PlotIndexSetInteger(mcSlowBufferIndex, PLOT_LINE_COLOR, mcSlowColor); // // SC Draw Type ... ENUM_DRAW_TYPE scDrawType = scDrawLines ? DRAW_LINE : DRAW_NONE; // // SC Fast Buffer ... string scFastBufferLabel = "SC F " + "(" + (string)scFastLength + ")"; ArraySetAsSeries(scFastBuffer, true); SetIndexBuffer(scFastBufferIndex, scFastBuffer, INDICATOR_DATA); PlotIndexSetString(scFastBufferIndex, PLOT_LABEL, scFastBufferLabel); PlotIndexSetInteger(scFastBufferIndex, PLOT_DRAW_BEGIN, scFastLength); PlotIndexSetInteger(scFastBufferIndex, PLOT_DRAW_TYPE, scDrawType); PlotIndexSetInteger(scFastBufferIndex, PLOT_LINE_COLOR, scFastColor); // // SC Slow Buffer ... string scSlowBufferLabel = "SC S " + "(" + (string)scSlowLength + ")"; ArraySetAsSeries(scSlowBuffer, true); SetIndexBuffer(scSlowBufferIndex, scSlowBuffer, INDICATOR_DATA); PlotIndexSetString(scSlowBufferIndex, PLOT_LABEL, scSlowBufferLabel); PlotIndexSetInteger(scSlowBufferIndex, PLOT_DRAW_BEGIN, scSlowLength); PlotIndexSetInteger(scSlowBufferIndex, PLOT_DRAW_TYPE, scDrawType); PlotIndexSetInteger(scSlowBufferIndex, PLOT_LINE_COLOR, scSlowColor); // // CC Draw Type ... // ENUM_DRAW_TYPE ccDrawType = ccDrawLines ? DRAW_LINE : DRAW_NONE; // // CC Fast Buffer ... // string ccFastBufferLabel = "CC F " + "(" + (string)ccFastLength + ")"; // ArraySetAsSeries(ccFastBuffer, true); // SetIndexBuffer(ccFastBufferIndex, ccFastBuffer, INDICATOR_DATA); // PlotIndexSetString(ccFastBufferIndex, PLOT_LABEL, ccFastBufferLabel); // PlotIndexSetInteger(ccFastBufferIndex, PLOT_DRAW_BEGIN, ccFastLength); // PlotIndexSetInteger(ccFastBufferIndex, PLOT_DRAW_TYPE, ccDrawType); // PlotIndexSetInteger(ccFastBufferIndex, PLOT_LINE_COLOR, ccFastColor); // // CC Slow Buffer ... // string ccSlowBufferLabel = "CC S " + "(" + (string)ccSlowLength + ")"; // ArraySetAsSeries(ccSlowBuffer, true); // SetIndexBuffer(ccSlowBufferIndex, ccSlowBuffer, INDICATOR_DATA); // PlotIndexSetString(ccSlowBufferIndex, PLOT_LABEL, ccSlowBufferLabel); // PlotIndexSetInteger(ccSlowBufferIndex, PLOT_DRAW_BEGIN, ccSlowLength); // PlotIndexSetInteger(ccSlowBufferIndex, PLOT_DRAW_TYPE, ccDrawType); // PlotIndexSetInteger(ccSlowBufferIndex, PLOT_LINE_COLOR, ccSlowColor); } // // Set Indicator Short Name and also we can define Buffers Labels ... void SetIndicatorName() { // string indicatorShortName = ""; StringConcatenate(indicatorShortName, ShortName, " ", "( ", lcFastLength, ",", lcSlowLength, " )"); // IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName); } // // Calculate Buffers ... void CalculateBuffers(int bar_index) { // // LC ... CalculateLC(bar_index); // // MC ... CalculateMC(bar_index); // // SC ... CalculateSC(bar_index); // // CC ... // CalculateCC(bar_index); } // // Calculate Long Cycle ... void CalculateLC(int bar_index) { // // Get LC Bar Index ... // int lcBarIndex = GetCandleBarIndex(bar_index, lcPeriod); // if (lcBarIndex == -1) { // return; // } // // Check Crosses ... bool isLCFastCrossOverSlow = IsCrossOver(lcFastBuffer, lcSlowBuffer, bar_index); bool isLCFastCrossUnderSlow = IsCrossUnder(lcFastBuffer, lcSlowBuffer, bar_index); if ( lcDrawCrosses && (isLCFastCrossOverSlow || isLCFastCrossUnderSlow)) { // // Draw Crosses ... color clrLine = isLCFastCrossOverSlow ? lcFastColor : lcSlowColor; DrawCrossLine(clrLine, bar_index); } // // Chack Trends ... bool isLCTrendsUp = IsOver(lcFastBuffer, lcSlowBuffer, bar_index); bool isLCTrendsDown = IsUnder(lcFastBuffer, lcSlowBuffer, bar_index); if ( lcDrawTrends && (isLCTrendsUp || isLCTrendsDown)) { // // Draw Trends ... color clrArrow = isLCTrendsUp ? lcFastColor : lcSlowColor; string name = "LC Trends " + (isLCTrendsUp ? "UP" : "Down"); uchar arrowCode = isLCTrendsUp ? lcTrendUpArrowCode : lcTrendDownArrowCode; // DrawTrendsArrow( name, clrArrow, arrowCode, isLCTrendsUp, bar_index); } // // Check Swings ... // double swingValue = lcSwingBuffer[bar_index]; // if (swingValue != 0) // { // // // string name = "LC"; // bool isSwingHigh = swingValue == 1; // uchar arrowCode = lcSwingsArrowCode; // color clrArrow = isSwingHigh ? lcSlowColor : lcFastColor; // // // DrawSwingArrow( // name, // isSwingHigh, // clrArrow, // arrowCode, // bar_index); // } } // // Calculate Medium Cycle ... void CalculateMC(int bar_index) { // // // // Get MC Bar Index ... // int mcBarIndex = GetCandleBarIndex(bar_index, mcPeriod); // if (mcBarIndex == -1) { // return; // } // // Check Crosses ... bool isMCFastCrossOverSlow = IsCrossOver(mcFastBuffer, mcSlowBuffer, bar_index); bool isMCFastCrossUnderSlow = IsCrossUnder(mcFastBuffer, mcSlowBuffer, bar_index); if ( mcDrawCrosses && (isMCFastCrossOverSlow || isMCFastCrossUnderSlow)) { // // Draw Crosses ... color clrLine = isMCFastCrossOverSlow ? mcFastColor : mcSlowColor; DrawCrossLine(clrLine, bar_index); } // // Chack Trends ... bool isMCTrendsUp = IsOver(mcFastBuffer, mcSlowBuffer, bar_index); bool isMCTrendsDown = IsUnder(mcFastBuffer, mcSlowBuffer, bar_index); if ( mcDrawTrends && (isMCTrendsUp || isMCTrendsDown)) { // // Draw Trends ... color clrArrow = isMCTrendsUp ? mcFastColor : mcSlowColor; string name = "MC Trends " + (isMCTrendsUp ? "UP" : "Down"); uchar arrowCode = isMCTrendsUp ? mcTrendUpArrowCode : mcTrendDownArrowCode; // DrawTrendsArrow( name, clrArrow, arrowCode, isMCTrendsUp, bar_index); } } // // Calculate Short Cycle ... void CalculateSC(int bar_index) { // // // // Get SC Bar Index ... // int scBarIndex = GetCandleBarIndex(bar_index, scPeriod); // if (scBarIndex == -1) { // return; // } // // Check Crosses ... bool isSCFastCrossOverSlow = IsCrossOver(scFastBuffer, scSlowBuffer, bar_index); bool isSCFastCrossUnderSlow = IsCrossUnder(scFastBuffer, scSlowBuffer, bar_index); if ( scDrawCrosses && (isSCFastCrossOverSlow || isSCFastCrossUnderSlow)) { // // Draw Crosses ... color clrLine = isSCFastCrossOverSlow ? scFastColor : scSlowColor; DrawCrossLine(clrLine, bar_index); } // // Chack Trends ... bool isSCTrendsUp = IsOver(scFastBuffer, scSlowBuffer, bar_index); bool isSCTrendsDown = IsUnder(scFastBuffer, scSlowBuffer, bar_index); if ( scDrawTrends && (isSCTrendsUp || isSCTrendsDown)) { // // Draw Trends ... color clrArrow = isSCTrendsUp ? scFastColor : scSlowColor; string name = "SC Trends " + (isSCTrendsUp ? "UP" : "Down"); uchar arrowCode = isSCTrendsUp ? scTrendUpArrowCode : scTrendDownArrowCode; // DrawTrendsArrow( name, clrArrow, arrowCode, isSCTrendsUp, bar_index); } } // // Calculate Current Cycle ... // void CalculateCC(int bar_index) // { // // // // Check Crosses ... // bool isCCFastCrossOverSlow = IsCrossOvedr(ccFastBuffer, ccSlowBuffer, bar_index); // bool isCCFastCrossUnderSlow = IsCrossUnder(ccFastBuffer, ccSlowBuffer, bar_index); // if ( // ccDrawCrosses && // (isCCFastCrossOverSlow || isCCFastCrossUnderSlow)) // { // // // // Draw Crosses ... // color clrLine = isCCFastCrossOverSlow ? ccFastColor : ccSlowColor; // DrawCrossLine(clrLine, bar_index); // } // // // // Chack Trends ... // bool isCCTrendsUp = IsOver(ccFastBuffer, ccSlowBuffer, bar_index); // bool isCCTrendsDown = IsUnder(ccFastBuffer, ccSlowBuffer, bar_index); // if ( // ccDrawTrends && // (isCCTrendsUp || isCCTrendsDown)) // { // // // // Draw Trends ... // color clrArrow = isCCTrendsUp ? ccFastColor : ccSlowColor; // string name = "CC Trends " + (isCCTrendsUp ? "UP" : "Down"); // uchar arrowCode = isCCTrendsUp ? ccTrendUpArrowCode : ccTrendDownArrowCode; // // // DrawTrendsArrow( // name, // clrArrow, // arrowCode, // isCCTrendsUp, // bar_index); // } // } // // Draw a Swing Point ... void DrawSwingArrow( string name, // Suggested Object Name Prefix bool isSwingHigh, // Swing Direction color arrowColor, // Suggested Arrow Color uchar arrowCode, // Suggested ArrowCode int bar_index // Bar Index ) { // XOHCL candle = GetCandle(bar_index + 3); // // Define Required Object Properties fro Draw an Arrow ... datetime time = iTime(_Symbol, _Period, bar_index + 3); ENUM_ARROW_ANCHOR anchor = isSwingHigh ? ANCHOR_BOTTOM : ANCHOR_TOP; double price = isSwingHigh ? candle.high : candle.low; name += " Swing " + (isSwingHigh ? "High" : "Low") + "_" + (string)time + "_" + (string)price; // // Draw desired Arrow ... DrawArrow( 0, name, 0, time, price, arrowCode, anchor, arrowColor); } // // Draw Cross Lines of Cycles ... void DrawCrossLine(color lineColor, int bar_index) { // datetime time = iTime(_Symbol, _Period, bar_index); string name = "CrossLine_" + (string)time; // DrawVerticalLine( 0, name, 0, time, lineColor); } // // void DrawTrendsArrow( string name, // Suggested Object Name Prefix color clr, // Suggested Arrow Color uchar arrowCode, // Suggested ArrowCode bool isUp, // Trend Direction int bar_index // Bar Index ) { // XOHCL candle = GetCandle(bar_index); // double price = isUp ? candle.low : candle.high; datetime time = iTime(_Symbol, _Period, bar_index); name += "_" + (string)time + "_" + (string)price; ENUM_ARROW_ANCHOR anchor = isUp ? ANCHOR_TOP : ANCHOR_BOTTOM; // // Draw Specified Arrow ... DrawArrow( 0, name, 0, time, price, arrowCode, anchor, clr, STYLE_SOLID, 1); } // // END Functions ... //