Count Crossovers and Crossunders

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15344 quote
    nickp104
    Participant
    New

    Hi,

    I’m trying to count the number of times a short moving average crosses over or crosses under a long moving average over a number of bars. Any help would be gratefully received.

    #15361 quote
    Nicolas
    Keymaster
    Legend

    Hmmm this question of “how much time something occurred in the past through x bars ” have been asked many times. I assume I should make a video for this 🙂

    So firstly, you have to define how much bars you want to lookback:

    lookback = 20 //20 bars lookback

    Then define the conditions you’d like to be tested through this lookback period:

    c1 = average[7] crosses over average[21]

    Finally, count how much time this “c1” condition returned true (so condition value would be 1) in the past with the summation instruction:

    x = summation[lookback](c1)

    Now you have your variable x which contain the number of times the condition “c1” occurred through “lookback”. Happy testing.

    nickp104, Philippo and manel thanked this post
    #15370 quote
    nickp104
    Participant
    New

    Nicolas thanks – and apologies. I assume if had looked harder I would have found the answer in your other posts. Really good of you to help me out and very much appreciated. Nick

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Count Crossovers and Crossunders


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
nickp104 @nickp104 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by nickp104
9 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/23/2016
Status: Active
Attachments: No files
Logo Logo
Loading...