Drawing fibonacci levels not based on a period

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #105941 quote
    stefou102
    Participant
    Veteran

    Hello,

    The common way to code fibonacci level is to take the high/low over a past period, lets say 1000 units, or 10 days, or whatever. The issue with this approch is that

    1. You never know if the relevant high/low is within your period
    2. The fibo that you have drawn has maybe already play its role (a retracement has occured) and news levels should be used.

     

    So I’m looking for a way to remove this fixed period, by using a rule. The rule is “if there has been a retracement greater than 50%, and then afterwards the market turns again and break the 50% level again, then a new fibo should be drawn”. I have attached an exemple on the Dax TF4H. Three fibos can be drawn successfully, first the blue, then the red, and finally the white. It means that the fibo which is now relevant is the white one, the two other can be deleted. This is in opposition with the common way to drawn it (11265-11990 vs 11572-11990).

    I have reused  a code of Nicolas, but I struggle to

    1. Add a loop which will takes first the highest high /lowest low, then move to the next high/low if there has been a retracement
    2. I need to add a way via zigzag or anything else to check if we break again the 50%.

     

    Sorry I’m a bit in a rush, but looking forward your advice

     

    defparam drawonlastbaronly=true
    
    ONCE startbar=0
    ONCE hh=0
    ONCE ll=1000000000
    ONCE shifthighest=0
    ONCE shiftlowest=0
    
    
    
    //shiftlowest=barindex
    for i = 1000-startbar downto 1 do
    if high[i]>=hh  then
    hh=high[i]
    shifthighest=barindex[i]
    endif
    if low[i]<=ll then
    ll=low[i]
    shiftlowest=barindex[i]
    endif
    next
    
    
    //
    isSwingDown = shiftHighest < shiftLowest
    
    if isSwingDown then
    fullrange = abs(hh-ll)
    fibo100 = hh
    fibo0 = ll
    fibo236 = ll+(fullrange*0.236)
    fibo382 = ll+(fullrange*0.382)
    fibo50 = ll+fullrange/2
    fibo618 = ll+(fullrange*0.618)
    startbar1 = min(shifthighest,shiftlowest)
    endbar=max(shifthighest,shiftlowest)
    r=255
    g=0
    b=0
    else
    fullrange = abs(hh-ll)
    fibo100 = ll
    fibo0 = hh
    fibo236 = hh-(fullrange*0.236)
    fibo382 = hh-(fullrange*0.382)
    fibo50 = hh-fullrange/2
    fibo618 = hh-(fullrange*0.618)
    startbar1 = min(shifthighest,shiftlowest)
    endbar=max(shifthighest,shiftlowest)
    r=0
    g=255
    b=0
    endif
    
    
    if not isSwingDown then
    blockprice=hh
    startbar=barindex-shifthighest
    for i = startbar downto 1 do
    if low[i]<blockprice then
    blockprice=low[i]
    //blockbar=barindex[i]
    endif
    next
    
    if blockprice<fibo50 then
    startbar=shifthighest
    
    endif
    
    else
    blockprice=ll
    startbar=barindex-shiftlowest
    for i = startbar downto 1 do
    if high[i]>blockprice then
    blockprice=high[i]
    
    endif
    
    next
    
    if blockprice>fibo50 then
    startbar=shiftlowest
    endif
    endif
    //
    
    
    
    drawsegment(startbar1,fibo100,endbar,fibo100) coloured(r,g,b)
    drawtext("          100%",endbar,fibo100,Dialog,Standard,20) coloured(r,g,b)
    drawsegment(startbar1,fibo0,endbar,fibo0) coloured(r,g,b)
    drawtext("          0%",endbar,fibo0,Dialog,Standard,20) coloured(r,g,b)
    drawsegment(startbar1,fibo236,endbar,fibo236) coloured(r,g,b)
    drawtext("          23.6%",endbar,fibo236,Dialog,Standard,20) coloured(r,g,b)
    drawsegment(startbar1,fibo382,endbar,fibo382) coloured(r,g,b)
    drawtext("          38.2%",endbar,fibo382,Dialog,Standard,20) coloured(r,g,b)
    drawsegment(startbar1,fibo50,endbar,fibo50) coloured(r,g,b)
    drawtext("          50%",endbar,fibo50,Dialog,Standard,20) coloured(r,g,b)
    drawsegment(startbar1,fibo618,endbar,fibo618) coloured(r,g,b)
    drawtext("          61.8%",endbar,fibo618,Dialog,Standard,20) coloured(r,g,b)
    
    return
    
    BullFlag thanked this post
    Capture-1.png Capture-1.png
    #105950 quote
    Vonasi
    Moderator
    Master

    stefou102 – Perhaps it is better to only post topics when you are not in such a rush!

    Surely pressing the return button and using shift to get a capital letter or two wouldn’t have taken too much extra time and would have made your post actually readable. I’ve edited it and inserted your numbered points in a more readable way. 🙂

    #105952 quote
    stefou102
    Participant
    Veteran

    Yes you right Vonasi my apologies…thx for making it clearer. My girlfriend was yielding at me to go out so I had to finish a bit in a hurry

    #106199 quote
    Nicolas
    Keymaster
    Master

    Sorry but is this code is already working or .. ? These 3 successful plotted fibos zones were made by the indicator or by hands?

    #146120 quote
    Copperwave
    Participant
    Veteran

    Hi Guys – I see this has been quietly gathering dust till I stumbled upon it. The code above only does one pass. The graphic is hand drawn. I do this manually (it is my go-to trading strategy) but having the platform identify the 50/61.8% fib levels in this manner, (i.e not bar based but price action based) would be very useful.

    Best regards

    //Copperwave

    #146142 quote
    Nicolas
    Keymaster
    Master

    In understand, but what tops and bottoms to use in order to plot the first High/Low levels retracement?

    #146257 quote
    Copperwave
    Participant
    Veteran

    Hmmm, good question…I think the problem is we are using lagging logic to try and identify leading levels. Is there a hybrid approach that could work?

    Lets say the largest (initial) high/low is found somewhere in the last 50~100 bars and we are looking for a retracement for a long. If price retraces under then over the 50% of the initial range, (but doesn’t exceed the 61.8% or 76.4% levels) the swing low/high created by this price action becomes the next fib range…all subsequent fib ranges are indexed off this initial fib range. If the 76.4% levels do get broken, then this starts a new fib high/low in the opposite direction.

    I hope this makes sense. In the graphic above, the first fib range (in blue) could be anywhere (n) bars back but if the retracement was valid there would be other ones following it (well I suppose at least 1)…It is almost like using your 61.8% retracement indicator but nesting or looping additional ones off of it…(if only I could code…!!).

    BR

    //Copperwave

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

Drawing fibonacci levels not based on a period


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
stefou102 @stefou102 Participant
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by Copperwave
5 years, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/30/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...