Difference in value between two moving averages

Forums ProRealTime English forum ProOrder support Difference in value between two moving averages

Viewing 6 posts - 1 through 6 (of 6 total)
  • #19703

    Hi, I’m a newbie here.

    I’m attempting to code a ProOrder trading system and I need to code a condition for a position.

    The condition is where the difference between two moving average values is greater than or equal to a value, say 5 for example. So it would need to take into account at any one point the two values of two different moving averages and act where the difference between the two values is greater than 5 as an example.

    Can someone point me at or provide an example of how this should be coded please? Hopefully I have explained it well enough.

    Many thanks

    Robert

    #19705

    This can be coded easily.

    Firstly, define your 2 moving average:

    Calculate their absolute differences (no need to test if the MA1 is above or below the MA2):

    Then make a boolean variable that will return “1” if the condition is true:

    With the variable “test”, you can now play with to do any other things in your code like open or close a position, adding another one, etc..

    Of course these lines of codes would have been shortened but I find it is the best way to explain the coding process.

     

    2 users thanked author for this post.
    #19712

    Great, thank you Nicolas.

    #19960

    Hi

    In this example, I do now need to test if one moving average is above or below the other and by how much. Is there an example of how this is achieved?

    Many thanks

    Robert

    #19964

    You already have everything to do it! You got your 2 MA values (MA1 and MA2), you only need to test if one is superior to the other one. The difference between them is already calculated with “difference”..

    #20038

    Yes, of course. Thank you.

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

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