ProRealCode - Trading & Coding with ProRealTime™
Hello,
I have written the code for previous day Fibonacci levels however can you please let me know how to put the “name tag” (as PRT does for Pivot lines) on top of the lines, e.g. it should write “1.618” on top of the line left justified.
Many thanks.
Sorry for double post since in the first instance I got WordPress Error.
When I am adding the below code then 1.618 is coming across the entire line repeatedly as enclosed.
voff=5*pipsize
DRAWTEXT("1.618", barindex,r11+voff, Dialog , Bold, 10) COLOURED(255,255,0)
If you ask it to draw at the close of every bar then that is what it will do!
Try enclosing the DRAWTEXT in an IF THEN so that it only draws when the value changes:
if r11 <> r11[1] then
voff=5*pipsize
DRAWTEXT(“1.618”, barindex,r11+voff, Dialog , Bold, 10) COLOURED(255,255,0)
endif
Note: Always use the ‘Insert PRT Code’ button when putting code in your posts – even if it is only a couple of lines of code as it makes it far easier for others to read. We like a tidy forum. I have edited your post.
Thank you Vonasi, however for some strange reason, the enclosed code is not printing the text.
Can you throw some light to it please?
Regards
D=DayOfWeek
if (D=2 or D=3 or D=4 or D=5) then
H1=DHigh(1)
elsif (D=1) then
H1=DHigh(1)
endif
if (D=2 or D=3 or D=4 or D=5) then
L1=DLow(1)
elsif (D=1) then
L1=DLow(1)
endif
if (D=2 or D=3 or D=4 or D=5) then
C1=DClose(1)
elsif D=1 then
C1=DClose(2)
endif
if (D=2 or D=3 or D=4 or D=5) then
O=DOpen(0)
elsif D=1 then
O=DOpen(1)
endif
r=h1-l1
R236=L1+R*0.236
R382=L1+R*0.382
R50=L1+R*0.5
r6=l1+r*0.618
r7=l1+r*.786
r1=l1+r*1.272
r11=l1+r*1.618
R22=L1+R*2
R2618=L1+R*2.618
R33=L1+R*3.33
DH=H1-r*1
DL=H1-r*0
Lr1=H1-r*1.272
L11=H1-r*1.618
L22=H1-R*2
L2618=H1-R*2.618
L33=H1-R*3.33
WPH=(H1+L1+C1)*2/3-H1
WPL=(H1+L1+C1)*2/3-L1
P=H1+L1+C1
if O>C1 then
X=(P+H1)/2
elsif O<C1 then
X=(P+L1)/2
elsif O=C1 then
X=(P+C1)/2
endif
DPH=X-L1
DPL=X-H1
IF R11<>R11[1] THEN
voff=5*pipsize
DRAWTEXT("1.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R236<>R236[1] THEN
voff=5*pipsize
DRAWTEXT("0.236", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R382<>R382[1] THEN
voff=5*pipsize
DRAWTEXT("0.382", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R50<>R50[1] THEN
voff=5*pipsize
DRAWTEXT("0.5", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R6<>R6[1] THEN
voff=5*pipsize
DRAWTEXT("0.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R7<>R7[1] THEN
voff=5*pipsize
DRAWTEXT("0.786", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R1<>R1[1] THEN
voff=5*pipsize
DRAWTEXT("1.272", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R22<>R22[1] THEN
voff=5*pipsize
DRAWTEXT("2.0", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R2618<>R2618[1] THEN
voff=5*pipsize
DRAWTEXT("2.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF R33<>R33[1] THEN
voff=5*pipsize
DRAWTEXT("3.33", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF DH<>DH[1] THEN
voff=5*pipsize
DRAWTEXT("DH", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ELSIF DL<>DL[1] THEN
voff=5*pipsize
DRAWTEXT("DL", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF LR1<>LR1[1] THEN
voff=5*pipsize
DRAWTEXT(" - 1.272", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L11<>L11[1] THEN
voff=5*pipsize
DRAWTEXT(" - 1.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L22<>L22[1] THEN
voff=5*pipsize
DRAWTEXT(" - 2.0", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L2618<>L2618[1] THEN
voff=5*pipsize
DRAWTEXT(" - 2.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L33<>L33[1] THEN
voff=5*pipsize
DRAWTEXT(" - 3.33", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF DPH<>DPH[1] THEN
voff=5*pipsize
DRAWTEXT("DPRH", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF DPL<>DPL[1] THEN
voff=5*pipsize
DRAWTEXT("DPRL", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF WPH<>WPH[1] THEN
voff=5*pipsize
DRAWTEXT("WPRH", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF WPL<>WPL[1] THEN
voff=5*pipsize
DRAWTEXT("WPRL", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
RETURN WPH AS "WPRH", DPH AS "DPRH", WPL AS "WPRL", DPL AS "DPRL", R236 AS "0.236", R382 AS "0.382", R50 AS "0.5", r6 as "0.618", r7 as "0.786", r1 as "1.272", r11 as "1.618", R22 AS "2", R2618 AS "2.618", R33 AS "3.33", LR1 AS "-1.272", L11 AS "-1.618", L22 AS "-2", L2618 AS "-2.618", L33 AS "-3.33", DH AS "DL", DL AS "DH"
Good Morning
You forgot to change the target according to the bar index has always been r11 for you.
D=DayOfWeek
if (D=2 or D=3 or D=4 or D=5) then
H1=DHigh(1)
elsif (D=1) then
H1=DHigh(1)
endif
if (D=2 or D=3 or D=4 or D=5) then
L1=DLow(1)
elsif (D=1) then
L1=DLow(1)
endif
if (D=2 or D=3 or D=4 or D=5) then
C1=DClose(1)
elsif D=1 then
C1=DClose(2)
endif
if (D=2 or D=3 or D=4 or D=5) then
O=DOpen(0)
elsif D=1 then
O=DOpen(1)
endif
r=h1-l1
R236=L1+R*0.236
R382=L1+R*0.382
R50=L1+R*0.5
r6=l1+r*0.618
r7=l1+r*.786
r1=l1+r*1.272
r11=l1+r*1.618
R22=L1+R*2
R2618=L1+R*2.618
R33=L1+R*3.33
DH=H1-r*1
DL=H1-r*0
Lr1=H1-r*1.272
L11=H1-r*1.618
L22=H1-R*2
L2618=H1-R*2.618
L33=H1-R*3.33
WPH=(H1+L1+C1)*2/3-H1
WPL=(H1+L1+C1)*2/3-L1
P=H1+L1+C1
if O>C1 then
X=(P+H1)/2
elsif O<C1 then
X=(P+L1)/2
elsif O=C1 then
X=(P+C1)/2
endif
DPH=X-L1
DPL=X-H1
IF R11<>R11[1] THEN
voff=5*pipsize
DRAWTEXT("1.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R236<>R236[1] THEN
voff=5*pipsize
DRAWTEXT("0.236", barindex,r236+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R382<>R382[1] THEN
voff=5*pipsize
DRAWTEXT("0.382", barindex,r382+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R50<>R50[1] THEN
voff=5*pipsize
DRAWTEXT("0.5", barindex,r50+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R6<>R6[1] THEN
voff=5*pipsize
DRAWTEXT("0.618", barindex,r6+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
IF R7<>R7[1] THEN
voff=5*pipsize
DRAWTEXT("0.786", barindex,r7+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R1<>R1[1] THEN
voff=5*pipsize
DRAWTEXT("1.272", barindex,r1+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R22<>R22[1] THEN
voff=5*pipsize
DRAWTEXT("2.0", barindex,r22+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R2618<>R2618[1] THEN
voff=5*pipsize
DRAWTEXT("2.618", barindex,r2618+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If R33<>R33[1] THEN
voff=5*pipsize
DRAWTEXT("3.33", barindex,r33+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If DH<>DH[1] THEN
voff=5*pipsize
DRAWTEXT("DH", barindex,DH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
endif
If DL<>DL[1] THEN
voff=5*pipsize
DRAWTEXT("DL", barindex,DL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF LR1<>LR1[1] THEN
voff=5*pipsize
DRAWTEXT(" - 1.272", barindex,LR1+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L11<>L11[1] THEN
voff=5*pipsize
DRAWTEXT(" - 1.618", barindex,L11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L22<>L22[1] THEN
voff=5*pipsize
DRAWTEXT(" - 2.0", barindex,L22+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L2618<>L2618[1] THEN
voff=5*pipsize
DRAWTEXT(" - 2.618", barindex,L2618+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF L33<>L33[1] THEN
voff=5*pipsize
DRAWTEXT(" - 3.33", barindex,L33+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF DPH<>DPH[1] THEN
voff=5*pipsize
DRAWTEXT("DPRH", barindex,DPH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF DPL<>DPL[1] THEN
voff=5*pipsize
DRAWTEXT("DPRL", barindex,DPL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF WPH<>WPH[1] THEN
voff=5*pipsize
DRAWTEXT("WPRH", barindex,WPH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
IF WPL<>WPL[1] THEN
voff=5*pipsize
DRAWTEXT("WPRL", barindex,WPL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
RETURN WPH AS "WPRH", DPH AS "DPRH", WPL AS "WPRL", DPL AS "DPRL", R236 AS "0.236", R382 AS "0.382", R50 AS "0.5", r6 as "0.618", r7 as "0.786", r1 as "1.272", r11 as "1.618", R22 AS "2", R2618 AS "2.618", R33 AS "3.33", LR1 AS "-1.272", L11 AS "-1.618", L22 AS "-2", L2618 AS "-2.618", L33 AS "-3.33", DH AS "DL", DL AS "DH"
Apart from the text drawing y value that Razz corrected and the ELSIFs that should have been ENDIFs there is an awful lot of code that is not needs that really slows down the calculation time. Plus you only need to do the calculations once when the day changes.
Here is the code tidied up:
D=openDayOfWeek
if d <> d[1] then
if (D=2 or D=3 or D=4 or D=5) then
H1=DHigh(1)
L1=DLow(1)
C1=DClose(1)
O=DOpen(0)
elsif (D=1) then
H1=DHigh(1)
L1=DLow(1)
C1=DClose(2)
O=DOpen(1)
endif
r=h1-l1
R236=L1+R*0.236
R382=L1+R*0.382
R50=L1+R*0.5
r6=l1+r*0.618
r7=l1+r*.786
r1=l1+r*1.272
r11=l1+r*1.618
R22=L1+R*2
R2618=L1+R*2.618
R33=L1+R*3.33
DH=H1-r*1
DL=H1-r*0
Lr1=H1-r*1.272
L11=H1-r*1.618
L22=H1-R*2
L2618=H1-R*2.618
L33=H1-R*3.33
WPH=(H1+L1+C1)*2/3-H1
WPL=(H1+L1+C1)*2/3-L1
P=H1+L1+C1
if O>C1 then
X=(P+H1)/2
elsif O<C1 then
X=(P+L1)/2
elsif O=C1 then
X=(P+C1)/2
endif
DPH=X-L1
DPL=X-H1
voff=5*pipsize
DRAWTEXT("1.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.236", barindex,r236+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.382", barindex,r382+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.5", barindex,r50+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.618", barindex,r6+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.786", barindex,r7+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("1.272", barindex,r1+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("2.0", barindex,r22+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("2.618", barindex,r2618+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("3.33", barindex,r33+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DH", barindex,DH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DL", barindex,DL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 1.272", barindex,LR1+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 1.618", barindex,L11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 2.0", barindex,L22+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 2.618", barindex,L2618+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 3.33", barindex,L33+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DPRH", barindex,DPH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DPRL", barindex,DPL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("WPRH", barindex,WPH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("WPRL", barindex,WPL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
RETURN WPH AS "WPRH", DPH AS "DPRH", WPL AS "WPRL", DPL AS "DPRL", R236 AS "0.236", R382 AS "0.382", R50 AS "0.5", r6 as "0.618", r7 as "0.786", r1 as "1.272", r11 as "1.618", R22 AS "2", R2618 AS "2.618", R33 AS "3.33", LR1 AS "-1.272", L11 AS "-1.618", L22 AS "-2", L2618 AS "-2.618", L33 AS "-3.33", DH AS "DL", DL AS "DH"
Also I’m not sure what you are trying to achieve with the first bit of code that sets the O H L C values. If it is to include Sunday data in with Monday data then you need to do it like this:
D=openDayOfWeek
if d <> d[1] then
if (D=2 or D=3 or D=4 or D=5) then
H1=DHigh(1)
L1=DLow(1)
C1=DClose(1)
O=DOpen(1)
elsif (D=1) then
H1=max(DHigh(1),dHigh(2))
L1=min(DLow(1),dLow(2))
C1=DClose(1)
O=DOpen(2)
endif
r=h1-l1
R236=L1+R*0.236
R382=L1+R*0.382
R50=L1+R*0.5
r6=l1+r*0.618
r7=l1+r*.786
r1=l1+r*1.272
r11=l1+r*1.618
R22=L1+R*2
R2618=L1+R*2.618
R33=L1+R*3.33
DH=H1-r*1
DL=H1-r*0
Lr1=H1-r*1.272
L11=H1-r*1.618
L22=H1-R*2
L2618=H1-R*2.618
L33=H1-R*3.33
WPH=(H1+L1+C1)*2/3-H1
WPL=(H1+L1+C1)*2/3-L1
P=H1+L1+C1
if O>C1 then
X=(P+H1)/2
elsif O<C1 then
X=(P+L1)/2
elsif O=C1 then
X=(P+C1)/2
endif
DPH=X-L1
DPL=X-H1
voff=5*pipsize
DRAWTEXT("1.618", barindex,r11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.236", barindex,r236+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.382", barindex,r382+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.5", barindex,r50+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.618", barindex,r6+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("0.786", barindex,r7+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("1.272", barindex,r1+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("2.0", barindex,r22+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("2.618", barindex,r2618+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("3.33", barindex,r33+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DH", barindex,DH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DL", barindex,DL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 1.272", barindex,LR1+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 1.618", barindex,L11+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 2.0", barindex,L22+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 2.618", barindex,L2618+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT(" - 3.33", barindex,L33+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DPRH", barindex,DPH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("DPRL", barindex,DPL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("WPRH", barindex,WPH+voff, Dialog , Bold, 18) COLOURED(255,255,0)
DRAWTEXT("WPRL", barindex,WPL+voff, Dialog , Bold, 18) COLOURED(255,255,0)
ENDIF
RETURN WPH AS "WPRH", DPH AS "DPRH", WPL AS "WPRL", DPL AS "DPRL", R236 AS "0.236", R382 AS "0.382", R50 AS "0.5", r6 as "0.618", r7 as "0.786", r1 as "1.272", r11 as "1.618", R22 AS "2", R2618 AS "2.618", R33 AS "3.33", LR1 AS "-1.272", L11 AS "-1.618", L22 AS "-2", L2618 AS "-2.618", L33 AS "-3.33", DH AS "DL", DL AS "DH"
Many thanks to both of you dear.
Vonasi you are a Legend. Special thanks to you.
@ Vonasi
what should the code OHLC be if you want to work with the values from Friday on Mondays?
thank you
Yes – looking at it after another coffee even my code is not quite right!
Change the OHLC code to the following and on Sundays and Mondays it bases the calculations on Fridays data and on Tuesdays it bases the calculations on Sunday and Monday’s data:
if d <> d[1] then
if (D=0 or D=3 or D=4 or D=5) then
H1=DHigh(1)
L1=DLow(1)
C1=DClose(1)
O=DOpen(1)
elsif (D=2) then
H1=max(DHigh(1),dHigh(2))
L1=min(DLow(1),dLow(2))
C1=DClose(1)
O=DOpen(2)
endif
Thanks for the quick implementation I am curious to see if it works on Monday.
Many thanks again to the legends!!
It seems the previous code is returning better results and new code is returning wrong levels as captured in the enclosed doc.
What say?
please use image file formats (jpg, png) when attaching pics and PDF or TXT file formats when attaching text.
Thank you 🙂
What should be the format if it is a combination of text and image? I presume it would be pdf, correct?
Display Line Name of Fibonacci Lines
This topic contains 23 replies,
has 4 voices, and was last updated by Vonasi
5 years, 8 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 05/28/2020 |
| Status: | Active |
| Attachments: | 7 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.