//+--------------------------------------------------------------------+ //| Copyright: (C) 2014, Miroslav Popov - All rights reserved! | //| 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 | //| another applications without a permission. 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 2014, Miroslav Popov" #property link "http://forexsb.com" #property version "1.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class RecentSwingHighLow : public Indicator { public: RecentSwingHighLow(SlotTypes slotType) { SlotType=slotType; IndicatorName="Recent Swing High Low"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void RecentSwingHighLow::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); double dShift = NumParam[0].Value * Data.Point; int iFirstBar = 7; // Calculation double adHighPrice[]; ArrayResize(adHighPrice,Data.Bars); ArrayInitialize(adHighPrice,0); double adLowPrice[]; ArrayResize(adLowPrice,Data.Bars); ArrayInitialize(adLowPrice,0); for(int iBar=iFirstBar; iBar= Data.High[iBar - 4] && Data.High[iBar - 3]> Data.High[iBar - 5] && // Check 2 candles to the left Data.High[iBar - 3] >= Data.High[iBar - 2] && Data.High[iBar - 3] > Data.High[iBar - 1]) // Check 2 candles to the right { adHighPrice[iBar]=Data.High[iBar-3]; } else { adHighPrice[iBar]=adHighPrice[iBar-1]; } // Check if current low is a swing low if(Data.Low[iBar - 3]<= Data.Low[iBar - 4] && Data.Low[iBar - 3]< Data.Low[iBar - 5] && // Check 2 candles to the left Data.Low[iBar - 3] <= Data.Low[iBar - 2] && Data.Low[iBar - 3] < Data.Low[iBar - 1]) // Check 2 candles to the right { adLowPrice[iBar]=Data.Low[iBar-3]; } else { adLowPrice[iBar]=adLowPrice[iBar-1]; } } // Shifting the price double adUpperBand[]; ArrayResize(adUpperBand, Data.Bars); ArrayInitialize(adUpperBand,0); double adLowerBand[]; ArrayResize(adLowerBand, Data.Bars); ArrayInitialize(adLowerBand,0); for(int iBar=1; iBar