Pivots scripts
Pivots scripts
Hi everyone,
There are quite a few Pivot scripts available for Wve59, but all of them connect horizontal pivot levels between days with vertical line.
Since my scripting abilities are bad, I wanted to ask if someone knows how to get rid of connecting vertical lines and draw actual pivot levels only.
Thanks,
Simon
There are quite a few Pivot scripts available for Wve59, but all of them connect horizontal pivot levels between days with vertical line.
Since my scripting abilities are bad, I wanted to ask if someone knows how to get rid of connecting vertical lines and draw actual pivot levels only.
Thanks,
Simon
Re: Pivots scripts
Hi Simon,
If you have a script you like, but just want to alter it, that could be done. There's a plot style called "ps_clear", which is basically invisible. At the bar at the end of the day, you can change your plot style from "ps_solid" (the default) to ps_clear, and then change it back to ps_solid on the first bar of the next day. The effect will be that the lines aren't connecting, and will look more like floating trendlines. It would look like this:
So what I did was check to see if the day on the very next bar is the same as the day on the current bar (day != day[-1]), and if it was different, switch to ps_clear, otherwise just go with the regular ps_solid;
The other workaround is to use trendlines instead of plot1, plot2, etc. That's a little trickier because you have to figure out the right numbers of bar in the day for your chart, but a helpful keyword in that case is bars_per_day. So if you compute your pivots on the first bar of the day, you can draw trendlines in right then that stretch the entire length of the day. That would be like:
Either way should work. If you get stuck, you can always post your code to the qscript forum and we'll help. If you're concerned about your calculation method, just replace it with something basic to get the plotting solved, then put it back in once that's fixed.
Earik
If you have a script you like, but just want to alter it, that could be done. There's a plot style called "ps_clear", which is basically invisible. At the bar at the end of the day, you can change your plot style from "ps_solid" (the default) to ps_clear, and then change it back to ps_solid on the first bar of the next day. The effect will be that the lines aren't connecting, and will look more like floating trendlines. It would look like this:
Code: Select all
my_pivot_level = <whatever you calculate in your script>;
plot1 = my_pivot_level;
if (day != day[-1]) {
style1 = ps_clear;
}
else {
style1 = ps_solid;
}
The other workaround is to use trendlines instead of plot1, plot2, etc. That's a little trickier because you have to figure out the right numbers of bar in the day for your chart, but a helpful keyword in that case is bars_per_day. So if you compute your pivots on the first bar of the day, you can draw trendlines in right then that stretch the entire length of the day. That would be like:
Code: Select all
if (day != day[1]) # this is first bar of the day
{
pivotlevel = <do your calculation here>;
ref = trendline(barnum, pivotlevel, barnum + bars_per_day, pivotlevel, red);
}
Earik
Re: Pivots scripts
Hi Earik,
Thanks for quick reply. I tried first option, but it is stil printing vertical lines. Please take a look at the script below.
input:piv_color(black),s1_color(red),r1_color(lime),s2_color(fuchsia),r2_color(aqua),
s3_color(silver),r3_color(silver),thickness(1);
if (barnum==barsback) {
dayhi,daylo=0;
fullday=false;
}
if (day!=day[1]) {
piv=(dayhi+daylo+close[1])/3;
diff=dayhi-daylo;
s1=2*piv-dayhi;
r1=2*piv-daylo;
s2=piv-diff;
r2=piv+diff;
s3=s2-piv-s1;
r3=r1-piv+r2;
dayhi=h;
daylo=l;
fullday=true;
}
if (h>dayhi) dayhi=h;
if (l<daylo) daylo=l;
if (fullday==true) {
plot1=piv;
if (day != day[-1]) {
style1 = ps_clear;
}
else {
style1 = ps_solid;
}
color1=piv_color;
plot2=s1;
color2=s1_color;
plot3=r1;
color3=r1_color;
plot4=s2;
color4=s2_color;
plot5=r2;
color5=r2_color;
plot6=s3;
color6=s3_color;
plot7=r3;
color7=r3_color;
thickness1, thickness2, thickness3, thickness4,
thickness5, thickness6, thickness7=thickness;
}
Thanks
Simon
Thanks for quick reply. I tried first option, but it is stil printing vertical lines. Please take a look at the script below.
input:piv_color(black),s1_color(red),r1_color(lime),s2_color(fuchsia),r2_color(aqua),
s3_color(silver),r3_color(silver),thickness(1);
if (barnum==barsback) {
dayhi,daylo=0;
fullday=false;
}
if (day!=day[1]) {
piv=(dayhi+daylo+close[1])/3;
diff=dayhi-daylo;
s1=2*piv-dayhi;
r1=2*piv-daylo;
s2=piv-diff;
r2=piv+diff;
s3=s2-piv-s1;
r3=r1-piv+r2;
dayhi=h;
daylo=l;
fullday=true;
}
if (h>dayhi) dayhi=h;
if (l<daylo) daylo=l;
if (fullday==true) {
plot1=piv;
if (day != day[-1]) {
style1 = ps_clear;
}
else {
style1 = ps_solid;
}
color1=piv_color;
plot2=s1;
color2=s1_color;
plot3=r1;
color3=r1_color;
plot4=s2;
color4=s2_color;
plot5=r2;
color5=r2_color;
plot6=s3;
color6=s3_color;
plot7=r3;
color7=r3_color;
thickness1, thickness2, thickness3, thickness4,
thickness5, thickness6, thickness7=thickness;
}
Thanks
Simon
Re: Pivots scripts
Hi Simon,
Thanks for sharing the code. I made a mistake writing that last section off the top of my head, which is part of the problem. Should be day!=day[1], rather than day[-1].
The other part is that you have to set the style for all the plots, in your case 7 of them. So if you change it to this...
...then it should work. I've built it on my end just to make sure, and it looks good.
Check it out and let me know if that doesn't get you going.
Earik
Thanks for sharing the code. I made a mistake writing that last section off the top of my head, which is part of the problem. Should be day!=day[1], rather than day[-1].
![Embarrassed :oops:](./images/smilies/icon_redface.gif)
Code: Select all
if (day!=day[1]) {
style1, style2, style3, style4, style5, style6, style7 = ps_clear;
}
else {
style1, style2, style3, style4, style5, style6, style7 = ps_solid;
}
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Earik
Re: Pivots scripts
Hi Earik,
That did the job, looks good !!!
Thanks a lot,
Simon
That did the job, looks good !!!
Thanks a lot,
Simon
Re: Pivots scripts
Here's another template for plotting pivot levels that lets the user select the open as a term also. It's flexible--you can add all sorts of things, don't have to use those canned pivot calcs, can develop modular transforms if you are so inclined, stuff like that.
Earik, how do get those nice looking box formats for posting code that you used here?
Todd
#Flexible script for plotting pivot levels.
Input:pivot_color(white),s1_color(aqua),r1_color(black), thickness(1);
IF (barnum == barsback)
{
startbar,endbar=barnum;
bpd= bars_per_day;
}
IF (day[-1]!= day )
{
myclose=close;myhigh=high;mylow=low;myopen=open[bars_per_day-1];
startbar=barnum+1;endbar=barnum+bpd+1;
For (i=-1 to bpd-1 by 1)
{
IF(low<mylow)mylow=low;
IF (high>myhigh)myhigh=high;
}
pivot=(myclose+mylow+myhigh)/3;
s1=(2*pivot)-myhigh;
r1=(2*pivot)-mylow;
# etc.
}
If ((startbar>=10) and (endbar>startbar))
{
ref1=trendline(startbar,pivot,endbar,pivot,pivot_color);
ref2=trendline(startbar,s1,endbar,s1,s1_color);
ref3=trendline(startbar,r1,endbar,r1,r1_color);
#etc.
}
Earik, how do get those nice looking box formats for posting code that you used here?
Todd
#Flexible script for plotting pivot levels.
Input:pivot_color(white),s1_color(aqua),r1_color(black), thickness(1);
IF (barnum == barsback)
{
startbar,endbar=barnum;
bpd= bars_per_day;
}
IF (day[-1]!= day )
{
myclose=close;myhigh=high;mylow=low;myopen=open[bars_per_day-1];
startbar=barnum+1;endbar=barnum+bpd+1;
For (i=-1 to bpd-1 by 1)
{
IF(low<mylow)mylow=low;
IF (high>myhigh)myhigh=high;
}
pivot=(myclose+mylow+myhigh)/3;
s1=(2*pivot)-myhigh;
r1=(2*pivot)-mylow;
# etc.
}
If ((startbar>=10) and (endbar>startbar))
{
ref1=trendline(startbar,pivot,endbar,pivot,pivot_color);
ref2=trendline(startbar,s1,endbar,s1,s1_color);
ref3=trendline(startbar,r1,endbar,r1,r1_color);
#etc.
}
Re: Pivots scripts
Hey Todd,
Thanks for sharing the script. To get the code formatting, click the button just above the box where you type your replies:
Earik
Thanks for sharing the script. To get the code formatting, click the button just above the box where you type your replies:
Earik
Re: Pivots scripts
Thanks, Earik.
Since we're talking about pivots, I've been stuck with a more generalized pivot scripting question. Is there a way to convert absolute price (such as measured by say, the W59 price counter) to bar numbers for charting time projections? I'm not referring to the actual techniques, just an open ended scripting solution with two hotspots for a selected H/L. Time to time, price to price, no problem. Price to barcount, a problem.
Todd
Since we're talking about pivots, I've been stuck with a more generalized pivot scripting question. Is there a way to convert absolute price (such as measured by say, the W59 price counter) to bar numbers for charting time projections? I'm not referring to the actual techniques, just an open ended scripting solution with two hotspots for a selected H/L. Time to time, price to price, no problem. Price to barcount, a problem.
Todd
Re: Pivots scripts
Hi Todd,
You'd have to write one that performed the calculation. If you are talking about converting a high-low range to bars, you could do it with trendlines. So:
Is that what you meant?
Full disclosure: I wrote this off the top of my head, so there may be typos in there.
Hopefully you get the gist of it though! Obviously, there are ways to clean this up, like using vertical trendlines for time projections, etc. I didn't want to get too fancy before understanding what you were trying to do though.
Earik
You'd have to write one that performed the calculation. If you are talking about converting a high-low range to bars, you could do it with trendlines. So:
Code: Select all
if (barnum == barsback)
{
# get the prices, and a starting point
price1 = hotspot_to_price(1);
price2 = hotspot_to_price(2);
bar1 = hotspot_to_bar(1);
bar2 = hotspot_to_bar(2);
#connect the price values
ref = trendline(bar1,price1,bar2,price2,red);
#convert to time
time_count = abs(price1-price2); # this is straight points-to-bars
#plot time, from bar2 as starting point
ref = trendline(bar2,price2,bar2+time_count,price2,red);
}
Full disclosure: I wrote this off the top of my head, so there may be typos in there.
![Wink ;)](./images/smilies/icon_e_wink.gif)
Earik
Re: Pivots scripts
Hi Earik,
Yes, that does the trick. I was stuck on that "plot time" routine. Just a matter of putting things together now. Thanks!
Todd
Yes, that does the trick. I was stuck on that "plot time" routine. Just a matter of putting things together now. Thanks!
Todd
Who is online
Users browsing this forum: No registered users and 1 guest