Users who thanked for this post:
Krümel (19.08.2011), Perfect Trader (24.03.2011)
Users who thanked for this post:
Krümel (19.08.2011), Perfect Trader (24.03.2011)
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
{ Function: _TWAP: Time-weighted average price
Very similar to VWAP, except Price is only weighted by the time (number of times the price occurs over a session).
Apply only to intraday charts
}
vars:
PriceW(0),
TimeW(0) ;
// Raise run time error to shut down if the bar type is not intraday
Once if BarType <> 1 then
RaiseRunTimeError(" TWAP function can only be used with intraday charts") ;
// If the current bar date is not equal to the prior bar date then we are on
// the first bar of a new day. If so, then reset PriceW and TimeW.
if Date[1] <> Date then
begin
PriceW = 0;
TimeW = 0;
end;
// Add to the price weighting the new average price times the bar interval (number of minutes)
PriceW = PriceW + ( AvgPrice * BarInterval ) ;
// Add to the time weighting the total elapsed minutes for this day
TimeW = TimeW + BarInterval ;
// If the time weighting is non-zero then we calculate a TWAP, else return -1
// indicating we cannot calculate TWAP.
if TimeW > 0 then
_TWAP = PriceW / TimeW
else
_TWAP = -1 ;
|
Users who thanked for this post:
Krümel (19.08.2011), Perfect Trader (24.03.2011)
Users who thanked for this post:
goso (22.03.2011), Krümel (19.08.2011), Perfect Trader (23.03.2011), trash (22.03.2011)



|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Private Sub Worksheet_Calculate()
Static BidVorher As Variant
Static AskVorher As Variant
Dim BidAktuell As Variant, AskAktuell As Variant
BidAktuell = Range("B3").Value
If BidAktuell <> BidVorher Then
BidVorher = BidAktuell
Application.ScreenUpdating = False
If Len(Range("B" & Rows.Count)) Then Range("A" & Rows.Count).Resize(1, 2) = ""
Range("A4:B4").Insert
Range("A4").NumberFormat = "dd.mm.yyyy hh:mm:ss"
Range("B4").NumberFormat = Range("B3").NumberFormat
Range("A4").Value = Now
Range("B4").Value = BidAktuell
Application.ScreenUpdating = True
End If
AskAktuell = Range("D3").Value
If AskAktuell <> AskVorher Then
AskVorher = AskAktuell
Application.ScreenUpdating = False
If Len(Range("D" & Rows.Count)) Then Range("C" & Rows.Count).Resize(1, 2) = ""
Range("C4:D4").Insert
Range("C4").NumberFormat = "dd.mm.yyyy hh:mm:ss"
Range("D4").NumberFormat = Range("D3").NumberFormat
Range("C4").Value = Now
Range("D4").Value = AskAktuell
Application.ScreenUpdating = True
End If
End Sub
|
Users who thanked for this post:
Shakesbeer (10.08.2010), Vikke (10.08.2010)
Users who thanked for this post:
hapack (10.08.2010), Perfect Trader (10.08.2010)
Users who thanked for this post:
Perfect Trader (10.08.2010), Vikke (10.08.2010)
Users who thanked for this post:
Shakesbeer (10.08.2010), trash (10.08.2010), Vikke (10.08.2010)
Forum Software: Burning Board® 3.1.6, developed by WoltLab® GmbH