//+--------------------------------------------------------------------+ //| 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.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class Keltnerv2 : public Indicator { public: Keltnerv2(SlotTypes slotType) { SlotType=slotType; IndicatorName="Keltner v2"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Keltnerv2::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters MAMethod maMethod=(MAMethod) ListParam[1].Index; BasePrice basePrice=(BasePrice) ListParam[2].Index; int nMA=(int) NumParam[0].Value; int atrPeriod=(int) NumParam[1].Value; double atrMultiplier= NumParam[3].Value; int previous=CheckParam[0].Checked ? 1 : 0; // Calculation double price[]; Price(basePrice,price); double adMA[]; MovingAverage(nMA,0,maMethod,price,adMA); double adAtr[]; ArrayResize(adAtr,Data.Bars); ArrayInitialize(adAtr,0); double adUpBand[]; ArrayResize(adUpBand,Data.Bars); ArrayInitialize(adUpBand,0); double adDnBand[]; ArrayResize(adDnBand,Data.Bars); ArrayInitialize(adDnBand,0); int firstBar=MathMax(nMA,atrPeriod)+previous+2; for(int iBar=2; iBar1) { for(int iBar=firstBar; iBarData.High[iBar-1] && dValueUpdOpen) || // The Data.Open price jumps below the indicator (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-previous]; // Current value double dValueDown1=adDnBand[iBar-previous-1]; // Previous value double dTempValDown=dValueDown; if((dValueDown1>Data.High[iBar-1] && dValueDowndOpen) || // The Data.Open price jumps below the indicator (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 Upper Band" || ListParam[0].Text=="Exit long at Upper Band") { Component[3].Value[iBar] = dTempValUp; Component[4].Value[iBar] = dTempValDown; } else { Component[3].Value[iBar] = dTempValDown; Component[4].Value[iBar] = dTempValUp; } } } else { for(int iBar=2; iBar