Distance to last fractal high

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #240681 quote
    trwcapitaltrwcapital
    Participant
    New

    I’m looking for some help to write code to define the distance to the last fractal high. In other words, what is the current distance to the last higher high (when there was at least 1 bar break lower). I’ve attached an example and drawn what I am defining as the fractal low (purple dot) and the distance I am trying to calculate (red lines). I assume this has to use an array of sorts but I’m not very well versed in those yet.

    Screenshot-2024-11-22-213510.png Screenshot-2024-11-22-213510.png
    #240692 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I don’t know what indicator you used, so I made this one:

    // Fractls
    //
    // https://www.prorealcode.com/topic/distance-to-last-fractal-high/
    //
    ONCE P           = 15
    ONCE HH          = 0
    ONCE HHprev      = 0
    ONCE LL          = 0
    ONCE LLprev      = 0
    ONCE LastFractal = 0
    FractalDistance  = 0
    Offset           = average[20,0](range)
    Bullish     = close > open
    Bearish     = close < open
    HIGHfractal = Bullish[1] AND Bearish AND (high[1] > high[2]) AND (high[1] > high) AND (high[1] = highest[P](high))
    LOWfractal  = Bearish[1] AND Bullish AND (low[1]  < low[2])  AND (low[1]  < low)  AND (low[1]  = lowest[P](low))
    //
    IF HIGHfractal AND ((LastFractal = 0) OR (LastFractal = -1)) THEN
    LastFractal = 1
    HHprev = HH
    HH     = high[1]
    DrawText("●",BarIndex[1],high[1] + Offset,dialog,standard,15) coloured("Green")
    IF HHprev <> 0 THEN
    Gap = HH - HHprev
    DrawText("#Gap#",BarIndex[1],high[1] + Offset*2,dialog,standard,15) coloured("Green")
    ENDIF
    ENDIF
    //
    IF LOWfractal AND ((LastFractal = 0) OR (LastFractal = 1)) THEN
    LastFractal = -1
    LLprev = LL
    LL     = low[1]
    DrawText("●",BarIndex[1],low[1] - Offset,dialog,standard,15) coloured("Red")
    IF LLprev <> 0 THEN
    Gap = LLprev - LL
    DrawText("#Gap#",BarIndex[1],low[1] - Offset*2,dialog,standard,15) coloured("Red")
    ENDIF
    ENDIF
    //
    RETURN
    Iván González thanked this post
Viewing 2 posts - 1 through 2 (of 2 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

Distance to last fractal high


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
trwcapital @trwcapital Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzirobertogozzi
1 year, 9 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 11/23/2024
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...