Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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.
Can you help answer these questions from other members on NexusFi?
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.