Page 2 of 2

Re: Pivots scripts

Posted: Wed Mar 20, 2019 6:37 pm
by abacaba
Yikes -- I accidentally posted an early draft version of my pivot script above. So, switch out this portion of the code:

endbar=barnum+bpd+1;
For (i=-1 to bpd-1 by 1)
{
IF(low<mylow)mylow=low;
IF (high>myhigh)myhigh=high;
}

with this

Code: Select all

endbar=barnum+bpd;                       
For (i=1 to bpd-1 by 1)
{
IF(low[i]<mylow)mylow=low[i];
IF (high[i]>myhigh)myhigh=high[i];
}
and you will be good to go. Hope I haven't caused to many headaches.

Earik, while we're still on the subject of intraday pivots, is there a way to display only the levels for the current day, and exclude preceding days?

Todd

Re: Pivots scripts

Posted: Thu Mar 21, 2019 6:26 pm
by earik
Hi Todd,

The best way to do that is to use trendlines as the pivot lines rather than plot1/plot2/etc. You would draw them in the first bar of the day, and you would also erase any old ones. That way the pivot lines are only active on the most recent day. The trick is that you have to save all of your trendline handles somewhere (arrays work well) so that you can refer to them later to delete them. It would sort of look like this:

Code: Select all

define array TL[]; #this is the array where handles to old trendlines get stored

# this block executes on the first bar of the day
if (day != day[1]) {
   pivot_high = <figure this out>;
   pivot_low = <figure this out>;

   #delete any old trendlines you may have drawn
   len = length(TL); # this is how many trendlines exist on the chart
   for (i = 0 to len-1 by 1) {
      tl_delete(TL[i]);
   }
   clear(TL); # this clears out the array
 
   #draw todays lines
   ref = trendline(barnum,pivot_high,barnum+bars_per_day,pivot_high,red);
   push(TL,ref); # save it in the array
   ref = trendline(barnum,pivot_low,barnum+bars_per_day,pivot_low,red);
   push(TL,ref);
}
Hope that helps!

Earik

Re: Pivots scripts

Posted: Thu Mar 21, 2019 11:41 pm
by abacaba
Earik,

This looks good. Thanks!

Todd