Calculating fibbonaci

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #120536 quote
    jebus89
    Participant
    Master

    Hi all im wondering how i can do the following:

    Calculate fibb, for example lets say “Close crosses under Fibb 50 level”

     

    What i want to do is something like:

    HH = Highest high variable1 bars ago

    LL = lowest low variable2 bars ago

    Fibb1: (HH-LL) * 0.5

    Fibb2: LL + fibb1

    return fibb2

     

    If we are trending upwards all is well, but if we are trending down, then HH comes before LL, and this causes problems.

    I need to tell the code something like:

    If LL happened 22 bars ago, then HH must be calculated from the past 21 bars ago (so that it comes AFTER LL has happened)

     

    How can i do this?

    #120550 quote
    jebus89
    Participant
    Master

    i tried this:

    once q = 1
    
    LL = lowest[50](low[1])
    HH = highest[q](high[1])
    
    if low crosses under LL then
    q = q+1
    endif
    
    if q >50 then
    q = 0
    endif
    
    o1 = HH - LL
    fibb1 = o1*0.5
    fibb2 = fibb1 + LL
    
    if close crosses under fibb2 then
    kk = 1
    elsif close > fibb2 or close < fibb2 then
    kk = 0
    endif
    
    return kk

    But i got the error message:

    “Error in the indicator: MyIndicator(30)

    A positive integer field is expected with HIGHEST”

     

    So im guessing i cant use a variable in the HIGHESt, it has to be a number?

    Any other way to do what i want to do?

    #120565 quote
    GraHal
    Participant
    Master

    You probably need the long awaited Arrays function to do it correctly?

    Have you tried recording / using the barindex when you get the LL / HH?

    For example …

    If (HHcondition) then
    MyHH = barindex
    Endif
    #120567 quote
    jebus89
    Participant
    Master

    Ive never seen this barindex, this might be the solution to my problems (?) would need to consult the holy PRT manual to see what barindex is and how to use it.

     

    If it dosnt work im guessing i need arrays?

     

    I have the same problem when trying to calculate “how many % the market has gone up”

     

    Say you want to calculate how far up the market has gone since the Lowest low past 100 bars.

     

    How can i calculate that? Same problem as with the fibb?

    #120568 quote
    robertogozzi
    Moderator
    Master

    Try removing ONCE from line 1, just write q = 1.

    This an indicator I wrote, where I am dealing with your problem with a FOR…NEXT loop:

    DEFPARAM CalculateOnLastBars = 300
    DEFPARAM DrawOnLastBarOnly   = True
    p       = 100
    HH      = highest[p](high)
    LL      = lowest[p](low)
    Diff    = HH - LL
    Fib0236 = Diff * 0.236
    Fib0382 = Diff * 0.382
    Fib0500 = Diff * 0.500
    Fib0618 = Diff * 0.618
    Fib0764 = Diff * 0.764
    Up     = 0
    Dn     = 0
    FOR i = 0 TO (p - 1)
       IF high[i] = HH THEN
          Up = 1
          BREAK
       ENDIF
       IF low[i] = LL THEN
          Dn = 1
          BREAK
       ENDIF
    NEXT
    DRAWHLINE(HH) coloured(238,122,233,255)//(0,128,0,255)
    DRAWHLINE(LL) coloured(238,122,233,255)//(0,128,0,255)
    IF Up THEN
       Fib0236 = HH - Fib0236
       Fib0382 = HH - Fib0382
       Fib0500 = HH - Fib0500
       Fib0618 = HH - Fib0618
       Fib0764 = HH - Fib0764
    ELSIF Dn THEN
       Fib0236 = LL + Fib0236
       Fib0382 = LL + Fib0382
       Fib0500 = LL + Fib0500
       Fib0618 = LL + Fib0618
       Fib0764 = LL + Fib0764
    ENDIF
    DRAWTEXT("                                      ------#Fib0236#---(23.6%)",barindex,Fib0236,SansSerif,Bold,10)coloured(238,122,233,255)
    DRAWTEXT("                                      ------#Fib0382#---(38.2%)",barindex,Fib0382,SansSerif,Bold,10)coloured(238,122,233,255)
    DRAWTEXT("                                      ------#Fib0500#---(50.0%)",barindex,Fib0500,SansSerif,Bold,10)coloured(238,122,233,255)
    DRAWTEXT("                                      ------#Fib0618#---(61.8%)",barindex,Fib0618,SansSerif,Bold,10)coloured(238,122,233,255)
    DRAWTEXT("                                      ------#Fib0764#---(76.4%)",barindex,Fib0764,SansSerif,Bold,10)coloured(238,122,233,255)
    RETURN
    jebus89 thanked this post
    #120573 quote
    GraHal
    Participant
    Master
    #120587 quote
    Nicolas
    Keymaster
    Master

    q= 0 at line 11, that’s why it fails to calculate the Highest with a null period at second run of the code (at 2nd bar or so)..

    #120609 quote
    jebus89
    Participant
    Master

    Big thanks guys, Roberto gave me the pieces i needed 🙂

     

    also thank you for links nicolas

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

Calculating fibbonaci


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jebus89 @jebus89 Participant
Summary

This topic contains 7 replies,
has 4 voices, and was last updated by jebus89
6 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/26/2020
Status: Active
Attachments: No files
Logo Logo
Loading...