//+--------------------------------------------------------------------+ //| Copyright: (C) 2016 Forex Software Ltd. | //| Website: http://forexsb.com/ | //| Support: http://forexsb.com/forum/ | //| License: Proprietary under the following circumstances: | //| | //| This code is a part of Forex Strategy Builder. It is free for | //| use as an integral part of Forex Strategy Builder. | //| One can modify it in order to improve the code or to fit it for | //| personal use. This code or any part of it cannot be used in | //| other applications without a permission. | //| The contact information cannot be changed. | //| | //| NO LIABILITY FOR CONSEQUENTIAL DAMAGES | //| | //| In no event shall the author be liable for any damages whatsoever | //| (including, without limitation, incidental, direct, indirect and | //| consequential damages, damages for loss of business profits, | //| business interruption, loss of business information, or other | //| pecuniary loss) arising out of the use or inability to use this | //| product, even if advised of the possibility of such damages. | //+--------------------------------------------------------------------+ #property copyright "Copyright (C) 2016 Forex Software Ltd." #property link "http://forexsb.com" #property version "2.1" #property strict #include #include #include //## Requires RSI.mqh class QQE : public Indicator { public: QQE(SlotTypes slotType) { SlotType=slotType; IndicatorName="QQE"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void QQE::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters MAMethod maMethod = (MAMethod ) ListParam[1].Index; MAMethod maSignalMAMethod = (MAMethod ) ListParam[2].Index; BasePrice basePrice = (BasePrice) ListParam[3].Index; int iPeriod1 = (int) NumParam[0].Value; int SF = (int) NumParam[1].Value; double dLevel = NumParam[2].Value; int previous=CheckParam[0].Checked ? 1 : 0; // Calculation int Wilders_Period = iPeriod1 * 2 - 1; int iFirstBar=iPeriod1 + SF + 1 + Wilders_Period + Wilders_Period + 2; double TrLevelSlow[]; ArrayResize(TrLevelSlow,Data.Bars); ArrayInitialize(TrLevelSlow,0); double AtrRsi[]; ArrayResize(AtrRsi,Data.Bars); ArrayInitialize(AtrRsi,0); double MaAtrRsi[]; double MaMaAtrRsi[]; double dar = 0; double tr = 0; double dv = 0; double rsi12 = 0; double rsi01 = 0; // ---------------------------------------------------- RSI *rsi1=new RSI(SlotType); rsi1.ListParam[1].Index = ListParam[1].Index; rsi1.ListParam[2].Index = ListParam[3].Index; rsi1.NumParam[0].Value=NumParam[0].Value; rsi1.CheckParam[0].Checked=CheckParam[0].Checked; rsi1.Calculate(dataSet); double indicator1[]; ArrayResize(indicator1,Data.Bars); ArrayCopy(indicator1,rsi1.Component[0].Value); delete rsi1; double RsiMa[]; MovingAverage(SF,0,maSignalMAMethod,indicator1,RsiMa); // ----------------------------------------------------- for (int iBar = iFirstBar; iBar < Data.Bars; iBar++) { AtrRsi[iBar] = MathAbs(RsiMa[iBar - 1] - RsiMa[iBar]); //shift +1 } MovingAverage(Wilders_Period, 0, maSignalMAMethod, AtrRsi,MaAtrRsi); //shift +wilders period MovingAverage(Wilders_Period, 0, maSignalMAMethod, MaAtrRsi,MaMaAtrRsi); for (int iBar = iFirstBar; iBar < Data.Bars; iBar++) { tr=TrLevelSlow[iBar-1]; rsi12 = RsiMa[iBar-1]; rsi01 = RsiMa[iBar]; dar = MaMaAtrRsi[iBar] * 4.236; dv=tr; if (rsi01 < tr) { tr=rsi01 + dar; if (rsi12 < dv && tr > dv) { tr=dv; } } else if (rsi01 > tr) { tr = rsi01 - dar; if (rsi12 > dv && tr < dv) { tr=dv; } } TrLevelSlow[iBar]=tr; rsi12=rsi01; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Fast line"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,RsiMa); ArrayResize(Component[1].Value,Data.Bars); Component[1].FirstBar=iFirstBar; ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; ArrayResize(Component[3].Value,Data.Bars); Component[3].CompName = "Slow line"; Component[3].DataType = IndComponentType_IndicatorValue; Component[3].FirstBar = iFirstBar; ArrayCopy(Component[3].Value,TrLevelSlow); // Sets the Component's type if(SlotType==SlotTypes_OpenFilter) { Component[1].DataType = IndComponentType_AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType_AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if(SlotType==SlotTypes_CloseFilter) { Component[1].DataType = IndComponentType_ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType_ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic IndicatorLogic indLogic=IndicatorLogic_It_does_not_act_as_a_filter; if(ListParam[0].Text=="The fast line rises") indLogic=IndicatorLogic_The_indicator_rises; else if(ListParam[0].Text=="The fast line falls") indLogic=IndicatorLogic_The_indicator_falls; else if(ListParam[0].Text=="The fast line is higher than the level line") indLogic=IndicatorLogic_The_indicator_is_higher_than_the_level_line; else if(ListParam[0].Text=="The fast line is lower than the level line") indLogic=IndicatorLogic_The_indicator_is_lower_than_the_level_line; else if(ListParam[0].Text=="The fast line crosses the level line upward") indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_upward; else if(ListParam[0].Text=="The fast line crosses the level line downward") indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_downward; else if(ListParam[0].Text=="The fast line changes its direction upward") indLogic=IndicatorLogic_The_indicator_changes_its_direction_upward; else if(ListParam[0].Text=="The fast line changes its direction downward") indLogic=IndicatorLogic_The_indicator_changes_its_direction_downward; else if(ListParam[0].Text=="The fast line crosses the slow line upward") IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, previous, RsiMa, TrLevelSlow, Component[1], Component[2]); else if(ListParam[0].Text=="The fast line crosses the slow line downward") IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, previous, RsiMa, TrLevelSlow, Component[1], Component[2]); else if(ListParam[0].Text=="The fast line is higher than the slow line") IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, previous, RsiMa, TrLevelSlow, Component[1], Component[2]); else if(ListParam[0].Text=="The fast line is lower than the slow line") IndicatorIsLowerThanAnotherIndicatorLogic(iFirstBar, previous, RsiMa, TrLevelSlow, Component[1], Component[2]); OscillatorLogic(iFirstBar,previous,RsiMa, dLevel, 100 - dLevel,Component[1],Component[2],indLogic); } //+------------------------------------------------------------------+