Ehlers' Sinewave Indicator

Viewing 12 posts - 16 through 27 (of 27 total)
  • Author
    Posts
  • #123303 quote
    Bard
    Participant
    Master

    Hi there, can anyone figure out how to get the Fractal indicator to take trades in a system?
    I tried writing it out manually (including adding the indicator in the system as I’m not sure if calling it is the fastest, cleanest way to use it?), but it only takes one trade. The first one.

    It’d be really interesting to backtest this with differnt types of stops (Kase Dev Stop, Kaufman, Trailing Stops etc) because the enrties already look like they’re way beyond 50% accurate on direction.

    Cheers for any help,

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    //Shouldersize = 3 //size of shoulders
    
    ShoulderSize = 5
    r = ShoulderSize*2
    
    once SwingH = 0
    once SwingL = 0
    once FractalD = 0
    
    For i = 0 to r Do
    If high[ShoulderSize] > high[i] or i = ShoulderSize Then
    SwingH = SwingH + 1
    EndIf
    If low[ShoulderSize]  < low[i] or i = ShoulderSize Then
    SwingL = SwingL + 1
    EndIf
    Next
    
    If SwingH = (r+1) and (FractalD = 0 or FractalD = -1) Then
    FractalH = high[ShoulderSize]
    FractalD = 1
    EndIf
    
    If SwingL = (r+1) and (FractalD = 0 or FractalD = 1) Then
    FractalD = -1
    EndIf
    
    SwingH = 0
    SwingL = 0
    
    // Conditions to enter long positions
    If SwingL = (r+1) and (FractalD = 0 or FractalD = -1) Then
    FractalL = low[ShoulderSize]
    Endif
    
    If FractalL then
    Buy 10 Perpoint at Market
    Endif
    
    // Conditions to enter short positions
    If SwingH = (r+1) and (FractalD = 0 or FractalD = 1) Then
    FractalH = high[ShoulderSize]
    Endif
    
    If FractalH then
    Sellshort 10 Perpoint at Market
    Endif
    
    #123489 quote
    Bard
    Participant
    Master

    Spotted my mistake, the Fractal conditions weren’t complete. Here’s the correct Fractal System code:
    Fractal triangles in the screenshot are yellow and blue.

    3.8 spread. £/$ Daily. 01/11/17-29/01/19
    200% return, 40% Drawdown.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    //Shouldersize = 3 //size of shoulders
    
    ShoulderSize = 2
    r = ShoulderSize*2
    
    once SwingH = 0
    once SwingL = 0
    once FractalD = 0
    
    For i = 0 to r Do
    If high[ShoulderSize] > high[i] or i = ShoulderSize Then
    SwingH = SwingH + 1
    EndIf
    If low[ShoulderSize] < low[i] or i = ShoulderSize Then
    SwingL = SwingL + 1
    EndIf
    Next
    
    If SwingH = (r+1) and (FractalD = 0 or FractalD = -1) Then
    FractalH = high[ShoulderSize]
    FractalD = 1
    EndIf
    
    If SwingL = (r+1) and (FractalD = 0 or FractalD = 1) Then
    FractalL = low[ShoulderSize]
    FractalD = -1
    EndIf
    
    SwingH = 0
    SwingL = 0
    
    // Conditions to enter long positions
    If SwingL = (r+1) and (FractalD = 0 or FractalD = -1) Then
    FractalL = low[ShoulderSize]
    Endif
    
    If FractalD = -1 and FractalL then
    Buy 10 Perpoint at Market
    Endif
    
    // Conditions to enter short positions
    If SwingH = (r+1) and (FractalD = 0 or FractalD = 1) Then
    FractalH = high[ShoulderSize]
    Endif
    
    If FractalD = 1 and FractalH then
    Sellshort 10 Perpoint at Market
    Endif
    #123494 quote
    Bard
    Participant
    Master

    Fractal + Kase Dev Stop

    Fractal triangles in the screenshot are yellow and blue.

    3.8 spread. £/$ Daily. 01/11/17-29/01/19 (randomly chosen dates)
    200% return, 32% Drawdown.
    Shouldersize = 5 randomly chosen. Please adjust these and the Dev Stop for different markets.

    Kase Dev Stop code: https://www.prorealcode.com/prorealtime-indicators/kase-dev-stop-v3

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    //Shouldersize = 3 //size of shoulders
    
    ShoulderSize = 5
    r = ShoulderSize*2
    
    once SwingH = 0
    once SwingL = 0
    once FractalD = 0
    
    For i = 0 to r Do
    If high[ShoulderSize] > high[i] or i = ShoulderSize Then
    SwingH = SwingH + 1
    EndIf
    If low[ShoulderSize]  < low[i] or i = ShoulderSize Then
    SwingL = SwingL + 1
    EndIf
    Next
    
    If SwingH = (r+1) and (FractalD = 0 or FractalD = -1) Then
    FractalH = high[ShoulderSize]
    FractalD = 1
    EndIf
    
    If SwingL = (r+1) and (FractalD = 0 or FractalD = 1) Then
    FractalL = low[ShoulderSize]
    FractalD = -1
    EndIf
    
    SwingH = 0
    SwingL = 0
    
    // Conditions to enter long positions
    If SwingL = (r+1) and (FractalD = 0 or FractalD = -1) Then
    FractalL = low[ShoulderSize]
    Endif
    
    If FractalD = -1 and FractalL then
    Buy 10 Perpoint at Market
    Endif
    
    // Conditions to exit long positions
    ignored, ignored, ignored, Dev,ignored, ignored = CALL "Kase Dev Stop Lisse+SAR+4.5/6"
    c1 = (close CROSSES UNDER Dev)
    
    IF c1 THEN
    SELL AT MARKET
    ENDIF
    
    //-------------------------//
    
    // Conditions to enter short positions
    If SwingH = (r+1) and (FractalD = 0 or FractalD = 1) Then
    FractalH = high[ShoulderSize]
    Endif
    
    If FractalD = 1 and FractalH then
    Sellshort 10 Perpoint at Market
    Endif
    
    // Conditions to exit short positions
    ignored, ignored, ignored, Dev, ignored, ignored = CALL "Kase Dev Stop Lisse+SAR+4.5/6"
    c2 = (close CROSSES OVER Dev)
    
    IF c2 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    //Voici le code en version SAR : plus WITH DEV STOP 4.5 + 6.0
    
    //Settings
    n=30
    
    p1=1.0
    p2=2.2
    p3=3.6
    p4=4.5
    p5=6.0
    
    difference=0
    Hg=highest[2](high)
    Lw=lowest[2](low)
    DTR=max(max(Hg-Lw,abs(Hg-close[2])),abs(Lw-close[2]))
    aDTR=average[n](DTR)
    for i=0 to n-1 do
    difference=difference+square(DTR[i]-aDTR)
    next
    difference=difference/n
    sdev=sqrt(difference)
    
    dev0=close-aDTR
    dev1=close-aDTR-p1*sdev
    dev2=close-aDTR-p2*sdev
    dev3=close-aDTR-p3*sdev
    dev4=close-aDTR-p4*sdev
    dev5=close-aDTR-p5*sdev
    
    if dev0<dev0[1] and close>dev5[1] then
    dev0=dev0[1]
    endif
    if dev1<dev1[1] and close>dev5[1] then
    dev1=dev1[1]
    endif
    if dev2<dev2[1] and close>dev5[1] then
    dev2=dev2[1]
    endif
    if dev3<dev3[1] and close>dev5[1] then
    dev3=dev3[1]
    endif
    if dev4<dev4[1] and close>dev5[1] then
    dev4=dev4[1]
    endif
    if dev5<dev5[1] and close>dev5[1] then
    dev5=dev5[1]
    endif
    
    dev6=close+aDTR
    dev7=close+aDTR+p1*sdev
    dev8=close+aDTR+p2*sdev
    dev9=close+aDTR+p3*sdev
    dev10=close+aDTR+p4*sdev
    dev11=close+aDTR+p5*sdev
    
    if dev6>dev6[1] and close<dev11[1] then
    dev6=dev6[1]
    endif
    if dev7>dev7[1] and close<dev11[1] then
    dev7=dev7[1]
    endif
    if dev8>dev8[1] and close<dev11[1] then
    dev8=dev8[1]
    endif
    if dev9>dev9[1] and close<dev11[1] then
    dev9=dev9[1]
    endif
    if dev10>dev10[1] and close<dev11[1] then
    dev10=dev10[1]
    endif
    if dev11>dev11[1] and close<dev11[1] then
    dev11=dev11[1]
    endif
    
    if close>dev11[1] then
    flag=-1
    else
    if close<dev5[1] then
    flag=1
    endif
    endif
    
    if flag=-1 then
    ind0=dev0
    ind1=dev1
    ind2=dev2
    ind3=dev3
    ind4=dev4
    ind5=dev5
    //k=1 Blue
    r=0
    g=191
    b=255
    else
    ind0=dev6
    ind1=dev7
    ind2=dev8
    ind3=dev9
    ind4=dev10
    ind5=dev11
    //k=-1 Orange
    r=255
    g=128
    b=0
    endif
    
    //ORIG return ind0 COLOURED BY k,ind1 coloured by k,ind2 coloured by k,ind3 coloured by k//
    
    //ORANGE AND LIGHT BLUE
    return ind0 coloured(r,g,b) style(dottedline,2) as "Warning Line", ind1 coloured(r,g,b) style(dottedline,2) as "Dev Stop 1.0", 
    ind2 coloured(r,g,b) style(dottedline,2) as "Dev Stop 2.2", ind3 coloured(r,g,b) style(line,2) as "Dev Stop 3.6", ind4 coloured(r,g,b) 
    style(dottedline,2) as "Dev Stop 4.5", ind5 coloured(r,g,b) style(line,2) as "Dev Stop 6.0"
    
    
    
    
    #123517 quote
    Bard
    Participant
    Master

    Hi @Nicolas, I was wondering could you please figure out why the buy signal occurred when it did and also why the sell signal is late? This applies to all the trades. Pls see my screenshot.

    The Trading System code is actually directly above this comment. I was trying to get this Fractal System to trade on the next bar after those yellow and blue fractal triangle signals appeared. Any ideas? This is a great indicator that Juanj has coded!

    Cheers and Stay safe,
    Bard

    #123555 quote
    Nicolas
    Keymaster
    Master

    Usual debugging routine:

    1. verify that you are using the same exact settings in both the strategy and the indicator applied on the chart
    2. GRAPH / GRAPHONEPRICE the variables (lines of your indicator) to verify they are the same as the one used on the price chart
    #123628 quote
    Bard
    Participant
    Master

    Thanks @Nicolas, I double checked indicator and system code, they’re both working off a shouldersize =5 variable. I have included the graphing function in the code using: https://www.prorealcode.com/blog/debugging-probuilder-graph-instruction/

    So I’ve tried many different attempts using different parts of the code like “FractalH” or “FractalD = -1 and FractalL ” in the graphing code (and my buy/sell code) — pls see code below — but I can never get the graph to line up with the blue and yellow triangles (or more importantly get the system to actually take trades AT those triangles! This is because I don’t understand the code well enough to be able to program it to take those trades and graph it at those exact blue and yellow triangle signals.

    I guess to a coder/programmer it is probably obvious. I get the basic premise that the code is searching for 5 day highs and lows dependent upon that “shouldersize = 5” variable, but don’t understand the line:
    SwingH = (r+1  (i.e. 11) ) and (FractalD = 0 or FractalD = -1) particularly the FractalD part?

    If FractalH (I also tried FractalH = high[ShoulderSize]) then
    signals = 1
    ELSE
    signals = -1
    ENDIF
    GRAPH signals AS "Fractal Signals"

    What code needs to be placed before that “buy 10 at market”  command to get it to enter the next bar after a blue or yellow triangle signal?

    Thanks again,

    #123736 quote
    Florian
    Participant
    Senior

    @Barde,

    Sorry  it’s impossible to add the KASE indicator in PRT for the test. Have YOU ITF ?

    Thank You

    Florian

    #123763 quote
    Bard
    Participant
    Master

    No worries, here you go @Florian: https://www.prorealcode.com/prorealtime-indicators/kase-dev-stop-v3/|

    It doesn’t matter if you add and use the non SAR version to the code because the issue I have isn’t the Exit it’s the Entry. Btw, what happens when you copy the SAR version I posted above?

    #123888 quote
    Nicolas
    Keymaster
    Master

    The fractals are marking tops and bottoms in the past. These points are obviously detected afterwards, that’s why your entries are “late”, they just open at the exact moment of when the fractals points are confirmed (later after the top or the bottom). I suggest you read about how the fractal are formed 😉

    Bard thanked this post
    #123937 quote
    Bard
    Participant
    Master

    “In order for a fractal to form, there should be a series of 5 consecutive bars where the middle bar will be the highest preceded and followed by two lower neighbouring bars on each side.” https://www.prorealcode.com/prorealtime-indicators/bill-williams-fractals/

    Right, got it! Thanks @Nicolas, I clearly need to take my Government prescribed daily dose of fresh air and exercise! 🤪 The shouldersize might be = 5, but “r” = shouldersize *2, so there is a 10 + 1 day formation with the highest or lowest candle in the middle of that pattern and not confirmed until the end of the last bar. I guess the only “solution” might be to go from the daily time frame and look at a 4 hour or 2 hour time frame to see if there is any “advance warning” of a top or bottom being formed but that’s not exactly going to always spot a daily formation.
    I still don’t understand the line: SwingH = (r+1) and (FractalD = 0 or FractalD = -1) particularly the FractalD part?
    That’s from Line 22 in this post: https://www.prorealcode.com/topic/ehlers-sinewave-indicator/page/2/#post-123494 How does the Fractal code know what FractalD = -1 is yet? It’s not been defined in the lines of code before line 22? Obviously it’s a conditionality (-1 or 1), so if, in Line 22, the Fractal identity is either 0 or -1 then a new high can be classified as FractalD = 1 but could you please explain this FractalD = -1 despite — not being defined yet — in layman’s terms though? Cheers,
    #123945 quote
    Nicolas
    Keymaster
    Master
    In this code, the FractalD  variable is the “direction” of the fractal, aka a top or a bottom. The code keep in memory the last formed fractal. In the first run the FractalD is not yet known, that’s why it also test if it is equal to 0 or 1/-1.
    Bard thanked this post
    #178483 quote
    Suzu Yuk
    Participant
    Average
Viewing 12 posts - 16 through 27 (of 27 total)
  • You must be logged in to reply to this topic.

Ehlers' Sinewave Indicator


ProBuilder: Indicators & Custom Tools

New Reply
Summary

This topic contains 26 replies,
has 1 voice, and was last updated by Suzu Yuk
4 years, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/19/2016
Status: Active
Attachments: 11 files
Logo Logo
Loading...