TWap

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #138756 quote
    Dr Manhattan
    Participant
    Senior
    //@version=4
    study("TWAP Trend", "TWAP", true)
    smoothing = input(14)
    resolution = input("0", "Timeframe") //240 D
    src = input(ohlc4)
    res = resolution != "0" ? resolution : timeframe.period
    weight = barssince(change(security(syminfo.tickerid, res, time, lookahead=barmerge.lookahead_on)))
    price = 0.
    price:= weight == 0 ? src : src + nz(price[1])
    twap = price / (weight + 1)
    ma = smoothing < 2 ? twap : sma(twap, smoothing)
    bullish = iff(smoothing < 2, src >= ma, src > ma)
    disposition = bullish ? color.lime : color.red
    basis = plot(src, "OHLC4", disposition, linewidth=1, transp=100)
    work = plot(ma, "TWAP", disposition, linewidth=2, transp=20)
    fill(basis, work, disposition, transp=65)
    
    showcross = input(false, title="Show Buy/Sell")
    crossup = ma[1] < src[1] and ma > src
    crossdn = ma[1] > src[1] and ma < src
    plotshape(showcross and crossup and not crossup[1] ? src : na, location=location.absolute, style=shape.labeldown, color=color.red, size=size.tiny, text="Sell", textcolor=#ffffff, transp=0, offset=-1)
    plotshape(showcross and crossdn and not crossdn[1] ? src : na, location=location.absolute, style=shape.labelup, color=color.lime, size=size.tiny, text="Buy", textcolor=#ffffff, transp=0, offset=-1)
    

    In finance, time-weighted average price (TWAP) is the average price of a security over a specified time. Below are some contrasting differences between TWAP and VWAP:-

    1. TWAP is weighted based on time, VWAP is weighted based on time and volume.
    2. Small volume trades do not impact TWAP but it does impact VWAP
    3. TWAP calculation is fairly simple while VWAP calculation is complex
    4. VWAP trade will buy or sell 40% of a trade in the first half of the day and then the other 60% in the second half of the day. A TWAP trade would most likely execute an even 50/50 volume in the first and second half of the day.
    #138981 quote
    Dr Manhattan
    Participant
    Senior

    I made a coding request for this one. I didnt know it would end up as a forum post,  but this is a coding request. I wasnt sure how to convert this from pine script to pro real code.

    #139115 quote
    Nicolas
    Keymaster
    Master

    Please post a screenshot of how it should look on a chart. Do you want it to work on v10.3? (other timeframe than the actual one is only possible with v11).

    #139388 quote
    Dr Manhattan
    Participant
    Senior

    Below is a screenshot! I can work on the current timeframe. I use it personally on a 30 min. It doesnt matter so much the settings, it just to cut it in a nice way and then use the risk control.

    TWAP.png TWAP.png
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

TWap


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Dr Manhattan
5 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/08/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...