So here I am trying to write the code for a PVT indicator.
The code I have will compile, but when I insert the indicator into a chart, it does not plot anything - just a blank panel.
I think others have also tried to find a PVT indicator, so success in this endeavor will probably benefit, others.
I know enough about programming to be somewhat dangerous.
Any help would be appreciated.
|
Code:
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class PVT : Indicator
{
private Text mytexttool;
private Brush axisColor;
private Gui.Tools.SimpleFont chartFont;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "PVT ";
// Adds a blue line style plot
AddPlot(Brushes.Blue, "PVTtotal");
}
}
protected override void OnBarUpdate()
{
// start PVTcode
double myClose0 = Close[0];
double myClose1 = Close[1];
double percentChg = 0;
double PVTtoday = 0;
double PVTtotal = 0;
// Calculate the Percentage Change in closing price.
// ( Closing Price [today] - Closing Price [yesterday] ) / Closing Price [yesterday]
percentChg = ((myClose0 - myClose1) / myClose1 );
// Multiply the Percentage Change by Volume. This is today PVT.
// Percentage Change * Volume [today]
PVTtoday = (percentChg * Volume[0]);
// Add to yesterday's cumulative total.
// Percentage Change * Volume [today] + PVT [yesterday]
PVTtotal = ( PVTtoday + PVTtotal);
}
}
}
|

Comment