First Difference and Running Sum

Forums ProRealTime English forum General trading discussions First Difference and Running Sum

  • This topic has 7 replies, 2 voices, and was last updated 2 weeks ago by avatarJS.
Currently, there are 0 users and 2 guests visiting this topic.
View all attachments
Viewing 8 posts - 1 through 8 (of 8 total)
  • #174646 Report
    JS

    In DSP (Digital Signal Processing) there are processes that can change signals in ways that resemble differentiation and integration.

    Only the terms differentiation and integration refers to actions on continuous signals.

    For actions on discreet signals these terms are given other names:

    First Derivative (continuous signals) = First Difference (discreet signals)

    Integration (continuous signals) = Running Sum (discreet signals)

    The relation (equation) for the First Difference is: y[n] = x[n] – x[n-1]

    The relation(equation) for the Running Sum is: y[n] = x[n] + y[n-1]

    This kind of equation is also called, Difference Equation or Recursion Equation.

    In code:

    //Calculation of the First Difference

    y=0

    For i = 1 to N-1

    y = Close[i] – Close[i-1]

    Next

    Return y

    //Calculation of the Running Sum

    y=Close

    For i = 1 to N-1

    y = Close[i] + y[i-1]

    Next

    Return y

     

    Attachments:
    #174649 Report

    The first FOR…NEXT is useless, since Y will be assigned only the last value of all iterations, the same as:

    Did you mean:

    ?
    Moreover, is it correct N-1 as last iteration?

    #174661 Report
    JS

    Thanks Roberto,

    Indeed sloppy coding, properly I must use arrays.

    The last iteration must be N instead of N-1

    (when i start at 0 then i=0 to N-1)

    #174663 Report
    JS

    @Roberto, can you give me some help with the coding…?

    (The equitations are correct)

    #174667 Report

    I’ll try asap.

     

    1 user thanked author for this post.
    avatar JS
    #175005 Report

    I think the First Difference should be (see attached pic):

    y[n] = x[n + 1] – x[n]

    If this is the case, then the code to get Ys is:

    FOR…NEXT is useless, as you only return the value calculated by the LAST iteration.
    What exactly do you want to calculate?
    As you have put it, it’s just a momentum indicator over the last 2 candles.

    Attachments:
    #175031 Report
    JS

    Thanks Roberto for the effort, I will give it a thought …

    #195487 Report
    JS

    I’ve become a little wiser 😉 partly thanks to the forum…

    The theory of the “first difference” and the “running sum” is correct but the execution was not correct, I had to use arrays…

    The “first difference” is the discrete version of the first derivative or the slope of the input signal (close).

    The “running sum” is the discrete version of the integral or when you integrate the first derivative you get the original signal (close).

    Attachments:
Viewing 8 posts - 1 through 8 (of 8 total)

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