//+--------------------------------------------------------------------+ //| 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 CandleCode : public Indicator { public: CandleCode(SlotTypes slotType) { SlotType=slotType; IndicatorName="CandleCode"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CandleCode::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters //BasePrice basePrice = (BasePrice)ListParam[2].Index; int BBlength=(int) NumParam[0].Value; int Average =(int) NumParam[3].Value; double Deviations=NumParam[2].Value; double level=NumParam[1].Value; MAMethod maMethod=(MAMethod) ListParam[3].Index; int prvs=CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar=BBlength+2; double Body[]; ArrayResize(Body,Data.Bars); ArrayInitialize(Body,0); double UpperShadow[]; ArrayResize(UpperShadow,Data.Bars); ArrayInitialize(UpperShadow,0); double LowerShadow[]; ArrayResize(LowerShadow,Data.Bars); ArrayInitialize(LowerShadow,0); double adCandleCode[]; ArrayResize(adCandleCode,Data.Bars); ArrayInitialize(adCandleCode,0); double CandleCodeAverage[]; ArrayResize(CandleCodeAverage,Data.Bars); ArrayInitialize(CandleCodeAverage,0); double BodyHi = 0; double BodyLo = 0; double ThBot_Body = 0; double ThTop_Body = 0; double ThBot_Ushd = 0; double ThTop_Ushd = 0; double ThBot_Lshd = 0; double ThTop_Lshd = 0; double ColorCode= 0; double BodyCode = 0; double UshdCode = 0; double LshdCode = 0; for(int bar=firstBar; bar=Data.Open[bar]) { ColorCode= 64; BodyCode = 48; if(Body[bar] < ThTop_Body) BodyCode = 32; if(Body[bar] < ThBot_Body) BodyCode = 16; if(Body[bar]==0) BodyCode=0; } else { ColorCode= 0; BodyCode = 0; if(Body[bar] < ThTop_Body) BodyCode = 16; if(Body[bar] < ThBot_Body) BodyCode = 32; if(Body[bar]==0) BodyCode=48; } UshdCode=12; if(UpperShadow[bar] < ThTop_Ushd) UshdCode = 8; if(UpperShadow[bar] < ThBot_Ushd) UshdCode = 4; if(UpperShadow[bar]==0) UshdCode=0; LshdCode=0; if(LowerShadow[bar] < ThTop_Lshd) LshdCode = 1; if(LowerShadow[bar] < ThBot_Lshd) LshdCode = 2; if(LowerShadow[bar]==0) LshdCode=3; adCandleCode[bar]=ColorCode+BodyCode+UshdCode+LshdCode; } MovingAverage(Average,0,maMethod,adCandleCode,CandleCodeAverage); // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "CandleCodeAverage"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = firstBar; ArrayCopy(Component[0].Value,CandleCodeAverage); ArrayResize(Component[1].Value,Data.Bars); Component[1].FirstBar=firstBar; ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=firstBar; // 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=="rises") indLogic=IndicatorLogic_The_indicator_rises; else if(ListParam[0].Text=="falls") indLogic=IndicatorLogic_The_indicator_falls; else if(ListParam[0].Text=="is higher than the level line") indLogic=IndicatorLogic_The_indicator_is_higher_than_the_level_line; else if(ListParam[0].Text=="is lower than the level line") indLogic=IndicatorLogic_The_indicator_is_lower_than_the_level_line; else if(ListParam[0].Text=="crosses the level line upward") indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_upward; else if(ListParam[0].Text=="crosses the level line downward") indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_downward; else if(ListParam[0].Text=="changes its direction upward") indLogic=IndicatorLogic_The_indicator_changes_its_direction_upward; else if(ListParam[0].Text=="changes its direction downward") indLogic=IndicatorLogic_The_indicator_changes_its_direction_downward; OscillatorLogic(firstBar,prvs,CandleCodeAverage,level,level,Component[1],Component[2],indLogic); } //+------------------------------------------------------------------+