//+--------------------------------------------------------------------+ //| 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 AmplifiedWilliamsPercentRange : public Indicator { public: AmplifiedWilliamsPercentRange(SlotTypes slotType) { SlotType=slotType; IndicatorName="Amplified William's Percent Range"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void AmplifiedWilliamsPercentRange::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); MAMethod maMethod=(MAMethod)ListParam[1].Index; int iPeriod = (int)NumParam[0].Value; int iSmoothing = (int)NumParam[1].Value; int dLevel = (int)NumParam[2].Value; int iAmp = (int)NumParam[3].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar=iPeriod+iSmoothing+iPrvs+2; double adR[]; ArrayResize(adR,Data.Bars); ArrayInitialize(adR,0); double adAmpR[]; ArrayResize(adAmpR,Data.Bars); ArrayInitialize(adAmpR,0); double dMin; double dMax; for(int iBar=iPeriod; iBar dMax) dMax = Data.High[iBar - index]; if(Data.Low [iBar - index] < dMin) dMin = Data.Low [iBar - index]; } adR[iBar]=2 *((dMax-Data.Close[iBar])/(dMax-dMin))-1; adAmpR[iBar]=-50 *((MathExp(iAmp*adR[iBar])-1)/(MathExp(iAmp*adR[iBar])+1))-50; } double adRSmoothed[]; MovingAverage(iSmoothing,0,maMethod,adAmpR,adRSmoothed); // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "%R"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,adRSmoothed); ArrayResize(Component[1].Value,Data.Bars); Component[1].FirstBar=iFirstBar; ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; // 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 %R rises") { indLogic=IndicatorLogic_The_indicator_rises; } else if(ListParam[0].Text=="The %R falls") { indLogic=IndicatorLogic_The_indicator_falls; } else if(ListParam[0].Text=="The %R is higher than the Level line") { indLogic=IndicatorLogic_The_indicator_is_higher_than_the_level_line; } else if(ListParam[0].Text=="The %R is lower than the Level line") { indLogic=IndicatorLogic_The_indicator_is_lower_than_the_level_line; } else if(ListParam[0].Text=="The %R crosses the Level line upward") { indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_upward; } else if(ListParam[0].Text=="The %R crosses the Level line downward") { indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_downward; } else if(ListParam[0].Text=="The %R changes its direction upward") { indLogic=IndicatorLogic_The_indicator_changes_its_direction_upward; } else if(ListParam[0].Text=="The %R changes its direction downward") { indLogic=IndicatorLogic_The_indicator_changes_its_direction_downward; } OscillatorLogic(iFirstBar,iPrvs,adRSmoothed,dLevel,-100-dLevel,Component[1],Component[2],indLogic); } //+------------------------------------------------------------------+