NexusFi: Find Your Edge


Home Menu

 





Populate an Array with Pivot Points


Discussion in MultiCharts

Updated
    1. trending_up 2,682 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Populate an Array with Pivot Points

  #1 (permalink)
 JHall65 
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
Posts: 23 since Apr 2013
Thanks Given: 3
Thanks Received: 2

I am designing a range trading system that uses pivot points. My first task is to populate an array with all the pivots as they happen. I have a good chunk of code, but it seems to run endlessly. I am not sure how to debug this type of problem. Any help would be greatly appreciated and of course I'll share the end results with the forum.


 
Code
Inputs:	NumberPivots(10), DiffVal(0), 
		LeftStrength(3),RightStrength(3); 

Vars:		counter(0),
		oPivotPriceL(0),oPivotBarL(0),oPivotPriceH(0),oPivotBarH(0),Length(0);

Array: 	Pivots[30,3] (0); //Creats a 2d array and intializes values to 0;

If BarNumber = 1 then 
ClearPrintLog;

//This sets the length to ensure that the same pivot is not observed twice.
Length = RightStrength +1;

//This evaluates each bar to check for a pivot.
value2 = Pivot(L,Length,LeftStrength,RightStrength,1,-1,oPivotPriceL,oPivotBarL);
value4 = Pivot(H,Length,LeftStrength,RightStrength,1,1,oPivotPriceH,oPivotBarH);

	
			For counter = 0 to (NumberPivots - 1) begin
				Pivots[counter,0]=Pivots[counter+1,0]; 
				Pivots[counter,1]=Pivots[counter+1,1];
				Pivots[counter,2]=Pivots[counter+1,2];
				Pivots[counter,3]=Pivots[counter+1,3];
			End;
	
	
			//Add any new pivot low lines
			If (value2 = 1 AND oPivotBarL = RightStrength) then 
				Begin
					Pivots[NumberPivots,0] = BarNumber-RightStrength; // The Bar Number
					Pivots[NumberPivots,1] = RightStrength; //The Number of Bars Ago
					Pivots[NumberPivots,2] = absvalue(H[RightStrength]-L[RightStrength]); // The Bar Body Size
					Pivots[NumberPivots,3] = oPivotPriceL; // The lower pivot price.
				End;
	
	
	
			//Add any new pivot high lines
			If (value4 = 1 AND oPivotBarH = RightStrength) then 
				Begin
					Pivots[NumberPivots,0] = BarNumber-RightStrength; // The Bar Number
					Pivots[NumberPivots,1] = RightStrength;
					Pivots[NumberPivots,2] = absvalue(H[RightStrength]-L[RightStrength]); // The Bar Body Size
					Pivots[NumberPivots,3] = oPivotPriceH; // The lower pivot price.
				End;
				
If LastBarOnChart then begin
	Print("Pivots[:,0]: ", Pivots[NumberPivots,0]);
	Print("Pivots[:,1]: ", Pivots[NumberPivots,1]); 
	Print("Pivots[:,2]: ", Pivots[NumberPivots,2]);
	Print("Pivots[:,3]: ", Pivots[NumberPivots,3]:4:4);	
End;

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

Hi JHall65,

what do you mean with runs endlessly? It seems to calculate quickly here.

What are you trying to do with this piece of code? I think your intention is to move the previously stored pivot in the array one step down to make room for a new pivot. However you are executing this code on every bar, this will probably cause unwanted results as you will likely have multiple indices with the same value.

 
Code
For counter = 0 to (NumberPivots - 1) begin
Pivots[counter,0]=Pivots[counter+1,0]; 
Pivots[counter,1]=Pivots[counter+1,1];
Pivots[counter,2]=Pivots[counter+1,2];
Pivots[counter,3]=Pivots[counter+1,3];
End;
Regards,
ABCTG


JHall65 View Post
I am designing a range trading system that uses pivot points. My first task is to populate an array with all the pivots as they happen. I have a good chunk of code, but it seems to run endlessly. I am not sure how to debug this type of problem. Any help would be greatly appreciated and of course I'll share the end results with the forum.


 
Code
Inputs:	NumberPivots(10), DiffVal(0), 
		LeftStrength(3),RightStrength(3); 

Vars:		counter(0),
		oPivotPriceL(0),oPivotBarL(0),oPivotPriceH(0),oPivotBarH(0),Length(0);

Array: 	Pivots[30,3] (0); //Creats a 2d array and intializes values to 0;

If BarNumber = 1 then 
ClearPrintLog;

//This sets the length to ensure that the same pivot is not observed twice.
Length = RightStrength +1;

//This evaluates each bar to check for a pivot.
value2 = Pivot(L,Length,LeftStrength,RightStrength,1,-1,oPivotPriceL,oPivotBarL);
value4 = Pivot(H,Length,LeftStrength,RightStrength,1,1,oPivotPriceH,oPivotBarH);

	
			For counter = 0 to (NumberPivots - 1) begin
				Pivots[counter,0]=Pivots[counter+1,0]; 
				Pivots[counter,1]=Pivots[counter+1,1];
				Pivots[counter,2]=Pivots[counter+1,2];
				Pivots[counter,3]=Pivots[counter+1,3];
			End;
	
	
			//Add any new pivot low lines
			If (value2 = 1 AND oPivotBarL = RightStrength) then 
				Begin
					Pivots[NumberPivots,0] = BarNumber-RightStrength; // The Bar Number
					Pivots[NumberPivots,1] = RightStrength; //The Number of Bars Ago
					Pivots[NumberPivots,2] = absvalue(H[RightStrength]-L[RightStrength]); // The Bar Body Size
					Pivots[NumberPivots,3] = oPivotPriceL; // The lower pivot price.
				End;
	
	
	
			//Add any new pivot high lines
			If (value4 = 1 AND oPivotBarH = RightStrength) then 
				Begin
					Pivots[NumberPivots,0] = BarNumber-RightStrength; // The Bar Number
					Pivots[NumberPivots,1] = RightStrength;
					Pivots[NumberPivots,2] = absvalue(H[RightStrength]-L[RightStrength]); // The Bar Body Size
					Pivots[NumberPivots,3] = oPivotPriceH; // The lower pivot price.
				End;
				
