Welcome to the Traders Laboratory.

Coding Forum Collaborate, receive help, or discuss indicators and other coding-related topics

Reply
Old 08-17-2015, 11:48 AM   #1

Join Date: Jul 2008
Location: nd
Posts: 20
Ignore this user

Thanks: 40
Thanked 2 Times in 2 Posts

PVP Code Error

Code:
///// PVP /////

BarSinceND = BarsSince(ND);
iStart = Max(BarCount - 1 - BarSinceND[BarCount - 1], 0);
Top = HighestSince(ND, High);
Bot = LowestSince(ND, Low);
Range = Top - Bot;
BoxesInRange = Range / TickSize + 1;
VolUnit = Volume / ((High - Low) / TickSize + 1);
VUcount = 0;
MaxVUcount = 0;
PVP = Null;

if(iStart > 0)
{
for(i = iStart; i < BarCount; i++)
	{
	jShift = round((Bot[i - 1] - Low[i]) / TickSize);
	if((BoxesInRange[i] < BarCount))
		{
		if(jShift > 0)
			{
			LastVUcount = VUcount;
			VUcount = 0;
			for(j = jShift; j < BoxesInRange[i]; j++)
				{
				VUCount[j] = LastVUCount[j - jShift];
				}
			}
		jStart = round((Low[i] - Bot[i]) / TickSize);
		jEnd = round((High[i] - Bot[i]) / TickSize);
		for(j = jStart; j <= jEnd; j++)
			{
			VUcount[j] = VUcount[j] + VolUnit[i];
			MaxVUcount = Max(MaxVUcount, VUcount[j]);
			}
		}
	}
for(j = 0; j < BoxesInRange[BarCount - 1]; j++)
	{
	if(MaxVUcount == VUcount[j])
		PVP = Bot[BarCount - 1] + j * TickSize;
	}
Plot(PVP, "PVP", colorTurquoise, styleDots + styleNoTitle + styleNoRescale);
}
This is the code for PVP which I found in market statistics forum. It is throwing some error : array subscript outof range. This is amibroker code. Can someone help in removing the error please?
delta is offline  
Reply With Quote
Old 08-17-2015, 11:55 AM   #2

Join Date: Jul 2008
Location: nd
Posts: 20
Ignore this user

Thanks: 40
Thanked 2 Times in 2 Posts

Re: PVP Code Error

Code:
ND = Day() != Ref(Day(), -1);

///// VWAP and SDs /////

P = (H + L) / 2;
VWP = P * V;
BI = BarIndex();
BeginBI = ValueWhen(ND, BI);
BeginBI = BeginBI[BarCount -1];
if(BeginBI < BarCount - 1)
	{
	InRange = BI >= BeginBI;
	CumV = Cum(V * InRange);
	CumVWP = Cum(VWP * InRange);
	VWAP = CumVWP / CumV;
	S = Cum(Ref(CumV, -1) * V * (P - Ref(VWAP, -1))^2 / CumV);
	Variance = S / CumV;
	SD = sqrt(Variance);
	VWAP = IIf(InRange, VWAP, Null);
	Plot(VWAP, "VWAP", colorYellow, styleNoTitle + styleNoRescale);
	Plot(VWAP + SD, "+1SD", colorGreen, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP - SD, "-1SD", colorRed, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP + 2*SD, "+2SD", colorSeaGreen, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP - 2*SD, "-2SD", colorOrange, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP + 3*SD, "+3SD", colorPaleGreen, styleDashed + styleNoTitle + styleNoRescale);
	Plot(VWAP - 3*SD, "-3SD", colorLightOrange, styleDashed + styleNoTitle + styleNoRescale);
	}

///// PVP /////

BarSinceND = BarsSince(ND);
iStart = Max(BarCount - 1 - BarSinceND[BarCount - 1], 0);
Top = HighestSince(ND, High);
Bot = LowestSince(ND, Low);
Range = Top - Bot;
BoxesInRange = Range / TickSize + 1;
VolUnit = Volume / ((High - Low) / TickSize + 1);
VUcount = 0;
MaxVUcount = 0;
PVP = Null;

if(iStart > 0)
{
for(i = iStart; i < BarCount; i++)
	{
	jShift = round((Bot[i - 1] - Low[i]) / TickSize);
	if((BoxesInRange[i] < BarCount))
		{
		if(jShift > 0)
			{
			LastVUcount = VUcount;
			VUcount = 0;
			for(j = jShift; j < BoxesInRange[i]; j++)
				{
				VUCount[j] = LastVUCount[j - jShift];
				}
			}
		jStart = round((Low[i] - Bot[i]) / TickSize);
		jEnd = round((High[i] - Bot[i]) / TickSize);
		for(j = jStart; j <= jEnd; j++)
			{
			VUcount[j] = VUcount[j] + VolUnit[i];
			MaxVUcount = Max(MaxVUcount, VUcount[j]);
			}
		}
	}
for(j = 0; j < BoxesInRange[BarCount - 1]; j++)
	{
	if(MaxVUcount == VUcount[j])
		PVP = Bot[BarCount - 1] + j * TickSize;
	}
Plot(PVP, "PVP", colorTurquoise, styleDots + styleNoTitle + styleNoRescale);
}

This is the complete code. The error is in PVP portion of the code.
delta is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile Error MC O66 Coding Forum 2 04-14-2010 11:00 AM
TS8 Error hogarstrasni General Discussion 2 10-07-2009 07:22 PM
Error in MC emptyvault Coding Forum 11 08-30-2009 01:55 PM
Error Code Help Please emptyvault Coding Forum 10 07-19-2009 01:21 PM
Url.dll Error - Help! brownsfan019 Tools of the Trade 5 09-16-2008 06:50 PM

All times are GMT -4. The time now is 12:06 PM.
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
2006-2011 Traders Laboratory, All Rights Reserved.