//============================================================== // 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.Store { public class FiniteVolumeElement : Indicator { public FiniteVolumeElement() { IndicatorName = "Finite Volume Element"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; SeparatedChart = true; IndicatorAuthor = "Denny Imanuel"; IndicatorVersion = "2.1"; IndicatorDescription = "A custom indicator for FSB and FST."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "The FVE Signal rises", "The FVE Signal falls", "The FVE Signal is higher than the Level line", "The FVE Signal is lower than the Level line", "The FVE Signal crosses the Level line upward", "The FVE Signal crosses the Level line downward", "The FVE Signal changes its direction upward", "The FVE Signal changes its direction downward" }; 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 = "Logic of application of the indicator."; IndParam.ListParam[1].Caption = "Chart's Signal"; IndParam.ListParam[1].ItemList = new string[] { "Original FVE", "Moving Average of FVE", "Regression Slope of FVE", }; 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 method used for smoothing the both Moving Averages."; IndParam.ListParam[2].Caption = "Smoothing Method"; IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(MAMethod)); IndParam.ListParam[2].Index = (int)MAMethod.Simple; IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index]; IndParam.ListParam[2].Enabled = true; IndParam.ListParam[2].ToolTip = "The method used for smoothing the both Moving Averages."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "FVE Samples"; IndParam.NumParam[0].Value = 22; IndParam.NumParam[0].Min = 1; IndParam.NumParam[0].Max = 200; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The period of Finite Volume Element"; IndParam.NumParam[1].Caption = "Smoothing/Regression Period"; IndParam.NumParam[1].Value = 10; IndParam.NumParam[1].Min = 1; IndParam.NumParam[1].Max = 200; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "The period of smoothing or regression"; IndParam.NumParam[2].Caption = "CutOff"; IndParam.NumParam[2].Value = 0.003; IndParam.NumParam[2].Min = 0; IndParam.NumParam[2].Max = 1; IndParam.NumParam[2].Point = 4; IndParam.NumParam[2].Enabled = true; IndParam.NumParam[2].ToolTip = "A cutoff level (for the appropriate logic)."; IndParam.NumParam[3].Caption = "Level"; IndParam.NumParam[3].Value = 0; IndParam.NumParam[3].Min = -100; IndParam.NumParam[3].Max = 100; IndParam.NumParam[3].Point = 4; IndParam.NumParam[3].Enabled = true; IndParam.NumParam[3].ToolTip = "A critical level (for the appropriate logic)."; // 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 MAMethod maMethod = (MAMethod )IndParam.ListParam[2].Index; int iSample = (int)IndParam.NumParam[0].Value; int iLength = (int)IndParam.NumParam[1].Value; double dCutOff = IndParam.NumParam[2].Value; double dLevel = IndParam.NumParam[3].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; double[] adTP = Price(BasePrice.Median); double[] adFVE = new double[Bars]; double[] adFVESig = new double[Bars]; double[] adVolPM = new double[Bars]; double dMF; double dFVEfactor; double dFVESum; double dVOLAvg; int iFirstBar = Math.Max(iSample, iLength) + 2; for (int iBar=iFirstBar; iBardCutOff*Close[iBar]) dFVEfactor = 1; else if (dMF<-dCutOff*Close[iBar]) dFVEfactor = -1; else dFVEfactor = 0; adVolPM[iBar] = Volume[iBar] * dFVEfactor; dFVESum = 0; dVOLAvg=0; for (int iBack=0; iBack