(SOLVED) How to remove previous days plots (on Pivot Points)?

jngy2k

Member
VIP
2nd edit: anyone know who i can use the getday() script to only plot from yesterday forward?
the getday()>=getlastday() only plots for today and days forward
but if i want it to plot yesterday as well what should i do?


edit: with this i solved below problem but new problem is how to get it to plot yesterday forward?
anysuggestions?
Code:
def today = getday()>=getlastday();



edit: this i solved
Good mornings and happy thanksgiving good people!
The following is the code to the pivot points indicator in thinkorswim.
I want to modify the code of that it doesn't show previous days plots.
In the following example, the code shows all pivots for $APPN.
Today being November 25, it will show pivots for tomorrow 11/26 as well as all previous days pivots.
Is there a code I can insert into the current code that will hide the pivot plots for days before Today?
I believe I should be using this code but can't get it to work.
Code:
def today = getday()=getlastday();
plot pivotlines = if today<=today[1] then 1 else 0;

Thanks and happy holidays.




Code:
input aggregationPeriod = AggregationPeriod.DAY;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
def PC = close(period = aggregationPeriod)[1];

plot R3;
plot R3M;
plot R2;
plot R2M;
plot R1;
plot R1M;
plot HH;
plot PP;
plot LL;
plot S1M;
plot S1;
plot S2M;
plot S2;
plot S3M;
plot S3;

HH = PH;
LL = PL;
PP = (PH + PL + PC) / 3;
R1 = 2 * PP - PL;
R1M = (R1 - PP) / 2 + PP;
R2 = PP + (PH - PL);
R2M = (R2 - R1) / 2 + R1;
R3 = 2 * PP + (PH - 2 * PL);
R3M = (R3 - R2) / 2 + R2;
S1 = 2 * PP - PH;
S1M = (PP - S1) / 2 + S1;
S2 = PP - (PH - PL);
S2M = (S1 - S2) / 2 + S2;
S3 = 2 * PP - (2 * PH - PL);
S3M = (S2 - S3) / 2 + S3;

R3.SetDefaultColor(GetColor(5));
R3M.SetDefaultColor(GetColor(5));
R2.SetDefaultColor(GetColor(5));
R2M.SetDefaultColor(GetColor(5));
R1.SetDefaultColor(GetColor(5));
R1M.SetDefaultColor(GetColor(5));
HH.SetDefaultColor(GetColor(4));
PP.SetDefaultColor(GetColor(0));
LL.SetDefaultColor(GetColor(1));
S1.SetDefaultColor(GetColor(6));
S1M.SetDefaultColor(GetColor(6));
S2.SetDefaultColor(GetColor(6));
S2M.SetDefaultColor(GetColor(6));
S3.SetDefaultColor(GetColor(6));
S3M.SetDefaultColor(GetColor(6));

R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

R3M.SetStyle(Curve.SHORT_DASH);
R2M.SetStyle(Curve.SHORT_DASH);
R1M.SetStyle(Curve.SHORT_DASH);
HH.SetStyle(Curve.MEDIUM_DASH);
LL.SetStyle(Curve.MEDIUM_DASH);
S1M.SetStyle(Curve.SHORT_DASH);
S2M.SetStyle(Curve.SHORT_DASH);
S3M.SetStyle(Curve.SHORT_DASH);

R3M.Hide();
R2M.Hide();
R1M.Hide();
HH.Hide();
LL.Hide();
S1M.Hide();
S2M.Hide();
S3M.Hide();
 
Last edited:

RickAns

Active member
VIP
I agree that all the previous days pivots can make a chart look cluttered. Be nice to have a way to just focus on a few current days worth of info. A late happy turkey day to you as well.
 

generic

Active member
@jngy2k You need to change getday()=getlastday() to getday()==getlastday(). Also since everything is based on PP, just make PP plot for today and all the other lines should follow.
 

RickAns

Active member
VIP
@jngy2k Not sure if you sorted this out yet or not but I think I have found a solution. At least it works for me, anyway. Or maybe others may find it useful. :)

Change the 3 to how far back you want to plot.

Code:
#-- test to show only current few pivot lines
def plotThis =  if getday() >= (getlastday() - 3)  then 1 else 0;

Then in your plot statement use an if plotThis == 1 then blahblah else Double.NaN like this.

Code:
plot TL_RTH = if plotThis == 1 then RTH_TL else Double.NaN;

It plots the current day, future forecast pivots and however many days back you want as well. If it is more than 3 or x many days back from current day it does not plot anything. (y)
 
Last edited:

jngy2k

Member
VIP
by any chance does anyone know how to draw a line to the right (and NOT TO THE LEFT) after a specific bar number

@XeoNoX u'll have to learn !Isnan (the value is not a number) and -1 (reference of the future) functions.

@RickAns My VWAP code so it doesn't plot on the whole graph when increasing chart frame.

Code:
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};
input ShowTodayOnly = { default "No", "Yes"};
def s = ShowTodayOnly;
def today = if s == 0 OR getDay() >= getLastDay()-3 then 1 else 0;

def cap = getAggregationPeriod();
def errorInAggregation =
    timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
    timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
    periodIndx = yyyyMmDd;
case WEEK:
    periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
    periodIndx = roundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = if today and getAggregationPeriod()<=aggregationPeriod.hour then price else double.nan;
plot UpperBand = if today and getAggregationPeriod()<=aggregationPeriod.FIFTEEN_MIN then price + numDevUp * deviation else double.nan;
plot LowerBand = if today and getAggregationPeriod()<=aggregationPeriod.FIFTEEN_MIN then price + numDevDn * deviation else double.nan;
AddLabel(GetAggregationPeriod() <= AggregationPeriod.hour, "VWAP: " + round(VWAP,2) , color.yellow);
VWAP.setDefaultColor(createColor(255,255,0));
UpperBand.setDefaultColor(getColor(7));
LowerBand.setDefaultColor(getColor(7));
upperband.setstyle(curve.short_DASH);
lowerband.setstyle(curve.short_DASH);
upperband.hide();
lowerband.hide();
 

XeoNoX

Active member
VIP
yea i was up late and tired... the Christmas holiday had me mentally and physically exhausted, i couldnt even think basic formulas at one point. Good Sleep fixes alot of things, haha.
 

jngy2k

Member
VIP
@RickAns hey not sure if this is happening on your end, but the script getday()>=getlastday()-3 stopped working today.
I'm trying to fix it now. I believe it has to do with the new year.
because it calculates each passing day from the new year as 1 so last years days that are greater than january are above the getlastday number

FINAL EDIT: add and GetLastYear() == GetYear() to set it for this year only.
 
Last edited:

RickAns

Active member
VIP
@jngy2k Mine had acted funny too recently. Just thought it might be the extended holiday. First one since using that bit of code. Did not think about the changing of the year affecting things. Thanks for the fix! I have added it to my own project as well. :)

The
Code:
and GetLastYear() == GetYear()

solved it. I had wrongly thought it counted back a years worth of days from the current position. Instead it does the last calendar year. Good to know. Thanks.(y)
 

Similar threads

Top