Pivots and VBA

grantx

Senior member
Messages
2,331
Likes
223
The code below will colour a bar on a bar chart blue or red with regard to pivots points/levels. I know the standard formula for pivot points but I don't recognise it here.

Could somebody tell me what calculation is being used here so I can transfer the formula for numerical analysis? I've numbered each line for convenience for ease of reference, and made bold what may be the relevant lines.

Thank you,

Grant.


1 '¡¡ Parameters
2 'Parameters !!
3 '¡¡ PDV parameters
4 Dim LateralBars As Double '5
5 Const Data As Long = 0
6 'PDV parameters !!
7 '¡¡ PDV declarations
8 Dim GetSwingHighBarDataOccur As Long 'Long
9 Dim GetSwingHighBarDatatPrice As Price 'Price
10 Dim GetSwingHighBarDataStrength As Long 'Long
11 Dim GetSwingHighBarDataLength As Long 'Long
12 Dim GetSwingLowBarDatanOccur As Long 'Long
13 Dim GetSwingLowBarDatatPrice As Price 'Price
14 Dim GetSwingLowBarDataStrength As Long 'Long
15 Dim GetSwingLowBarDataLength As Long 'Long
16 'PDV declarations !!
17 Option Explicit
18 Public APP As DrwUserApp
19 Implements Study
20 Public Sub Study_OnInitCalculate()
21 With APP
22 '¡¡ PDV initializations
23 GetSwingHighBarDataOccur = 1
24 GetSwingHighBarDatatPrice = PriceHigh
25 GetSwingHighBarDataStrength = 5
26 GetSwingHighBarDataLength = 50
27 GetSwingLowBarDatanOccur = 1
28 GetSwingLowBarDatatPrice = PriceLow
29 GetSwingLowBarDataStrength = 2
30 GetSwingLowBarDataLength = 50
31 .StartBar = 0
32 'PDV initializations !!
33 End With
34 End Sub
35 Public Sub Study_OnCalculateBar(ByVal Bar As Long)
36 With APP
37 '¡¡ PDV code
38 GetSwingHighBarDataLength = LateralBars * 15
39 GetSwingLowBarDataLength = LateralBars * 15
 
Then "Implements" keyword in line 19 + the "_OnInitCalculate" and "_OnCalculateBar" (20 & 35) type nomencalature would indicate that this code comes from a class module.

Therefore "PriceHigh" and "PriceLow" (24 & 28) are, presumably Sub procedures of the "APP" class dimmed in line 18.

I assume you've made a reference to the DrwUserApp class somehow ie gone (in VBA) Tools . . . References?

If you F2, and so a search for "PriceHigh" and "PriceLow" (the little drop down to the right of the binocular icon) do you see them?
 
DB,

Thank you for the reply. I do see "PriceHigh" and "PriceLow" as described (this was the only part I understood).

If it helps, attached is the full (?) code.

I didn’t write this code; it’s part of my quote feed/system. All I’m looking for is the underlying formula and parameters.


Thanks, again.

Grant.
 

Attachments

  • Pivot Show vba.doc
    36.5 KB · Views: 472
Hello Grantx



The study paints the bar placed in the (n) position where n is the position where there is a pivot high or low, to calculate this position we use two functions:

(for pivot high).GetSwingHighBar(Data, GetSwingHighBarDataOccur, GetSwingHighBarDatatPrice, GetSwingHighBarDataStrength, GetSwingHighBarDataLength)

(for pivot low).GetSwingLowBar(Data, GetSwingLowBarDatanOccur, GetSwingLowBarDatatPrice, GetSwingLowBarDataStrength, GetSwingLowBarDataLength)
Where
(I would rather put the code this way)
'¡¡ PDV initializations
GetSwingHighBarDataOccur = 1 (indicates the closer (n=1) pivot high
GetSwingHighBarDatatPrice = PriceHigh (indicates that the pivot is calculated upon the bar high)
GetSwingHighBarDataStrength = = LateralBars (indicates that a pivot is a pivot if it’s the higher prices = LateralBars bars to the left and to the right)
GetSwingHighBarDataLength = LateralBars * 15
(number of bars to be taken in to account to find the pivot from the current position)
GetSwingLowBarDatanOccur = 1 (indicates the closer (n=1) pivot low
GetSwingLowBarDatatPrice = PriceLow (indicates that the pivot is calculated upon the bar low)

GetSwingLowBarDataStrength = LateralBars (indicates that a pivot is a pivot if it’s the lower prices LateralBars bars to the left and to the right)
GetSwingLowBarDataLength = LateralBars * 15
(number of bars to be taken in to account to find the pivot from the current position)

Remember it has nothing to do with the stnadard pivot point calculation.

Hope it helps.

Mikel
 
Mikel,

Is the following correct? A high pivot is the high of a bar 15 bars back from the current if it also the highest high (opposite for the low pivot).

However, I am confused re DataStrength - Lateral bars to the left and right. Left of where, right of where? Are there actually 2 reference points for the highest high, ie the highest high of the 15 bars back from the current, and the preceding 15 bars from this point? So we are actually looking at the perious 30 bars.

Grant.
 
Hello Grant.

Here is a screenshot .
Let´s start at bar 0 (current bar), the study check if 15 (lateral bars) bars ago is the highest high. Let´s say it is, ( we will name this point , point A) it is not enough to be considered as a pivot yet.
Now we know point A is the highest high from our current bar to the left.
Now the system check from point A to the left (backwards) and it it is the highest high again, it will be then considered as a pivot.
Same staff for the pivot low.

In general therms lets say the current bar makes the lowest low of the last 15 bars (lateral bars),(we will call it point B) the study will have to wait 15 bars more to check that prices do not make a new low. because it they do point B will not be painted as a pivot low.

Mikel
 

Attachments

  • Grant.gif
    Grant.gif
    100.8 KB · Views: 929
Hi Grant.

I forgot an important thing .
We go back to pivot A in the screen shot.
From A backwards you can find a highest high equal to point A.
This is still valid A must be >= to the highest high 15 bars backwards to be considered as pivot
But A must be strictly > to the highest high (lateral bars 15) forwards.


Mikel
 
Hello Mikel,

Perfectly clear. We get there in the end.

Thank you, mate.

Grant.
 
Top