NexusFi: Find Your Edge


Home Menu

 





TWAP and VWAP


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one bomberone1 with 9 posts (0 thanks)
    2. looks_two Fat Tails with 5 posts (12 thanks)
    3. looks_3 courier12 with 3 posts (0 thanks)
    4. looks_4 Big Mike with 2 posts (1 thanks)
      Best Posters
    1. looks_one Fat Tails with 2.4 thanks per post
    2. looks_two treydog999 with 1 thanks per post
    3. looks_3 NickA with 0.5 thanks per post
    4. looks_4 Big Mike with 0.5 thanks per post
    1. trending_up 30,734 views
    2. thumb_up 15 thanks given
    3. group 11 followers
    1. forum 27 posts
    2. attach_file 0 attachments




 
 

TWAP and VWAP

 
 bomberone1 
London
 
Experience: Beginner
Platform: MultiCharts
Posts: 277 since Nov 2010
Thanks Given: 14
Thanks Received: 29

Whow i am not good in math but I surpryse that no one coder is able to code twap, wow is it so difficult??

Started this thread

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
 
 
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


bomberone1 View Post
So I am searching both twap indicator in easylanguage both twap trading metod.

I see a video that a folk manage to make a vwap multiday, it's called n vwap.


Could someone code it please?

The VWAP and TWAP are average prices determined for the period between an anchor point and now. You can define any anchor point that you like.

If you look up, the July 2010 issue of "Technical Analysis of Stocks and Commodities", you will find the tradestation code for a VWAP channel in the Trader's Tips section, page 74.

As MultiCharts uses EasyLanguage you can use the code and run it on MultiCharts.

 
 bomberone1 
London
 
Experience: Beginner
Platform: MultiCharts
Posts: 277 since Nov 2010
Thanks Given: 14
Thanks Received: 29



Fat Tails View Post
The VWAP and TWAP are average prices determined for the period between an anchor point and now. You can define any anchor point that you like.

If you look up, the July 2010 issue of "Technical Analysis of Stocks and Commodities", you will find the tradestation code for a VWAP channel in the Trader's Tips section, page 74.

As MultiCharts uses EasyLanguage you can use the code and run it on MultiCharts.

Thanks but about twap, I need to find easylanguage code. I get vwap.

Started this thread
 
 NickA 
London
 
Experience: None
Platform: MC & Ninja mainly
Posts: 135 since Jan 2010
Thanks Given: 5
Thanks Received: 50

Not sure what you want really?

TWAP is just a way of splitting up orders nad submitting them in chunks based on time. Do you want some easy language code to break up orders and submit them automatically?

If you want to know what the 'TWAP' was just use a simple moving average.

 
 bomberone1 
London
 
Experience: Beginner
Platform: MultiCharts
Posts: 277 since Nov 2010
Thanks Given: 14
Thanks Received: 29

You Don't worry that all.


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

Could you improve it?

Started this thread
 
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


NickA View Post
Not sure what you want really?

TWAP is just a way of splitting up orders nad submitting them in chunks based on time. Do you want some easy language code to break up orders and submit them automatically?

If you want to know what the 'TWAP' was just use a simple moving average.

This is a bit simplistic, if not false.

-> TWAP is not a way of breaking up orders.

-> TWAP is an anchored moving average. This means that it is a moving average, for which the period is incremented by 1 for each bar.

-> TWAP is only a simple moving average (SMA) on charts with a fixed period. The reason is simple. If all bars have the same duration, the weight used for each bar is one, and the TWAP is identical with an anchored SMA.

-> On other chart types, such as tick, range or volume chart, the bars do not have the same duration, so a time-weighting is necessary to calculate the TWAP. In this case the TWAP is a time-weighted moving average (TWMA).

-> If you divide a large order and execute it over time in a linear fashion, that is at a constant execution speed, at the end of the day your execution price will be the TWAP. I believe that nobody is doing this anymore.

Hope this makes things clearer.

 
 NickA 
London
 
Experience: None
Platform: MC & Ninja mainly
Posts: 135 since Jan 2010
Thanks Given: 5
Thanks Received: 50

Sure - the bar periodicity controls the sampling frequency. The start bar controls the anchor point. If you don't want that to be at the beginning of a session you'd have to write a couple of lines of extra code.

bomberone1 has been posting for some while now round the internet asking 'can you give me TWAP code', I thought I'd try and help. If you explain exactly what you need bomber it should not be too hard to point you in the right direction.

Compared to VWAP TWAP is ....well... trivial to implement. VWAP is much tricker especially if you want to use an online algorithm (making it suitable for large data sets like tick data) and include stuff like SD's.

Maybe its just semantics but if you speak to most traders about TWAP they will assume you are talking about execution. Platforms that offer TWAP execution do indeed break up a large order and executes it as a batch of smaller orders over time. That's all I meant there

What I don't understand is what bomber wants. If it is TWAP execution there are platforms that offer it, if it's plotting it on a chart its pretty straight forward.

Incidentally I glanced at the code that you have and it appears OK Bomber, what do you want improved?

Thanked by:
 
rocky9281
Kolkata,India
 
Posts: 100 since Feb 2011
Thanks Given: 52
Thanks Received: 40

Hello,

I am using NT 7, I want to track if any vwap /twap algo is currently getting executed thru the T&S data. Can anybody please guide me on how to do this?

 
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


rocky9281 View Post
Hello,

I am using NT 7, I want to track if any vwap /twap algo is currently getting executed thru the T&S data. Can anybody please guide me on how to do this?

I think that you cannot easily spot them. If I had to code a TWAP execution algorithm, I would include at least two elements

-> breaking up the order into equal slices over the execution period
-> use another algorithm which acts in a similar fashion as a random generator to hide the execution

Also TWAP is really the first generation of execution algorithms, and there are much better options.

However, you may well examine the ticker tape for non-random properties. If a specific ordersize regularly occurs on the order book, you may at least conclude that a larger order is executed by a primitve algorithm and decide to exploit it. If the time intervals between these orders are identical, it may well be a TWAP algorithm working, But how would you want to generate profits?

 
 mavinwiz 
arcadia
 
Experience: Intermediate
Platform: Ninja
Trading: es
Posts: 22 since Aug 2009
Thanks Given: 29
Thanks Received: 22


Does anyone have TWAP for Ninjatrader?

Thanks in advance and cheers!


 



Last Updated on May 7, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts