//============================================================== // 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.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class PVT : Indicator { public PVT() { IndicatorName = "Price Volume Trend"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; SeparatedChart = true; IndicatorAuthor = "Ahmed Alhoseny"; IndicatorVersion = "2.0"; IndicatorDescription = "Custom Indicator."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new[] { "Price Volume Trend rises", "Price Volume Trend falls", "Price Volume Trend changes its direction upward", "Price Volume Trend 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 Price Volume Trend."; // 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 iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; const int firstBar = 3; var adPVT = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { double PcChange = (Close[iBar] - Close[iBar - 1]) / Close[iBar - 1]; adPVT[iBar] = adPVT[iBar - 1] + PcChange*Volume[iBar]/1000; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Price Volume Trend", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = firstBar, Value = adPVT }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // 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 var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "Price Volume Trend rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "Price Volume Trend falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "Price Volume Trend changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "Price Volume Trend changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(firstBar, iPrvs, adPVT, 0, 0, ref Component[1], ref Component[2], indLogic); } public override void SetDescription() { EntryFilterLongDescription = "the " + ToString() + " "; EntryFilterShortDescription = "the " + ToString() + " "; ExitFilterLongDescription = "the " + ToString() + " "; ExitFilterShortDescription = "the " + ToString() + " "; switch (IndParam.ListParam[0].Text) { case "Price Volume Trend rises": EntryFilterLongDescription += "rises"; EntryFilterShortDescription += "falls"; ExitFilterLongDescription += "rises"; ExitFilterShortDescription += "falls"; break; case "Price Volume Trend falls": EntryFilterLongDescription += "falls"; EntryFilterShortDescription += "rises"; ExitFilterLongDescription += "falls"; ExitFilterShortDescription += "rises"; break; case "Price Volume Trend changes its direction upward": EntryFilterLongDescription += "changes its direction upward"; EntryFilterShortDescription += "changes its direction downward"; ExitFilterLongDescription += "changes its direction upward"; ExitFilterShortDescription += "changes its direction downward"; break; case "Price Volume Trend changes its direction downward": EntryFilterLongDescription += "changes its direction downward"; EntryFilterShortDescription += "changes its direction upward"; ExitFilterLongDescription += "changes its direction downward"; ExitFilterShortDescription += "changes its direction upward"; break; } } public override string ToString() { return IndicatorName + (IndParam.CheckParam[0].Checked ? "*" : ""); } } }