VPN indicator code

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #176180 quote
    eckaw
    Participant
    Veteran

    I’m curious about the VPN indicator by Markos Katsanos, but I’m struggling to convert the code. Does anyone know how to code this?

    “The VPN indicator calculates the difference of up day volume and down day volume, divided by the total volume. A day is an up day when its typical price – the average of high, low, and close – is higher than yesterday’s typical price plus 1/10 ATR. The opposite is true for down days. The result is multiplied by 100 and smoothed with a 3-day EMA.”

    This is my poor attempt, would appreciate if someone could point me in the right direction.

     

    // VPN INDICATOR
    
    //The VPN indicator calculates the difference of up day volume and down day volume, divided by the total volume. A day is an up day when its typical price - the average of high, low, and close - is higher than yesterday’s typical price plus 1/10 ATR. The opposite is true for down days. The result is multiplied by 100 and smoothed with a 3-day EMA. The C code of this indicator:
    
    
    hlc = (Dhigh(0) + Dlow(0) + Dclose(0)) / 3
    //should it be?  hlc = (high + low + close) / 3
    
    once Periods = 30
    
    dist =  0.1 * AverageTrueRange
    once vp = 0.0
    once vn = 0.0
    for i = 0 to periods-1 do
    if (hlc[i] > hlc[i+1] + dist) then
    vp = volume[i]
    elsif (hlc[i] < hlc[i+1] - dist) then
    vn = volume[i]
    vtot = volume[i]
    endif
    next
    
    result = 100*((vp-vn)/vtot)
    
    VPN = ExponentialAverage(result)[3]
    
    
    DRAWHLINE(0)coloured(0,0,0)
    
    return VPN coloured(225,0,0)
    #176182 quote
    Nicolas
    Keymaster
    Master

    Not correct, but you were close! 🙂 Pinescript is somehow similar to Python with indentation.

    Try that version instead:

    once period=30
    once iATR = .1
    
    dist = AverageTrueRange[period](close) * iATR
    vp = 0.0
    vn = 0.0
    vtot = 0.0
    for i = 0 to period - 1
    hlc3 = (Dhigh(i) + Dlow(i) + Dclose(i)) / 3
    hlc31 = (Dhigh(i+1) + Dlow(i+1) + Dclose(i+1)) / 3
    if (hlc3 > (hlc31 + dist)) then 
    vp = vp+volume[i]
    elsif (hlc3 < (hlc31 - dist)) then 
    vn = vn+volume[i]
    endif
    vtot = vtot+ volume[i]
    next
    vpn = (((vp - vn) / (vtot / period)) / period) * 100
    
    return vpn
    eckaw thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

VPN indicator code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
eckaw @eckaw Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Nicolas
4 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/25/2021
Status: Active
Attachments: No files
Logo Logo
Loading...