PriceVolumeTrend by ahmedalhoseny
48011 downloads / 4281 views / Created: 13.12.2013 Average Rating: 5
Indicator Description
Price and Volume Trend (PVT) is a variation of On Balance Volume, used to determine the strength of trends and warn of reversals.
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.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 ? "*" : "");
}
}
}
//+--------------------------------------------------------------------+ //| 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 <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class PriceVolumeTrend : public Indicator { public: PriceVolumeTrend(SlotTypes slotType) { SlotType=slotType; IndicatorName="Price Volume Trend"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PriceVolumeTrend::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters int iPrvs=CheckParam[0].Checked ? 1 : 0; const int firstBar=3; double adPVT[]; ArrayResize(adPVT,Data.Bars); ArrayInitialize(adPVT, 0); for(int iBar=1; iBar<Data.Bars; iBar++) { double PcChange=(Data.Close[iBar]-Data.Close[iBar-1])/Data.Close[iBar-1]; adPVT[iBar]=adPVT[iBar-1]+PcChange*Data.Volume[iBar]/1000; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Price Volume Trend"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = firstBar; ArrayCopy(Component[0].Value,adPVT); 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=="Price Volume Trend rises") { indLogic=IndicatorLogic_The_indicator_rises; } else if(ListParam[0].Text=="Price Volume Trend falls") { indLogic=IndicatorLogic_The_indicator_falls; } else if(ListParam[0].Text=="Price Volume Trend changes its direction upward") { indLogic=IndicatorLogic_The_indicator_changes_its_direction_upward; } else if(ListParam[0].Text=="Price Volume Trend changes its direction downward") { indLogic=IndicatorLogic_The_indicator_changes_its_direction_downward; } OscillatorLogic(firstBar,iPrvs,adPVT,0,0,Component[1],Component[2],indLogic); } //+------------------------------------------------------------------+
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.;
Copyright © 2006 - 2024, Forex Software Ltd.;