If LastBarOnChart then begin
	Print("Pivots[:,0]: ", Pivots[NumberPivots,0]);
	Print("Pivots[:,1]: ", Pivots[NumberPivots,1]); 
	Print("Pivots[:,2]: ", Pivots[NumberPivots,2]);
	Print("Pivots[:,3]: ", Pivots[NumberPivots,3]:4:4);	
End;


Follow me on Twitter Reply With Quote
  #3 (permalink)
 JHall65 
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
Posts: 23 since Apr 2013
Thanks Given: 3
Thanks Received: 2


Thanks ABCTG. I figured out that the code keep "calculating" if you do not have a minimum number of bars on your chart. I'm not sure why that is...

You're correct about cascading the values for every bar. I fixed that per your recommendation. Now I am finding that I have incorrect BarNumber(s) turning up. I am not sure why this is happening, so I tried counting the bars manually in the code; same result. Any ideas? I need to be able to store the BarNumber value in the array for comparison purposes.

 
Code
Inputs:	NumberPivots(100), DiffVal(0), 
		LeftStrength(3),RightStrength(3); 

Vars:		counter(0),
		oPivotPriceL(0),oPivotBarL(0),oPivotPriceH(0),oPivotBarH(0),Length(0),
		BarCount(0);

Arrays: 	Pivots[101,4](0); //Creats a 2d array and intializes values to 0;

BarCount = BarCount+1; 

If BarNumber = 1 then 
ClearPrintLog;

//This evaluates each bar to check for a pivot.
value2 = Pivot(L,RightStrength+1,LeftStrength,RightStrength,1,-1,oPivotPriceL,oPivotBarL);
value4 = Pivot(H,RightStrength+1,LeftStrength,RightStrength,1,1,oPivotPriceH,oPivotBarH);
	
	
//Add any new pivot low
If (value2 = 1 AND oPivotBarL = RightStrength) then Begin

	//Cascade all the values
	For counter = 0 to (NumberPivots-1) begin
		Pivots[counter,0]=Pivots[counter+1,0];  
		Pivots[counter,1]=Pivots[counter+1,1]; 
		Pivots[counter,2]=Pivots[counter+1,2];
		Pivots[counter,3]=Pivots[counter+1,3];
		Pivots[counter,4]=Pivots[counter+1,4];
	End;
	
	
	Pivots[NumberPivots,0] = BarNumber; // The Bar Number
	Pivots[NumberPivots,1] = BarNumber - RightStrength; //The Number of Bars Ago
	Pivots[NumberPivots,2] = absvalue(H[RightStrength]-L[RightStrength]); // The Bar Body Size
	Pivots[NumberPivots,3] = oPivotPriceL; // The lower pivot price.
	Pivots[NumberPivots,4] = -1; //Identifies this as a low pivot.
End;
	
	 
	
//Add any new pivot high
If (value4 = 1 AND oPivotBarH = RightStrength) then Begin

	//Cascade all the values
	For counter = 0 to (NumberPivots-1) begin
		Pivots[counter,0]=Pivots[counter+1,0]; 
		Pivots[counter,1]=Pivots[counter+1,1]; 
		Pivots[counter,2]=Pivots[counter+1,2];
		Pivots[counter,3]=Pivots[counter+1,3];
		Pivots[counter,4]=Pivots[counter+1,4];
	End;

	Pivots[NumberPivots,0] = BarNumber; // The Bar Number
	Pivots[NumberPivots,1] = BarNumber - RightStrength;
	Pivots[NumberPivots,2] = absvalue(H[RightStrength]-L[RightStrength]); // The Bar Body Size
	Pivots[NumberPivots,3] = oPivotPriceH; // The lower pivot price.
	Pivots[NumberPivots,4] = 1; //Identifies this as a low pivot.
End;
		
				
If LastBarOnChart then begin
	For counter=0 to NumberPivots begin

		Print(
		"   Pivots[:,0]: ", Pivots[Counter,0],
		"   Pivots[:,1]: ", Pivots[Counter,1],
		"   Pivots[:,2]: ", Pivots[Counter,2]:4:4,
		"   Pivots[:,3]: ", Pivots[Counter,3]:4:4,
		"   Pivots[:,4]: ", Pivots[Counter,4]);
		
	End;	
End;
Print(BarCount,BarNumber);

Started this thread Reply With Quote
  #4 (permalink)
LogicalTrader
Houston, TX
 
Posts: 294 since Aug 2013
Thanks Given: 1,420
Thanks Received: 757

Try storing the value in oPivotBarL and oPivotBarH variables in the array instead of the BarNumber. The Pivot function copies the swing high/low bar number to this ref variable when it is called.

Reply With Quote




Last Updated on August 26, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts