Stuck WIth EMA Above Under Above

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #137059 quote
    TravellingTrader
    Participant
    New

    Hi

    I am trying to get a piece of code that measures a close below the ema above the ema and below the ema – I have come up with :-

    But its bust 🙁

    Any Help gratefully appreciated

    If Barindex > 229 then
    For TP = 24 downto 1 do
    //Loop 1 Close Below EMA
    IF close[tp] < ExponentialAverage[8](close)[tp] and close[tp] < ExponentialAverage[20](close) [tp] then
    //Save When the TP started
    TP1=TP
    //We Found The first Calculation
    C1 = 1
    break
    else
    c1=0
    endif
    next
    
    For TP1 = 24 downto 1 do
    //Loop 1 Close Below EMA
    IF close[tp] > ExponentialAverage[8](close)[tp] and close[tp] > ExponentialAverage[20](close) [tp] then
    //Save When the T2 started
    TP2=TP1
    //We Found The second Calculation
    C2 = 1
    break
    else
    c2=0
    endif
    next
    For TP2 = 24 downto 1 do
    //Loop 1 Close Below EMA
    IF close[tp] < ExponentialAverage[8](close)[tp] and close[tp] < ExponentialAverage[20](close) [tp] then
    //We Found The third Calculation
    C3 = 1
    break
    else
    c3=0
    endif
    next
    endif
    If c1 and c2 and c3 then
    DRAWTEXT(“ON”,barindex,.1,SansSerif,Bold,10)coloured(0,255,0)
    endif
    
    return
    #137064 quote
    robertogozzi
    Moderator
    Master

    Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.

    Thank you 🙂

    TravellingTrader thanked this post
    #137069 quote
    robertogozzi
    Moderator
    Master

    Line 4:

    x = summation[24](close < ExponentialAverage[8](close) and close < ExponentialAverage[20](close))

    line 17:

    y = summation[24](close > ExponentialAverage[8](close) and close > ExponentialAverage[20](close))

    line 29:

    z = summation[24](close < ExponentialAverage[8](close) and close < ExponentialAverage[20](close))

    Lines 4 and 29 are identical, so I must be misunderstanding something.

    Moreover, my examples won’t detect adjacent occurrences only, but any occurrence.

    More detailed info on what you want to achieve would be beneficial.

    TravellingTrader thanked this post
    #137143 quote
    TravellingTrader
    Participant
    New

    Thank you Roberto

    I really appreciate your help

    The reason for the duplicate is that I want to detect when the close is :-

    A. below both the 8 and 20 ema

    B. above both the 8 and 20 ema

    C. Back below both the 7 and 20 ema

    In that order

    I hope that’s clearer

    #137246 quote
    robertogozzi
    Moderator
    Master

    There you go:

    n  = 24
    p1 = 0
    p2 = 0
    IF BarIndex > 229 AND close < ExponentialAverage[8](close) and close < ExponentialAverage[20](close)THEN
       FOR i = n - 1 DOWNTO 1
          IF close[i] < ExponentialAverage[8](close[i]) and close[i] < ExponentialAverage[20](close[i]) THEN
             p1 = i
             Break
          ENDIF
       NEXT
       FOR j = p1 - 1 DOWNTO 1
          IF close[j] > ExponentialAverage[8](close[j]) and close[j] > ExponentialAverage[20](close[j]) THEN
             p2 = j
             Break
          ENDIF
       NEXT
       If p1 > 0 and p2 > 0 then
          DRAWTEXT("ON",barindex,high + range,SansSerif,Bold,10)coloured(0,128,0,255)
       ENDIF
    ENDIF
    return
    TravellingTrader thanked this post
    x-20.jpg x-20.jpg
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Stuck WIth EMA Above Under Above


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by robertogozzi
5 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/24/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...