This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:

We work extremely hard to keep things positive on our forums.

We do not tolerate rude behavior, trolling, or vendor advertising in posts.

We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.

We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

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.

Last edited by JHall65; August 26th, 2013 at 02:51 PM.

This post has been selected as an answer to the original posters question

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.

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.

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);

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.