/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XCX121XATRHelper // Description: provides all Indicator // Helper requirements ... // // // 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.x-helper.class.mq5" // // Definitions ... // // Definitions ... enum ENUM_X121_XATR_BUFFERS { // X121_ATR_UPPER_LINE = 0, X121_ATR_LOWER_LINE = 1, X121_ATR_SM_UPPER_LINE = 2, X121_ATR_SM_LOWER_LINE = 3, X121_PRICE_CHANGE_LINE = 4, X121_PRICE_CHANGE_SM_LINE = 5, X121_RSI_CHANGE_LINE = 6, X121_RSI_CHANGE_SM_LINE = 7, X121_ATR_LINE = 8, X121_RSI_LINE = 9, }; // // Input Models ... struct X121XATRInputs { // // Props ... // // RSI Detection ... int rsiLength; // Length ENUM_X_PRICE rsiPriceType; // Applied To ENUM_X_MA_METHOD rsiSmoothingMethod; // Smoothing Method; // // ATR Detection ... int atrLength; // Length double atrMultiplier; // Multiplier ENUM_X_PRICE atrUpperPriceType; // Upper Zone Applied To ENUM_X_PRICE atrLowerPriceType; // Lower Zone Applied To ENUM_X_MA_METHOD atrSmoothingMethod; // Smoothing Method // // Price Change ... int priceChangeSmoothingLength; // Length ENUM_X_PRICE priceChangeType; // Price Type ENUM_X_MA_METHOD priceChangeSmoothingMethod; // Moving Average Moethod // // Presentation ... int startCalculationForLastBars; // Calculate Last n Bars bool showAtrUpper; // Show Upper Zone bool showAtrLower; // Show Lower Zone bool showSmoothedAtrUpper; // Show Smoothed Upper Zone bool showSmoothedAtrLower; // Show Smoothed Lower Zone bool showRSIChange; // Show RSI Change bool showSmoothedRSIChange; // ShowSmoothed RSI Change bool showPriceChange; // Show Price Change bool showSmoothedPriceChange; // ShowSmoothed Price Change // // Custom Props ... int rsiOverSoldLevel; // RSI Over Sold Level ... int rsiOverBoughtLevel; // RSI Over Bought Level ... // // Constructor(s) ... X121XATRInputs() { // Clean(); } // // Tools ... // // Clean ... void Clean() { // // RSI Detection ... rsiLength = 0; // Length rsiPriceType = X_PRICE_NONE; // Applied To rsiSmoothingMethod = X_MA_MODE_NONE; // Smoothing Method; // // ATR Detection ... atrLength = 0; // Length atrMultiplier = 0; // Multiplier atrUpperPriceType = X_PRICE_NONE; // Upper Zone Applied To atrLowerPriceType = X_PRICE_NONE; // Lower Zone Applied To atrSmoothingMethod = X_MA_MODE_NONE; // Smoothing Method // // Price Change ... priceChangeSmoothingLength = 0; // Length priceChangeType = X_PRICE_NONE; // Price Type priceChangeSmoothingMethod = X_MA_MODE_NONE; // Moving Average Moethod // // Presentation ... startCalculationForLastBars = 0; // Calculate Last n Bars showAtrUpper = false; // Show Upper Zone showAtrLower = false; // Show Lower Zone showSmoothedAtrUpper = false; // Show Smoothed Upper Zone showSmoothedAtrLower = false; // Show Smoothed Lower Zone showRSIChange = false; // Show RSI Change showSmoothedRSIChange = false; // ShowSmoothed RSI Change showPriceChange = false; // Show Price Change showSmoothedPriceChange = false; // ShowSmoothed Price Change // rsiOverSoldLevel = 0; rsiOverBoughtLevel = 0; // ZeroMemory(this); } // // Default ... void Default() { // // RSI Detection ... rsiLength = 14; // Length rsiPriceType = X_PRICE_CLOSE; // Applied To rsiSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method; // // ATR Detection ... atrLength = 14; // Length atrMultiplier = 1; // Multiplier atrUpperPriceType = X_PRICE_HIGH; // Upper Zone Applied To atrLowerPriceType = X_PRICE_LOW; // Lower Zone Applied To atrSmoothingMethod = X_MA_MODE_SMA; // Smoothing Method // // Price Change ... priceChangeSmoothingLength = 14; // Length priceChangeType = X_PRICE_CLOSE; // Price Type priceChangeSmoothingMethod = X_MA_MODE_SMA; // Moving Average Moethod // // Presentation ... startCalculationForLastBars = 1000; // Calculate Last n Bars showAtrUpper = true; // Show Upper Zone showAtrLower = true; // Show Lower Zone showSmoothedAtrUpper = true; // Show Smoothed Upper Zone showSmoothedAtrLower = true; // Show Smoothed Lower Zone showRSIChange = true; // Show RSI Change showSmoothedRSIChange = true; // ShowSmoothed RSI Change showPriceChange = true; // Show Price Change showSmoothedPriceChange = true; // ShowSmoothed Price Change // rsiOverSoldLevel = 30; rsiOverBoughtLevel = 70; } // // Validate ... bool IsValid() { // bool result = false; // result = // // RSI ... rsiLength > 0 && // // ATR ... atrLength > 0 && atrMultiplier > 0 && // // RSI Levels ... rsiOverSoldLevel > 0 && rsiOverSoldLevel < 100 && rsiOverBoughtLevel > 0 && rsiOverBoughtLevel < 100 && rsiOverSoldLevel < rsiOverBoughtLevel && // priceChangeSmoothingLength > 0 && // IsValid(rsiPriceType) && IsValid(priceChangeType) && IsValid(atrUpperPriceType) && IsValid(atrLowerPriceType) // ; // return result; } // // Retrieve MAx Length ... int Max() { // int result = 0; // result = MathMax(rsiLength, atrLength); result = MathMax(result, priceChangeSmoothingLength); // return result; } }; // // Conditions ... struct X121XATRConditions { // // Common ... string symbol; ENUM_TIMEFRAMES period; datetime time; // // Buffers ... double rsiBuffer[]; double atrBuffer[]; double atrUpperBuffer[]; double atrLowerBuffer[]; double atrUpperSMBuffer[]; double atrLowerSMBuffer[]; double rsiChangeBuffer[]; double rsiChangeSMBuffer[]; double priceChangeBuffer[]; double priceChangeSMBuffer[]; // // Conditions ... // // RSI ... bool isRsiInRange; bool isRsiOverSold; bool isRsiOverBought; bool isRsiCrossedOverOverSold; bool isRsiCrossedUnderOverSold; bool isRsiCrossedOverOverBought; bool isRsiCrossedUnderOverBought; // // Other ... // bool isRsiSMOverPriceChange; bool isRsiSMUnderPriceChange; // bool isRsiSMCrossedOverPriceChange; bool isRsiSMCrossedUnderPriceChange; // bool isPriceChangeSMOverRsi; bool isPriceChangeSMUnderRsi; // bool isPriceChangeSMCrossedOverRsi; bool isPriceChangeSMCrossedUnderRsi; // bool isRsiOverRsiSM; bool isRsiUnderRsiSM; // bool isRsiCrossedOverRsiSM; bool isRsiCrossedUnderRsiSM; // bool isPriceChangeOverPriceChangeSM; bool isPriceChangeUnderPriceChangeSM; // bool isPriceChangeCrossedOverPriceChangeSM; bool isPriceChangeCrossedUnderPriceChangeSM; // // bool isCloseLower // // Constructor ... X121XATRConditions() { Clean(); } // // Tools ... /** * Cleaning Up ... */ void Clean() { // // Commons ... symbol = NULL; period = NULL; time = NULL; // // Buffers ... // Clean(rsiBuffer); Clean(atrBuffer); Clean(atrUpperBuffer); Clean(atrLowerBuffer); Clean(atrUpperSMBuffer); Clean(atrLowerSMBuffer); Clean(rsiChangeBuffer); Clean(rsiChangeSMBuffer); Clean(priceChangeBuffer); Clean(priceChangeSMBuffer); // ArraySetAsSeries(rsiBuffer, true); ArraySetAsSeries(atrBuffer, true); ArraySetAsSeries(atrUpperBuffer, true); ArraySetAsSeries(atrLowerBuffer, true); ArraySetAsSeries(atrUpperSMBuffer, true); ArraySetAsSeries(atrLowerSMBuffer, true); ArraySetAsSeries(rsiChangeBuffer, true); ArraySetAsSeries(rsiChangeSMBuffer, true); ArraySetAsSeries(priceChangeBuffer, true); ArraySetAsSeries(priceChangeSMBuffer, true); // // Conditions ... // // RSI ... isRsiInRange = false; isRsiOverSold = false; isRsiOverBought = false; isRsiCrossedOverOverSold = false; isRsiCrossedUnderOverSold = false; isRsiCrossedOverOverBought = false; isRsiCrossedUnderOverBought = false; // // Other ... // isRsiSMOverPriceChange = false; isRsiSMUnderPriceChange = false; // isRsiSMCrossedOverPriceChange = false; isRsiSMCrossedUnderPriceChange = false; // isPriceChangeSMOverRsi = false; isPriceChangeSMUnderRsi = false; // isPriceChangeSMCrossedOverRsi = false; isPriceChangeSMCrossedUnderRsi = false; // isRsiOverRsiSM = false; isRsiUnderRsiSM = false; // isRsiCrossedOverRsiSM = false; isRsiCrossedUnderRsiSM = false; // isPriceChangeOverPriceChangeSM = false; isPriceChangeUnderPriceChangeSM = false; // isPriceChangeCrossedOverPriceChangeSM = false; isPriceChangeCrossedUnderPriceChangeSM = false; // ZeroMemory(this); } /** * Generate Conditions Scores ... * * @param bullishScore: Double, Directional Scores Reference ... * @param bearishScore: Double, Directional Scores Reference ... */ void GenerateScore( double &bullishScore, double &bearishScore // ) { // bullishScore = 0; bearishScore = 0; // double score = 1; double minScore = 0.5; double highScore = 1.5; // if (isRsiOverSold) { bullishScore += minScore; } if (isRsiOverRsiSM) { bullishScore += minScore; } if (isRsiSMOverPriceChange) { bullishScore += minScore; } if (isPriceChangeSMOverRsi) { bullishScore += minScore; } if (isPriceChangeOverPriceChangeSM) { bullishScore += minScore; } // if (isRsiCrossedOverRsiSM) { bullishScore += score; } if (isRsiCrossedOverOverSold) { bullishScore += score; } if (isRsiCrossedUnderOverBought) { bullishScore += score; } if (isRsiSMCrossedOverPriceChange) { bullishScore += score; } if (isPriceChangeSMCrossedOverRsi) { bullishScore += score; } if (isPriceChangeCrossedOverPriceChangeSM) { bullishScore += score; } // if (isRsiOverBought) { bearishScore += minScore; } if (isRsiUnderRsiSM) { bearishScore += minScore; } if (isRsiSMUnderPriceChange) { bearishScore += minScore; } if (isPriceChangeSMUnderRsi) { bearishScore += minScore; } if (isPriceChangeUnderPriceChangeSM) { bearishScore += minScore; } // if (isRsiCrossedUnderRsiSM) { bearishScore += score; } if (isRsiCrossedUnderOverSold) { bearishScore += score; } if (isRsiCrossedOverOverBought) { bearishScore += score; } if (isRsiSMCrossedUnderPriceChange) { bearishScore += score; } if (isPriceChangeSMCrossedUnderRsi) { bearishScore += score; } if (isPriceChangeCrossedUnderPriceChangeSM) { bearishScore += score; } } /** * Generate Summary String for Represent Conditions State ... * * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... * @param onlyConditions: Boolean, Just Generate Only Conditions ... * @param includeScores: Boolean, Attach Scores Representations on Result ... * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... * @param separator: String, Separate Lines ... * * @return ( string ) */ string GenerateSummary( bool onlyCommons = false, bool onlyConditions = false, bool includeScores = true, bool ignoreFalseConditions = true, string separator = "\n" // ) { // string result = NULL; // double bullishScore = 0; double bearishScore = 0; GenerateScore( bullishScore, bearishScore // ); // string scoresStr = // "Scores: " + separator + "---------------" + separator + "Bullish: " + ToString(bullishScore) + separator + "Bearish: " + ToString(bearishScore) + separator + "" // ; // string commonStr = GenerateSpecifiedCommonSummary( this, separator, includeScores // ); // string conditionsStr = // "-----------------------" + separator + "XATR: " + separator + "-----------------------" + separator + ToString("isRsiInRange", isRsiInRange, ignoreFalseConditions, separator) + ToString("isRsiOverSold", isRsiOverSold, ignoreFalseConditions, separator) + ToString("isRsiOverBought", isRsiOverBought, ignoreFalseConditions, separator) + ToString("isRsiCrossedOverOverSold", isRsiCrossedOverOverSold, ignoreFalseConditions, separator) + ToString("isRsiCrossedUnderOverSold", isRsiCrossedUnderOverSold, ignoreFalseConditions, separator) + ToString("isRsiCrossedOverOverBought", isRsiCrossedOverOverBought, ignoreFalseConditions, separator) + ToString("isRsiCrossedUnderOverBought", isRsiCrossedUnderOverBought, ignoreFalseConditions, separator) + // ToString("isRsiSMOverPriceChange", isRsiSMOverPriceChange, ignoreFalseConditions, separator) + ToString("isRsiSMUnderPriceChange", isRsiSMUnderPriceChange, ignoreFalseConditions, separator) + ToString("isRsiSMCrossedOverPriceChange", isRsiSMCrossedOverPriceChange, ignoreFalseConditions, separator) + ToString("isRsiSMCrossedUnderPriceChange", isRsiSMCrossedUnderPriceChange, ignoreFalseConditions, separator) + ToString("isPriceChangeSMOverRsi", isPriceChangeSMOverRsi, ignoreFalseConditions, separator) + ToString("isPriceChangeSMUnderRsi", isPriceChangeSMUnderRsi, ignoreFalseConditions, separator) + ToString("isPriceChangeSMCrossedOverRsi", isPriceChangeSMCrossedOverRsi, ignoreFalseConditions, separator) + ToString("isPriceChangeSMCrossedUnderRsi", isPriceChangeSMCrossedUnderRsi, ignoreFalseConditions, separator) + ToString("isRsiOverRsiSM", isRsiOverRsiSM, ignoreFalseConditions, separator) + ToString("isRsiUnderRsiSM", isRsiUnderRsiSM, ignoreFalseConditions, separator) + ToString("isRsiCrossedOverRsiSM", isRsiCrossedOverRsiSM, ignoreFalseConditions, separator) + ToString("isRsiCrossedUnderRsiSM", isRsiCrossedUnderRsiSM, ignoreFalseConditions, separator) + ToString("isPriceChangeOverPriceChangeSM", isPriceChangeOverPriceChangeSM, ignoreFalseConditions, separator) + ToString("isPriceChangeUnderPriceChangeSM", isPriceChangeUnderPriceChangeSM, ignoreFalseConditions, separator) + ToString("isPriceChangeCrossedOverPriceChangeSM", isPriceChangeCrossedOverPriceChangeSM, ignoreFalseConditions, separator) + ToString("isPriceChangeCrossedUnderPriceChangeSM", isPriceChangeCrossedUnderPriceChangeSM, ignoreFalseConditions, separator) + // "" // ; // result = // "[" + GetTag() + "]" + separator + (onlyConditions ? "" : commonStr) + (!includeScores ? "" : scoresStr) + " " + separator + (onlyCommons ? "" : conditionsStr) + "" // ; // return result; } /** * Retrieve nique Tag Identifier ... * * @return ( string ) */ string GetTag() { return GetTypeName(this); } // }; // // Class ... class XCX121XATRHelper : public XCBaseHelper { // // Public ... public: // // Props ... // // Constructors ... XCX121XATRHelper() : XCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... ~XCX121XATRHelper() { // Clean(rsiBuffer); Clean(atrBuffer); Clean(atrUpperBuffer); Clean(atrLowerBuffer); Clean(atrUpperSMBuffer); Clean(atrLowerSMBuffer); Clean(rsiChangeBuffer); Clean(rsiChangeSMBuffer); Clean(priceChangeBuffer); Clean(priceChangeSMBuffer); // mInputs.Clean(); } // // Tools ... bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period X121XATRInputs &inputs // Inputs ) { // bool result = false; // mSymbol = symbol; mPeriod = period; // result = inputs.IsValid(); if (!result) { return result; } // ArraySetAsSeries(rsiBuffer, true); ArraySetAsSeries(atrBuffer, true); ArraySetAsSeries(atrUpperBuffer, true); ArraySetAsSeries(atrLowerBuffer, true); ArraySetAsSeries(atrUpperSMBuffer, true); ArraySetAsSeries(atrLowerSMBuffer, true); ArraySetAsSeries(rsiChangeBuffer, true); ArraySetAsSeries(rsiChangeSMBuffer, true); ArraySetAsSeries(priceChangeBuffer, true); ArraySetAsSeries(priceChangeSMBuffer, true); // mInputs = inputs; // mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.x121.xatr", // // Inputs ... // // Market ... "", // // RSI Detection ... "", mInputs.rsiLength, // Length mInputs.rsiPriceType, // Applied To mInputs.rsiSmoothingMethod, // Smoothing Method; // // ATR Detection ... "", mInputs.atrLength, // Length mInputs.atrMultiplier, // Multiplier mInputs.atrUpperPriceType, // Upper Zone Applied To mInputs.atrLowerPriceType, // Lower Zone Applied To mInputs.atrSmoothingMethod, // Smoothing Method // // Price Change ... "", mInputs.priceChangeSmoothingLength, // Length mInputs.priceChangeType, // Price Type mInputs.priceChangeSmoothingMethod, // Moving Average Moethod // // Presentation ... "", mInputs.startCalculationForLastBars, // Calculate Last n Bars mInputs.showAtrUpper, // Show Upper Zone mInputs.showAtrLower, // Show Lower Zone mInputs.showSmoothedAtrUpper, // Show Smoothed Upper Zone mInputs.showSmoothedAtrLower, // Show Smoothed Lower Zone mInputs.showRSIChange, // Show RSI Change mInputs.showSmoothedRSIChange, // ShowSmoothed RSI Change mInputs.showPriceChange, // Show Price Change mInputs.showSmoothedPriceChange // ShowSmoothed Price Change // ); result = mHandler != INVALID_HANDLE; if (!result) { return result; } // return result; } // // Inputs ... // X121XATRInputs GetInputs() { return mInputs; } // bool SetInputs( X121XATRInputs &inputs // Configs ) { // return Init( mSymbol, mPeriod, inputs // ); } // // Readers ... // // RSI ... // double GetRSI( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(rsiBuffer); if (barIndex >= count) { barIndex = count - 1; } // return rsiBuffer[barIndex]; } // int CopyRSI( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, rsiBuffer, buffer, forceClean // ); } // // ATR ... // double GetATR( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(atrBuffer); if (barIndex >= count) { barIndex = count - 1; } // return atrBuffer[barIndex]; } // int CopyATR( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, atrBuffer, buffer, forceClean // ); } // double GetATRUpper( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(atrUpperBuffer); if (barIndex >= count) { barIndex = count - 1; } // return atrUpperBuffer[barIndex]; } // int CopyATRUpper( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, atrUpperBuffer, buffer, forceClean // ); } // double GetATRLower( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(atrLowerBuffer); if (barIndex >= count) { barIndex = count - 1; } // return atrLowerBuffer[barIndex]; } // int CopyATRLower( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, atrLowerBuffer, buffer, forceClean // ); } // double GetSMATRUpper( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(atrUpperSMBuffer); if (barIndex >= count) { barIndex = count - 1; } // return atrUpperSMBuffer[barIndex]; } // int CopySMATRUpper( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, atrUpperSMBuffer, buffer, forceClean // ); } // double GetSMATRLower( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(atrLowerSMBuffer); if (barIndex >= count) { barIndex = count - 1; } // return atrLowerSMBuffer[barIndex]; } // int CopySMATRLower( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, atrLowerSMBuffer, buffer, forceClean // ); } // // PRICE Change ... // double GetPriceChange( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(priceChangeBuffer); if (barIndex >= count) { barIndex = count - 1; } // return priceChangeBuffer[barIndex]; } // int CopyPriceChange( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, priceChangeBuffer, buffer, forceClean // ); } // double GetSMPriceChange( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(priceChangeSMBuffer); if (barIndex >= count) { barIndex = count - 1; } // return priceChangeSMBuffer[barIndex]; } // int CopySMPriceChange( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, priceChangeSMBuffer, buffer, forceClean // ); } // // RSI Change ... // double GetRsiChange( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(rsiChangeBuffer); if (barIndex >= count) { barIndex = count - 1; } // return rsiChangeBuffer[barIndex]; } // int CopyRsiChange( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, rsiChangeBuffer, buffer, forceClean // ); } // double GetSMRsiChange( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(barIndex); // int count = ArraySize(rsiChangeSMBuffer); if (barIndex >= count) { barIndex = count - 1; } // return rsiChangeSMBuffer[barIndex]; } // int CopySMRsiChange( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer bool forceClean = true // Force To Clean buffer ) { // // Update Calculations ... Calculate(start); // // Copy Items ... return Copy( 0, count, rsiChangeSMBuffer, buffer, forceClean // ); } // void Free() override { Cleanup(10); } // bool GetConditions( X121XATRConditions &conditions, // int barIndex = 0, // int loopback = 5 // ) { // bool result = true; // if (loopback < 5) { loopback = 5; } // conditions.Clean(); // conditions.symbol = mSymbol; conditions.period = mPeriod; conditions.time = TimeCurrent(); // int zIndex = barIndex; int cIndex = zIndex + 1; int pIndex = cIndex + 1; int ppIndex = pIndex + 1; // XOHCL zBar; result = zBar.Init( mSymbol, mPeriod, zIndex // ); if (!result) { return result; } // XOHCL cBar; result = cBar.Init( mSymbol, mPeriod, cIndex // ); if (!result) { return result; } // XOHCL pBar; result = pBar.Init( mSymbol, mPeriod, pIndex // ); if (!result) { return result; } // // Buffers ... // CopyRSI( zIndex, loopback, conditions.rsiBuffer // ); // CopyATR( zIndex, loopback, conditions.atrBuffer // ); // CopyATRUpper( zIndex, loopback, conditions.atrUpperBuffer // ); // CopyATRLower( zIndex, loopback, conditions.atrLowerBuffer // ); // CopySMATRUpper( zIndex, loopback, conditions.atrUpperSMBuffer // ); // CopySMATRLower( zIndex, loopback, conditions.atrLowerSMBuffer // ); // CopyPriceChange( zIndex, loopback, conditions.priceChangeBuffer // ); // CopySMPriceChange( zIndex, loopback, conditions.priceChangeSMBuffer // ); // CopyRsiChange( zIndex, loopback, conditions.rsiChangeBuffer // ); // CopySMRsiChange( zIndex, loopback, conditions.rsiChangeSMBuffer // ); // // Conditions ... // int zIDX = 0; int cIDX = zIDX + 1; int pIDX = cIDX + 1; int pPIDX = pIDX + 1; // double cRSI = conditions.rsiBuffer[cIDX]; double pRSI = conditions.rsiBuffer[pIDX]; double pPRSI = conditions.rsiBuffer[pPIDX]; // // RSI ... // bool isRsiInRange = cRSI > mInputs.rsiOverSoldLevel && cRSI < mInputs.rsiOverBoughtLevel; bool isRsiInRangeP = pRSI > mInputs.rsiOverSoldLevel && pRSI < mInputs.rsiOverBoughtLevel; // bool isRsiOverSold = cRSI < mInputs.rsiOverSoldLevel; bool isRsiOverSoldP = pRSI < mInputs.rsiOverSoldLevel; bool isRsiCrossedOverOverSold = isRsiOverSold && !isRsiOverSoldP; bool isRsiCrossedUnderOverSold = isRsiOverSoldP && !isRsiOverSold; // bool isRsiOverBought = cRSI > mInputs.rsiOverBoughtLevel; bool isRsiOverBoughtP = pRSI > mInputs.rsiOverBoughtLevel; bool isRsiCrossedOverOverBought = isRsiOverBought && !isRsiOverBoughtP; bool isRsiCrossedUnderOverBought = isRsiOverBoughtP && !isRsiOverBought; // // Other ... // double rsiChange = conditions.rsiChangeBuffer[cIDX]; double rsiChangeP = conditions.rsiChangeBuffer[pIDX]; // double rsiChangeSM = conditions.rsiChangeSMBuffer[cIDX]; double rsiChangeSMP = conditions.rsiChangeSMBuffer[pIDX]; // double priceChange = conditions.priceChangeBuffer[cIDX]; double priceChangeP = conditions.priceChangeBuffer[pIDX]; // double priceChangeSM = conditions.priceChangeSMBuffer[cIDX]; double priceChangeSMP = conditions.priceChangeSMBuffer[pIDX]; // // // // bool isRsiSMOverPriceChange = rsiChangeSM > priceChangeSM; bool isRsiSMOverPriceChangeP = rsiChangeSMP > priceChangeSMP; bool isRsiSMCrossedOverPriceChange = isRsiSMOverPriceChange && !isRsiSMOverPriceChangeP; // bool isRsiSMUnderPriceChange = rsiChangeSM < priceChangeSM; bool isRsiSMUnderPriceChangeP = rsiChangeSMP < priceChangeSMP; bool isRsiSMCrossedUnderPriceChange = isRsiSMUnderPriceChange && !isRsiSMUnderPriceChangeP; // bool isPriceChangeSMOverRsi = priceChangeSM > rsiChangeSM; bool isPriceChangeSMOverRsiP = priceChangeSMP > rsiChangeSMP; bool isPriceChangeSMCrossedOverRsi = isPriceChangeSMOverRsi && !isPriceChangeSMOverRsiP; // bool isPriceChangeSMUnderRsi = priceChangeSM < rsiChangeSM; bool isPriceChangeSMUnderRsiP = priceChangeSMP < rsiChangeSMP; bool isPriceChangeSMCrossedUnderRsi = isPriceChangeSMUnderRsi && !isPriceChangeSMUnderRsiP; // bool isRsiOverRsiSM = rsiChange > rsiChangeSM; bool isRsiOverRsiSMP = rsiChangeP > rsiChangeSMP; bool isRsiCrossedOverRsiSM = isRsiOverRsiSM && !isRsiOverRsiSMP; // bool isRsiUnderRsiSM = rsiChange < rsiChangeSM; bool isRsiUnderRsiSMP = rsiChangeP < rsiChangeSMP; bool isRsiCrossedUnderRsiSM = isRsiUnderRsiSM && !isRsiUnderRsiSMP; // bool isPriceChangeOverPriceChangeSM = priceChange > priceChangeSM; bool isPriceChangeOverPriceChangeSMP = priceChangeP > priceChangeSMP; bool isPriceChangeCrossedOverPriceChangeSM = isPriceChangeOverPriceChangeSM && !isPriceChangeOverPriceChangeSMP; // bool isPriceChangeUnderPriceChangeSM = priceChange < priceChangeSM; bool isPriceChangeUnderPriceChangeSMP = priceChangeP < priceChangeSMP; bool isPriceChangeCrossedUnderPriceChangeSM = isPriceChangeUnderPriceChangeSM && !isPriceChangeUnderPriceChangeSMP; // // // // conditions.isRsiInRange = isRsiInRange; conditions.isRsiOverSold = isRsiOverSold; conditions.isRsiOverRsiSM = isRsiOverRsiSM; conditions.isRsiOverBought = isRsiOverBought; conditions.isRsiUnderRsiSM = isRsiUnderRsiSM; conditions.isRsiCrossedOverRsiSM = isRsiCrossedOverRsiSM; conditions.isRsiCrossedUnderRsiSM = isRsiCrossedUnderRsiSM; conditions.isPriceChangeSMOverRsi = isPriceChangeSMOverRsi; conditions.isRsiSMOverPriceChange = isRsiSMOverPriceChange; conditions.isPriceChangeSMUnderRsi = isPriceChangeSMUnderRsi; conditions.isRsiSMUnderPriceChange = isRsiSMUnderPriceChange; conditions.isRsiCrossedOverOverSold = isRsiCrossedOverOverSold; conditions.isRsiCrossedUnderOverSold = isRsiCrossedUnderOverSold; conditions.isRsiCrossedOverOverBought = isRsiCrossedOverOverBought; conditions.isRsiCrossedUnderOverBought = isRsiCrossedUnderOverBought; conditions.isPriceChangeSMCrossedOverRsi = isPriceChangeSMCrossedOverRsi; conditions.isRsiSMCrossedOverPriceChange = isRsiSMCrossedOverPriceChange; conditions.isRsiSMCrossedUnderPriceChange = isRsiSMCrossedUnderPriceChange; conditions.isPriceChangeSMCrossedUnderRsi = isPriceChangeSMCrossedUnderRsi; conditions.isPriceChangeOverPriceChangeSM = isPriceChangeOverPriceChangeSM; conditions.isPriceChangeUnderPriceChangeSM = isPriceChangeUnderPriceChangeSM; conditions.isPriceChangeCrossedOverPriceChangeSM = isPriceChangeCrossedOverPriceChangeSM; conditions.isPriceChangeCrossedUnderPriceChangeSM = isPriceChangeCrossedUnderPriceChangeSM; // Cleanup(); // zBar.Clean(); cBar.Clean(); pBar.Clean(); // return result; } // // Protected ... protected: // // Private ... private: // // Props ... X121XATRInputs mInputs; // Inputs ... // // Buffers ... double rsiBuffer[]; double atrBuffer[]; double atrUpperBuffer[]; double atrLowerBuffer[]; double atrUpperSMBuffer[]; double atrLowerSMBuffer[]; double rsiChangeBuffer[]; double rsiChangeSMBuffer[]; double priceChangeBuffer[]; double priceChangeSMBuffer[]; // void Calculate( int barIndex = 0, int maxRequiredBars = 100 // ) { // // Buffers ... if (barIndex < 0) { barIndex = 0; } // // RSI ... CopyBuffer( mHandler, X121_RSI_LINE, barIndex, maxRequiredBars, rsiBuffer // ); // // ATR ... CopyBuffer( mHandler, X121_ATR_LINE, barIndex, maxRequiredBars, atrBuffer // ); // // ATR Band ... // // Upper ... CopyBuffer( mHandler, X121_ATR_UPPER_LINE, barIndex, maxRequiredBars, atrUpperBuffer // ); // // Lower ... CopyBuffer( mHandler, X121_ATR_LOWER_LINE, barIndex, maxRequiredBars, atrLowerBuffer // ); // // SM Upper ... CopyBuffer( mHandler, X121_ATR_SM_UPPER_LINE, barIndex, maxRequiredBars, atrUpperSMBuffer // ); // // Lower ... CopyBuffer( mHandler, X121_ATR_SM_LOWER_LINE, barIndex, maxRequiredBars, atrLowerSMBuffer // ); // // PRICE Change ... // CopyBuffer( mHandler, X121_PRICE_CHANGE_LINE, barIndex, maxRequiredBars, priceChangeBuffer // ); // CopyBuffer( mHandler, X121_PRICE_CHANGE_SM_LINE, barIndex, maxRequiredBars, priceChangeSMBuffer // ); // // RSI Change ... // CopyBuffer( mHandler, X121_RSI_CHANGE_LINE, barIndex, maxRequiredBars, rsiChangeBuffer // ); // CopyBuffer( mHandler, X121_RSI_CHANGE_SM_LINE, barIndex, maxRequiredBars, rsiChangeSMBuffer // ); // } // void Cleanup( int maxAllowed = 100 // ) { // CleanupArray( rsiBuffer, maxAllowed // ); // CleanupArray( atrBuffer, maxAllowed // ); // CleanupArray( atrUpperBuffer, maxAllowed // ); // CleanupArray( atrLowerBuffer, maxAllowed // ); // CleanupArray( atrUpperSMBuffer, maxAllowed // ); // CleanupArray( atrLowerSMBuffer, maxAllowed // ); // CleanupArray( rsiChangeBuffer, maxAllowed // ); // CleanupArray( rsiChangeSMBuffer, maxAllowed // ); // CleanupArray( priceChangeBuffer, maxAllowed // ); // CleanupArray( priceChangeSMBuffer, maxAllowed // ); // } // }; // // Tools ...