How to code no crossover/crossunder on the moving average for the past 20 bars

Forums ProRealTime English forum ProBuilder support How to code no crossover/crossunder on the moving average for the past 20 bars

Currently, there are 0 users and 1 guest visiting this topic.
View all attachments
Viewing 4 posts - 1 through 4 (of 4 total)
  • #147634 Report

    Hello all and sorry for such a beginners question i guess, but ive forgot how to do this and i cant easily find an answer by searching words for this so im just going to ask:

    How can i code: If there has been no crossover/crossunder on the moving average, for the past 20 bars, then K = 0

     

    x = moving average 20

    I could say:  Close > x and close[1] > x[1] ……. close[20] > x[20]

     

    and then reverse the < sign, but i know theres an easier way to write this piece of the code.

     

    Big thx for any help.

    #147635 Report

    Hello,

     

    you are talking about “no cross” moving average I guess.

     

    You can find a code snipet here :

    https://www.prorealcode.com/topic/codage-non-croisement-d-mm/

    1 user thanked author for this post.
    #147636 Report

    Hello,

    you are talking about “no cross” moving average I guess.

    You can find a code snipet here :

    https://www.prorealcode.com/topic/codage-non-croisement-d-mm/

    Thanks, i think its the “summation” part i was looking for 🙂 Looks like my code is working now, here it is for anyone wondering:

    i have e1 and e2 = 20 at the moment, but you can try whatever numbers you want.

    Im going to use this as a filter for when “price is choppy”. As soon as there has been e2 periods (20 at the moment) with no crossover/crossunder, then K=0.

     

     

    #147744 Report

    You must know the rules by now jebus89! Topics must have meaningful titles – I’ve changed yours from ‘Simple question’!

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