Periods since close below Supertrend

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #104664 quote
    Damian LeeDamian Lee
    Participant
    New

    Hi

    Looking to try and code to return number of periods since when the close crosses above (or below) the supertend, and then note the last value of the supertrend prior to the close crossing it. I can see the barindex and tradeindex but don’t know how to refer to any other condition.

    Thanks in advance šŸ™‚

    #104667 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I moved your topic to ProOrder support, since you are referencing TRADEINDEX which is related to strategies.

    This is the code:

    ONCE CrossOVER  = 0
    ONCE CrossUNDER = 0
    ONCE PrevClose  = 0
    MyST = Supertrend[3,10]
    IF CrossUNDER = 0 THEN
       IF close CROSSES UNDER MyST THEN
          PrevClose  = close[1]
          CrossUNDER = BarIndex
          CrossOVER  = 0
       ENDIF
    ENDIF
    IF CrossOVER = 0 THEN
       IF close CROSSES OVER MyST THEN
          PrevClose  = close[1]
          CrossUNDER = 0
          CrossOVER  = BarIndex
       ENDIF
    ENDIF

    Basically you have to keep track of the bar when the crossing occurs and, at the same time, save the value of the CLOSE prior to the crossing.

    Clear all values and flags when a reverse crossing occurs.

    At the end of the code, PREVCLOSE, if other than 0, will retaing the CLOSing price the candle before the crossing occurs.

    To tell how many bars have elapsed, in case CROSSOVER/UNDER > 0, just use the expression:

    ElapsedBars = (BarIndex - CrossOver)  + 1
    ElapsedBars = (BarIndex - CrossUnder) + 1
    #104670 quote
    Damian LeeDamian Lee
    Participant
    New

    Thank heaps for that.Ā  Sooo much appreciated

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

Periods since close below Supertrend


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Damian Lee @damian_lee Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Damian LeeDamian Lee
7 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/13/2019
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...