//+--------------------------------------------------------------------+ //| 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 CustomDonchianChannel : public Indicator { public: CustomDonchianChannel(SlotTypes slotType) { SlotType=slotType; IndicatorName="Custom Donchian Channel"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CustomDonchianChannel::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters int iPeriod = (int)NumParam[0].Value; int iShift = (int)NumParam[1].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; // Calculation double adUpBand[]; ArrayResize(adUpBand, Data.Bars);ArrayInitialize(adUpBand,0); double adDnBand[]; ArrayResize(adDnBand, Data.Bars);ArrayInitialize(adDnBand,0); int iFirstBar=iPeriod+iShift+iPrvs+2; for(int iBar=iPeriod+iPrvs+2; iBar dMax) dMax = Data.High[iBar - i]; if(Data.Low[iBar - i] < dMin) dMin = Data.Low[iBar - i]; } adUpBand[iBar + iShift] = dMax; adDnBand[iBar + iShift] = dMin; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Upper Band"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,adUpBand); ArrayResize(Component[1].Value,Data.Bars); Component[1].CompName = "Lower Band"; Component[1].DataType = IndComponentType_IndicatorValue; Component[1].FirstBar = iFirstBar; ArrayCopy(Component[1].Value,adDnBand); ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; ArrayResize(Component[3].Value,Data.Bars); Component[3].FirstBar=iFirstBar; // Sets the Component's type. if(SlotType==SlotTypes_Open) { Component[2].DataType = IndComponentType_OpenLongPrice; Component[2].CompName = "Long position entry price"; Component[3].DataType = IndComponentType_OpenShortPrice; Component[3].CompName = "Short position entry price"; } else if(SlotType==SlotTypes_OpenFilter) { Component[2].DataType = IndComponentType_AllowOpenLong; Component[2].CompName = "Is long entry allowed"; Component[3].DataType = IndComponentType_AllowOpenShort; Component[3].CompName = "Is short entry allowed"; } else if(SlotType==SlotTypes_Close) { Component[2].DataType = IndComponentType_CloseLongPrice; Component[2].CompName = "Long position closing price"; Component[3].DataType = IndComponentType_CloseShortPrice; Component[3].CompName = "Short position closing price"; } else if(SlotType==SlotTypes_CloseFilter) { Component[2].DataType = IndComponentType_ForceCloseLong; Component[2].CompName = "Close out long position"; Component[3].DataType = IndComponentType_ForceCloseShort; Component[3].CompName = "Close out short position"; } if(SlotType==SlotTypes_Open || SlotType==SlotTypes_Close) { if(iPeriod>1) { for(int iBar=iFirstBar; iBarData.High[iBar-1] && dValueUp dOpen) || // The Data.Open price jumps below the indicator (Data.Close[iBar - 1] < dValueUp && dValueUp < dOpen) || // The Data.Open price is in a positive gap (Data.Close[iBar - 1] > dValueUp && dValueUp > dOpen)) // The Data.Open price is in a negative gap dTempValUp=dOpen; // The entry/exit level is moved to Data.Open price // Lower band double dValueDown = adDnBand[iBar - iPrvs]; // Current value double dValueDown1 = adDnBand[iBar - iPrvs - 1]; // Previous value double dTempValDown = dValueDown; if((dValueDown1>Data.High[iBar-1] && dValueDown dOpen) || // The Data.Open price jumps below the indicator (Data.Close[iBar - 1] < dValueDown && dValueDown < dOpen) || // The Data.Open price is in a positive gap (Data.Close[iBar - 1] > dValueDown && dValueDown > dOpen)) // The Data.Open price is in a negative gap dTempValDown=dOpen; // The entry/exit level is moved to Data.Open price if(ListParam[0].Text=="Enter long at the Upper Band" || ListParam[0].Text=="Exit long at the Upper Band") { Component[2].Value[iBar] = dTempValUp; Component[3].Value[iBar] = dTempValDown; } else { Component[2].Value[iBar] = dTempValDown; Component[3].Value[iBar] = dTempValUp; } } } else { for(int iBar=2; iBar= adUpBand[iBar - iPrvs] ? 1 : 0; Component[3].Value[iBar] = Data.Low[iBar - 1] <= adDnBand[iBar - iPrvs] ? 1 : 0; } } else if(ListParam[0].Text=="The bar touches the Lower Band") { for(int iBar=iFirstBar+iPrvs; iBar= adUpBand[iBar - iPrvs] ? 1 : 0; } } } } //+------------------------------------------------------------------+