Rising Volume by Popov

4026 downloads / 1335 views / Created: 14.12.2015
 Average Rating: 5

Indicator Description

The indicator calculates the average tick volume for the last "n" bars and rises a signal if the previous bar has a volume "m" times higher than the average.

Rising Volume indicator doesn't determine the entry direction. You need an additional indicator for that.

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 ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Custom { public class RisingVolume : Indicator { public RisingVolume() { IndicatorName = "Rising Volume"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; SeparatedChart = false; IndicatorAuthor = "Miroslav Popov"; IndicatorVersion = "1.0"; IndicatorDescription = "Determines rising volume bars."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new[] { "Volume higher than the average" }; 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 = "Logical rule for the indicator."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Volume period"; IndParam.NumParam[0].Value = 10; IndParam.NumParam[0].Min = 1; IndParam.NumParam[0].Max = 200; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The period for calculating the average volume."; IndParam.NumParam[1].Caption = "Volume threshold"; IndParam.NumParam[1].Value = 1.5; IndParam.NumParam[1].Min = 1; IndParam.NumParam[1].Max = 5; IndParam.NumParam[1].Point = 1; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "Average volume threshold."; // 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 int period = (int) IndParam.NumParam[0].Value; double threshold = IndParam.NumParam[1].Value; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + previous + 2; // Average volume double[] average = new double[Bars]; double sum = 0; for (int bar = 0; bar < period; bar++) sum += Volume[bar]; average[period - 1] = sum/period; for (int bar = period; bar < Bars; bar++) average[bar] = average[bar - 1] + (Volume[bar] - Volume[bar - period])/(float)period; // Signal double[] signal = new double[Bars]; for (int bar = firstBar; bar < Bars; bar++) signal[bar] = Volume[bar - previous] >= threshold*average[bar - previous] ? 1 : 0; // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { ChartType = IndChartType.NoChart, Value = signal, FirstBar = firstBar }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, Value = signal, 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"; } } public override void SetDescription() { string text = "there is a volume higher than the average"; EntryFilterLongDescription = text; EntryFilterShortDescription = text; ExitFilterLongDescription = text; ExitFilterShortDescription = text; } } }
//+--------------------------------------------------------------------+ //| Copyright: (C) 2015 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) 2015 Forex Software Ltd." #property link "http://forexsb.com" #property version "1.00" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> class RisingVolume : public Indicator { public: RisingVolume(SlotTypes slotType) { SlotType = slotType; IndicatorName = "Rising Volume"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; void RisingVolume::Calculate(DataSet &dataSet) { Data = GetPointer(dataSet); // Reading the parameters int period = (int) NumParam[0].Value; double threshold = NumParam[1].Value; int previous = CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + previous + 2; // Average volume double average[]; ArrayResize(average, Data.Bars); ArrayInitialize(average, 0); long sum = 0; for (int bar = 0; bar < period; bar++) sum += Data.Volume[bar]; average[period - 1] = (double) (sum/period); for (int bar = period; bar < Data.Bars; bar++) average[bar] = average[bar - 1] + (Data.Volume[bar] - Data.Volume[bar - period])/(float)period; // Signal double signal[]; ArrayResize(signal, Data.Bars); ArrayInitialize(signal, 0); for (int bar = firstBar; bar < Data.Bars; bar++) signal[bar] = Data.Volume[bar - previous] >= threshold*average[bar - previous] ? 1 : 0; // Saving the components ArrayResize(Component[0].Value, Data.Bars); Component[0].FirstBar = firstBar; ArrayCopy(Component[0].Value, signal); ArrayResize(Component[1].Value, Data.Bars); Component[1].FirstBar = firstBar; ArrayCopy(Component[1].Value, signal); // 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"; } }
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 - 2017, Miroslav Popov; Created by Yavor Kirov