/////////////////////////////////////////////////////// // SaherElm IT Center MQL5 Indicator // ------------------------------------------- // Name: XASCT // Description: XASCTrend Detector ... // // 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 XASCT Indicator" #property strict // #define ShortName "XASCT" // // Inputs ... // input group "Market"; input int risk = 4; // Risk // input group "Presentation"; input bool showLongs = true; // Show Long Arrows input bool showShorts = true; // Show Short Arrows input uchar longArrowCode = 233; // Long Arrow input uchar shortArrowCode = 234; // Short Arrow // // Buffers ... // #property indicator_chart_window // #property indicator_buffers 2 #property indicator_plots 2 // #define longBufferIndex 0 double longBuffer[]; // #property indicator_label1 "XASCT Long" #property indicator_type1 DRAW_ARROW #property indicator_color1 clrAqua #property indicator_width1 3 // #define shortBufferIndex 1 double shortBuffer[]; // #property indicator_label2 "XASCT Short" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrMagenta #property indicator_width2 3 // // Variables ... int maxLength = 0; int wPRHandlers[3]; int x1, x2 = 0; int value10, value11 = 0; // // EVENT Handlers ... // // Initialization ... int OnInit() { // // Validate Inputs ... if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // maxLength = ExtractMaxLengthOfInputs(); // x1 = 67 + risk; x2 = 33 - risk; value10 = 2; value11 = value10; // wPRHandlers[0] = iWPR(_Symbol, _Period, 3); if (wPRHandlers[0] == INVALID_HANDLE) { return INIT_FAILED; } // wPRHandlers[1] = iWPR(_Symbol, _Period, 4); if (wPRHandlers[1] == INVALID_HANDLE) { return INIT_FAILED; } // wPRHandlers[2] = iWPR(_Symbol, _Period, 3 + risk * 2); if (wPRHandlers[2] == INVALID_HANDLE) { return INIT_FAILED; } // // Define Index Buffers ... DefineBuffers(); // // Set Indicator ShortName ... SetIndicatorName(); // // 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 } // // Calculating what we want ... int OnCalculate( const int rates_total, // Total Bars on Chart ... const int prev_calculated, // Total Calculated Bars on Charts ... const datetime &time[], // History of Open Time ... const double &open[], // History of Open Price ... const double &high[], // History of High Price ... const double &low[], // History of Low Price ... const double &close[], // History of Close Price ... const long &tick_volume[], // History of Tick Volumes on Bar ... const long &volume[], // History of Trade Volumes ... const int &spread[] // History of Spread Price ... ) { // // Validate Calculated Bars ... bool isPassedRequiredCalculatedBars = // BarsCalculated(wPRHandlers[0]) == rates_total && BarsCalculated(wPRHandlers[1]) == rates_total && BarsCalculated(wPRHandlers[2]) == rates_total // ; if (!isPassedRequiredCalculatedBars) { return 0; } // // Declare Some Local Variables for Use ... int limit, bar, count, iii; double value2, value3, vel = 0, wprs[]; double trueCount, range, avgRange, mrO1, mrO2; // // checking for the first start of the indicator calculation ... if (prev_calculated > rates_total || prev_calculated <= 0) { limit = rates_total - maxLength; } // // starting index for calculation of all bars else { limit = rates_total - prev_calculated; } // ArraySetAsSeries(wprs, true); ArraySetAsSeries(open, true); ArraySetAsSeries(high, true); ArraySetAsSeries(low, true); ArraySetAsSeries(close, true); // // Main Loop ... for (bar = limit; bar >= 0 && !IsStopped(); bar--) { // range = 0.0; avgRange = 0.0; for (count = bar; count <= bar + 9; count++) { avgRange = avgRange + MathAbs(high[count] - low[count]); } // count = bar; trueCount = 0; range = avgRange / 10; // while (count < bar + 9 && trueCount < 1) { // if (MathAbs(open[count] - close[count + 1]) >= range * 2.0) { trueCount++; } // count++; } // if (trueCount >= 1) { mrO1 = count; } else { mrO1 = -1; } // count = bar; trueCount = 0; // while (count < bar + 6 && trueCount < 1) { // if (MathAbs(close[count + 3] - close[count]) >= range * 4.6) { trueCount++; } // count++; } // if (trueCount >= 1) { mrO2 = count; } else { mrO2 = -1; } // if (mrO1 > -1) { value11 = 0; } else { value11 = value10; } if (mrO2 > -1) { value11 = 1; } else { value11 = value10; } // if (CopyBuffer(wPRHandlers[value11], 0, bar, 1, wprs) <= 0) { return 0; } // value2 = 100 - MathAbs(wprs[0]); // longBuffer[bar] = 0; shortBuffer[bar] = 0; // value3 = 0; // if (value2 < x2) { // iii = 1; while (bar + iii < rates_total) { // if (CopyBuffer(wPRHandlers[value11], 0, bar + iii, 1, wprs) <= 0) { return 0; } // vel = 100 - MathAbs(wprs[0]); if (vel >= x2 && vel <= x1) { iii++; } else { break; } } // if (vel > x1) { value3 = high[bar] + range * 0.5; shortBuffer[bar] = value3; } } // if (value2 > x1) { // iii = 1; while (bar + iii < rates_total) { // if (CopyBuffer(wPRHandlers[value11], 0, bar + iii, 1, wprs) <= 0) { return 0; } // vel = 100 - MathAbs(wprs[0]); if (vel >= x2 && vel <= x1) { iii++; } else { break; } } // if (vel < x2) { value3 = low[bar] - range * 0.5; longBuffer[bar] = value3; } } } // return rates_total; } // // CUSTOM Functions ... // // Validate Input Args for Initialization ... bool ValidateInputs() { // bool result = true; // result = risk >= 1; // return result; } // // Retrieve all Exists Input Max Length ... // use for Start Of Drawing ... int ExtractMaxLengthOfInputs() { // int result = 0; // result = int(MathMax(3 + risk * 2, 4) + 1); // return result; } // // Set Indicator Short Name and also we can define Buffers Labels ... void SetIndicatorName() { // IndicatorSetInteger(INDICATOR_DIGITS, _Digits); IndicatorSetString(INDICATOR_SHORTNAME, ShortName); } // // Define Indexes and Styles ... void DefineBuffers() { // // Longs Buffer ... ENUM_DRAW_TYPE longsDrawType = showLongs ? DRAW_ARROW : DRAW_NONE; ArraySetAsSeries(longBuffer, true); SetIndexBuffer(longBufferIndex, longBuffer, INDICATOR_DATA); PlotIndexSetDouble(longBufferIndex, PLOT_EMPTY_VALUE, 0); PlotIndexSetInteger(longBufferIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(longBufferIndex, PLOT_SHOW_DATA, showLongs); PlotIndexSetInteger(longBufferIndex, PLOT_DRAW_TYPE, longsDrawType); PlotIndexSetInteger(longBufferIndex, PLOT_ARROW, longArrowCode); // // Short Buffer ... ENUM_DRAW_TYPE shortsDrawType = showShorts ? DRAW_ARROW : DRAW_NONE; ArraySetAsSeries(shortBuffer, true); SetIndexBuffer(shortBufferIndex, shortBuffer, INDICATOR_DATA); PlotIndexSetDouble(shortBufferIndex, PLOT_EMPTY_VALUE, 0); PlotIndexSetInteger(shortBufferIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(shortBufferIndex, PLOT_SHOW_DATA, showShorts); PlotIndexSetInteger(shortBufferIndex, PLOT_DRAW_TYPE, shortsDrawType); PlotIndexSetInteger(shortBufferIndex, PLOT_ARROW, shortArrowCode); }