Summation with IF inside…

Forums ProRealTime English forum ProBuilder support Summation with IF inside…

Viewing 4 posts - 1 through 4 (of 4 total)
  • #167703

    Hi,

    I want to implement the following code in PROREALCODE:

    vp = Sum(if diff > factor * atr then volume else 0, length);

    (The diff, factor and atr are known, The length is a period)

    I do following but it seems not the result what I want.

     

     

     

    #167706

    Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.

    Thank you 🙂

     

    #167707

    The logic is correct, you can double check it by using a complete sum, then check any difference:

    VP and VV should be different.

    Moreover, starting from 1 skips the current candle [0].

     

     

    #167730

    Hi Robert,

    Thanks for the reply. But it looks different than the original one.

    Here are the codes from ThinkOrSwim (see the attached chart):

    input length = 30;
    input emaLength = 3;
    input averageLength = 30;
    input factor = 0.1;
    input criticalValue = 10;
    input averageType = AverageType.EXPONENTIAL;

    def atr = WildersAverage(TrueRange(high, close, low), length);
    def diff = hlc3 – hlc3[1];
    def vp = Sum(if diff > factor * atr then volume else 0, length);
    def vn = Sum(if diff < -factor * atr then volume else 0, length);

    plot VPN = ExpAverage(100 * (vp – vn) / Sum(volume, length), emaLength);
    plot VPNAvg = MovingAverage(averageType, VPN, averageLength);
    plot CriticalLevel = criticalValue;

    And here are my ProRealTime code:

     

     

     

Viewing 4 posts - 1 through 4 (of 4 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login