本帖最後由 sangi 於 13-1-25 23:35 編輯
以下是 日內的VWAP(Volume-Weighted Average Price) 和 TWAP(Time-Weighted Average Price)
1. Indicator: Intraday VWAP
Inputs: PriceSeries(Close) ;
Vars: SumVolume(0) , SumPriceVol(0) , IntradayVWAP(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 Date > Date[1] Then
Begin
SumVolume = 0 ;
SumPriceVol = 0 ;
End ;
SumVolume = SumVolume + Ticks ;
SumPriceVol = SumPriceVol + ( PriceSeries * Ticks ) ;
If SumVolume > 0 Then
IntradayVWAP = SumPriceVol / SumVolume
Else
IntradayVWAP = PriceSeries ;
Plot1(IntradayVWAP ,"VWAP",Yellow,Default,3) ;
2. Indicator: Intraday TWAP
Inputs: PriceSeries(Close) ;
Vars: PriceW(0) , TimeW(0) , IntradayTWAP(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 Date > Date[1] Then
Begin
PriceW = 0 ;
TimeW = 0 ;
End;
PriceW = PriceW + ( PriceSeries * BarInterval ) ;
TimeW = TimeW + BarInterval ;
IntradayTWAP = IFF(TimeW > 0 ,PriceW / TimeW ,0) ;
Plot1(IntradayTWAP,"TWAP",Cyan,Default,3) ;
|