Calculating fibbonaci
Forums › ProRealTime English forum › ProOrder support › Calculating fibbonaci
- This topic has 7 replies, 4 voices, and was last updated 5 years ago by
jebus89.
-
-
02/26/2020 at 10:33 AM #120536
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?
02/26/2020 at 12:54 PM #120550i tried this:
123456789101112131415161718192021222324once q = 1LL = lowest[50](low[1])HH = highest[q](high[1])if low crosses under LL thenq = q+1endifif q >50 thenq = 0endifo1 = HH - LLfibb1 = o1*0.5fibb2 = fibb1 + LLif close crosses under fibb2 thenkk = 1elsif close > fibb2 or close < fibb2 thenkk = 0endifreturn kkBut 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?
02/26/2020 at 1:34 PM #12056502/26/2020 at 1:36 PM #120567Ive 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?
02/26/2020 at 1:38 PM #120568Try 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:
1234567891011121314151617181920212223242526272829303132333435363738394041424344DEFPARAM CalculateOnLastBars = 300DEFPARAM DrawOnLastBarOnly = Truep = 100HH = highest[p](high)LL = lowest[p](low)Diff = HH - LLFib0236 = Diff * 0.236Fib0382 = Diff * 0.382Fib0500 = Diff * 0.500Fib0618 = Diff * 0.618Fib0764 = Diff * 0.764Up = 0Dn = 0FOR i = 0 TO (p - 1)IF high[i] = HH THENUp = 1BREAKENDIFIF low[i] = LL THENDn = 1BREAKENDIFNEXTDRAWHLINE(HH) coloured(238,122,233,255)//(0,128,0,255)DRAWHLINE(LL) coloured(238,122,233,255)//(0,128,0,255)IF Up THENFib0236 = HH - Fib0236Fib0382 = HH - Fib0382Fib0500 = HH - Fib0500Fib0618 = HH - Fib0618Fib0764 = HH - Fib0764ELSIF Dn THENFib0236 = LL + Fib0236Fib0382 = LL + Fib0382Fib0500 = LL + Fib0500Fib0618 = LL + Fib0618Fib0764 = LL + Fib0764ENDIFDRAWTEXT(" ------#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)RETURN1 user thanked author for this post.
02/26/2020 at 2:05 PM #120573Ive never seen this barindex
https://www.prorealcode.com/documentation/barindex/
Tradeindex also …
https://www.prorealcode.com/documentation/tradeindex/
02/26/2020 at 4:42 PM #12058702/26/2020 at 8:35 PM #120609 -
AuthorPosts
