Candle Color by Popov

49091 downloads / 4274 views / Created: 06.06.2015
 Average Rating: 5

Indicator Description

This indicator detects Bullish and Bearish candles. It takes two parameters: minimum body height and minimum consecutive candles.

Forum topic: Candle Color

Comments

//============================================================== // Forex Strategy Builder // Copyright © Miroslav Popov. All rights reserved. //============================================================== // THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE. //============================================================== using System; using System.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Custom { public class CandleColor : Indicator { public CandleColor() { IndicatorName = "Candle Color"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; IndicatorAuthor = "Miroslav Popov"; IndicatorVersion = "1.1"; IndicatorDescription = "Detects bullish and bearish candles."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new[] { "Bullish Candle formed", "Bearish Candle formed" }; IndParam.ListParam[0].Index = 0; IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index]; IndParam.ListParam[0].Enabled = true; IndParam.ListParam[0].ToolTip = "Gives a signal when a candle is formed."; IndParam.ListParam[1].Caption = "Base price"; IndParam.ListParam[1].ItemList = new[]{"Bar range"}; IndParam.ListParam[1].Index = 0; IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index]; IndParam.ListParam[1].Enabled = true; IndParam.ListParam[1].ToolTip = "The indicator uses the bar range."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Min body height [pips]"; IndParam.NumParam[0].Value = 5; IndParam.NumParam[0].Min = 1; IndParam.NumParam[0].Max = 200; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "Minimum required body height in pips."; IndParam.NumParam[1].Caption = "Consecutive candles"; IndParam.NumParam[1].Value = 1; IndParam.NumParam[1].Min = 1; IndParam.NumParam[1].Max = 10; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "Gives a signal if there are consecutive candles."; // The CheckBox parameters IndParam.CheckParam[0].Caption = "Use previous bar value"; IndParam.CheckParam[0].Enabled = true; IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var minHeight = (int) IndParam.NumParam[0].Value; var consecutive = (int) IndParam.NumParam[1].Value; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; int firstBar = 2 + consecutive + previous; var whiteCandles = new int[Bars]; var blackCandles = new int[Bars]; var pipVal = dataSet.Properties.Pip*minHeight; for (int b = 1 + previous; b < Bars; b++) { if (Close[b - previous] - Open[b - previous] >= pipVal) whiteCandles[b] = whiteCandles[b - 1] + 1; if (Open[b - previous] - Close[b - previous] >= pipVal) blackCandles[b] = blackCandles[b - 1] + 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].CompName = "Is long entry allowed"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[0].DataType = IndComponentType.ForceCloseLong; Component[0].CompName = "Close out long position"; Component[1].DataType = IndComponentType.ForceCloseShort; Component[1].CompName = "Close out short position"; } if(IndParam.ListParam[0].Text == "Bullish Candle formed") for (int b = firstBar; b < Bars; b++) { Component[0].Value[b] = whiteCandles[b] >= consecutive ? 1 : 0; Component[1].Value[b] = blackCandles[b] >= consecutive ? 1 : 0; } else if(IndParam.ListParam[0].Text == "Bearish Candle formed") for (int b = firstBar; b < Bars; b++) { Component[1].Value[b] = whiteCandles[b] >= consecutive ? 1 : 0; Component[0].Value[b] = blackCandles[b] >= consecutive ? 1 : 0; } } public override void SetDescription() { var consecutive = (int) IndParam.NumParam[1].Value; string white = consecutive == 1 ? "a bullish candle is formed" : consecutive + " bullish candles are formed"; string black = consecutive == 1 ? "a bearish candle is formed" : consecutive + " bearish candles are formed"; switch (IndParam.ListParam[0].Text) { case "Bullish Candle formed": EntryFilterLongDescription = white; EntryFilterShortDescription = black; ExitFilterLongDescription = white; ExitFilterShortDescription = black; break; case "Bearish Candle formed": EntryFilterLongDescription = black; EntryFilterShortDescription = white; ExitFilterLongDescription = black; ExitFilterShortDescription = white; break; } } } }
//+--------------------------------------------------------------------+ //| Copyright: (C) 2014 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) 2014 Forex Software Ltd." #property link "http://forexsb.com" #property version "1.1" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CandleColor : public Indicator { public: CandleColor(SlotTypes slotType) { SlotType=slotType; IndicatorName="Candle Color"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CandleColor::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters int minHeight = (int) NumParam[0].Value; int consecutive = (int) NumParam[1].Value; int previous = CheckParam[0].Checked ? 1 : 0; int firstBar = 2 + consecutive + previous; int whiteCandles[];ArrayResize(whiteCandles,Data.Bars);ArrayInitialize(whiteCandles,0); int blackCandles[];ArrayResize(blackCandles,Data.Bars);ArrayInitialize(blackCandles,0); double pipVal = dataSet.Pip*minHeight; for (int b = 1 + previous; b < dataSet.Bars; b++) { if (Data.Close[b - previous] - Data.Open[b - previous] >= pipVal) whiteCandles[b] = whiteCandles[b - 1] + 1; if (Data.Open[b - previous] - Data.Close[b - previous] >= pipVal) blackCandles[b] = blackCandles[b - 1] + 1; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); ArrayInitialize(Component[0].Value,0); Component[0].FirstBar=firstBar; ArrayResize(Component[1].Value,Data.Bars); ArrayInitialize(Component[1].Value,0); Component[1].FirstBar=firstBar; // Sets the Component's type. if(SlotType==SlotTypes_OpenFilter) { Component[0].DataType = IndComponentType_AllowOpenLong; Component[0].CompName = "Is long entry allowed"; Component[1].DataType = IndComponentType_AllowOpenShort; Component[1].CompName = "Is short entry allowed"; } else if(SlotType==SlotTypes_CloseFilter) { Component[0].DataType = IndComponentType_ForceCloseLong; Component[0].CompName = "Close out long position"; Component[1].DataType = IndComponentType_ForceCloseShort; Component[1].CompName = "Close out short position"; } if(ListParam[0].Text == "Bullish Candle formed") for (int b = firstBar; b < Data.Bars; b++) { Component[0].Value[b] = whiteCandles[b] >= consecutive ? 1 : 0; Component[1].Value[b] = blackCandles[b] >= consecutive ? 1 : 0; } else if(ListParam[0].Text == "Bearish Candle formed") for (int b = firstBar; b < Data.Bars; b++) { Component[1].Value[b] = whiteCandles[b] >= consecutive ? 1 : 0; Component[0].Value[b] = blackCandles[b] >= consecutive ? 1 : 0; } } //+------------------------------------------------------------------+
Risk warning: Forex, spread bets and CFD are leveraged products. They may not be suitable for you as they carry a high degree of risk to your capital and you can lose more than your initial investment. You should ensure you understand all of the risks.
Copyright © 2006 - 2024, Forex Software Ltd.;