Useful Intraday Stats for ThinkorSwim

P

Pensar

Active member
VIP
Thanks, @henry1224 ! Should now be fixed. I ran it through my code editor and corrected it.
 
R

RochaTheRock

New member
As this is my first input I have a suggestion for some chart labels I find very useful when day trading, as we know history tends to repeat itself and if we analyze the stock history we can add more edge to our trading plan.

- how many times % and number it closed below the open when had a gap up or down - (this helps determine if a particular stock has more probability of closing red or green - looking for long or short setups)

- number of gaps above any % we choose - (like 15 or 20%)

- average % high from the open when gaps - (when closes above how much furder can it go)

- average % closes from the open when gaps - (when closes below how much furder can it go)

- average spike % - (when it spikes up or down how much it usually run)

- average daily spike when close above the open %

- average fade when close below the open %

thanks in advance
 
S

soary

Member
Can someone add the 52 Week high and low stats in a label and percentage that price is away from high and low. Thanks
 
R

RochaTheRock

New member
Is there a way to highlight all gaps on a daily chart?
 
S

soary

Member
@teo_teo asked for the following chart labels:

Premarket gap %
PM gap down (from PM High)
Open to current High as %
High to current price

If you look at the code I just posted above this, you will see PM gap % as the percent change.

The PM gap down (from PM high) would show up with this code:

def PMGD = close - OverNightHigh;
Addlabel(pmopen, "PMGD: " + PMGD, color.PINK);

Open to current High as % would show up with this code:

def OH1 = Round(100*((high1/open1)-1),1);
Addlabel(pmclosed, "OH1: " + OH1 + "%", createcolor(48,138,183));

High to current price would show up with this:

def HC = close - high1;
Addlabel(pmclosed, "HC: " + HC, createcolor(217,168,215));

Make sure these codes are added to the bottom of the big code I just posted above.

It's wonderful that you shared this. I'm a little confused with the hours are they eastern time?
I like these stats but would prefer to know them starting from previous close in eastern time such as:
  • Premarket open price based on eastern time
  • % change from yesterdays or previous close and Premarket open price based on eastern time
  • % change from Premarket open price to Premarket high price based on eastern time. Not sure if that's your "Open to current High as % would show up with this code"

-Price of Premarket high that updates based on eastern time
-Price currently in premarket that updates based on eastern time
-52 week high and low
-% difference of previous close from 52 week high and low

Thanks
 
C

convertiblejay

New member
Hey @Sonny i am back again. question. Can you write me a code that says if price closes or is above vwap its front side and if price closes or is below vwap it is backside? just want a label that i can add to the already great labels you have given me.
 
S

Sonny

Active member
VIP
Hey @Sonny i am back again. question. Can you write me a code that says if price closes or is above vwap its front side and if price closes or is below vwap it is backside? just want a label that i can add to the already great labels you have given me.
Just want to make sure I give you the right info. Do you want VWAP value as a chart label or difference between VWAP and current price as a label? I already submitted a chart study that shows an alert when price crosses above VWAP. I could add code to show when it goes below VWAP as well if you want. Please let me know which of these codes you are looking for and I will try to do it.

Thanks!
 
S

Sonny

Active member
VIP
Can someone add the 52 Week high and low stats in a label and percentage that price is away from high and low. Thanks
Here is the chart study code for what you asked:

#52 week high and low and percent differences

def HY = highest(HIGH (period = AggregationPeriod.DAY), 252);
def LY = lowest(LOW (period = AggregationPeriod.DAY), 252);
def H2 = Round(100*(close/HY),1);
def L2 = Round(100*(close/LY),1);

AddLabel(1,"HY: " + HY +"%", createcolor(239,222,205));
Addlabel(1,"LY: " + LY +"%", createcolor(155,166,192));
Addlabel(1,"Hd: " + H2 + "%", createcolor(239,222,205));
Addlabel(1,"Ld: " + L2 + "%", createcolor(155,166,192));
 
Last edited:
S

Sonny

Active member
VIP
@soary

The hours are eastern standard time. Premarket from 4am to 9:30am and Market hours from 9:30am to 4pm.
Here is the code for what you asked:

Code:
#Premarket High

def h = high;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());

def ONhigh = if GlobeX and !GlobeX[1] then h else if GlobeX and h > ONhigh[1] then h else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh then bar else Double.NaN;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];
AddLabel(1, "PMH: " + Round(OverNightHigh,2), color.CYAN);


#Current Price
Addlabel (1, "Price: " + close, createcolor(254,216,177));


#52 week high and low and percent differences from yesterday close

def HY = highest(HIGH (period = AggregationPeriod.DAY), 252);
def LY = lowest(LOW (period = AggregationPeriod.DAY), 252);
def YC = close(period = AggregationPeriod.DAY)[1];

def H2 = Round(100*(YC/HY),1);
def L2 = Round(100*(YC/LY),1);

AddLabel(1,"HY: " + HY, createcolor(239,222,205));
Addlabel(1,"LY: " + LY, createcolor(155,166,192));
Addlabel(1,"Hd: " + H2 + "%", createcolor(239,222,205));
Addlabel(1,"Ld: " + L2 + "%", createcolor(155,166,192));
 
Last edited:
S

Sonny

Active member
VIP
I fixed the error. Just get rid of the dot between Aggregation and Period. Let me work on the other things you asked about.
 
R

RochaTheRock

New member
@Sonny it's possible to write the code for the volume on a current bar in any timeframe?
 
C

convertiblejay

New member
Just want to make sure I give you the right info. Do you want VWAP value as a chart label or difference between VWAP and current price as a label? I already submitted a chart study that shows an alert when price crosses above VWAP. I could add code to show when it goes below VWAP as well if you want. Please let me know which of these codes you are looking for and I will try to do it.

Thanks!

no not VWAP value idont know if i am explaining it right but you know when price is above VWAP its seen as bullish and when its below its seen as bearish. I just want the label to say front side or backside depending on where price is if its above or below
 
S

soary

Member
If want to know the difference between today's volume and yesterday's volume, you could add the following code:

def difvol = today-YV;
Addlabel(1,"Difvol: " + difvol, color.PINK);

Make sure you add the code for yesterday's volume which I gave above before adding this code for difvol.
........................................................................................

@Sonny Thank you for your time and please forgive me for the length of this message. Most of the code works great the problem is when I piece portions from this thread together as posted below. The volume parts that read

= volume (period = AP); def today

def difvol = today-YV;

are red with the error codes that say:

39.29 No such variable AP

42.22 No such variable YV

And red also is the premarket line that says,

Addlabel(pmopen, "PMGD: " + PMGD, color.PINK);

Has error code that say:

64:10 No such variable pmopen

If it's not too much trouble could you add to the volume part the average volume of the last 100 days and the % difference between current volume and volume average of the last 100 days. Then, to the premarket part is where you would piece in the premarket open and difference between yesterdays close and the premarket open, also label for premarket low. Will that current price portion of the label show premarket price bec Tos charts don't show price in premarket? This is going to save me time from looking around for stats and doing calculations.

I read that you modified the labels to disappear but for my trading style I want them to remain visible all day and I couldn’t figure out what to change so the labels remain. Could you fix that please. You said,

“I modified my original code so that the intraday labels will show up only at 9:30am. From 4am to 9:30am, you will get Current price, Percent Change, Yesterday Close, and Premarket High (PMH). The PMH will disappear at 10am. The key to the labels appearing is the first variable in Addlabel. The label will show if it is 1 and not show if it is 0.”

Here’s what I pieced tighter and it includes the errors mentioned above:

Code:
#Intraday Stats

#Sonny @ usethinkscript.com

#modified by Pensar to add user-adjustable symbol input


input symbol = "/ES";

def c = close(symbol, aggregationperiod.DAY);

def o = open(symbol, aggregationperiod.DAY);

def h = high(symbol, aggregationperiod.DAY);

def l = low(symbol, aggregationperiod.DAY);

def v = volume(symbol, aggregationperiod.DAY);


#Symbol Label

AddLabel(1,symbol,color.white);


#Current Price

Addlabel (1, "Price: " + c, color.CYAN);


#Percent Change from yesterday close

def Priorclose = c[1];

def PctChange = (c - Priorclose) / Priorclose;

def PC1 = Round(PctChange,3);

Addlabel(1, "YC Ch: " + AsPercent(PC1), if PctChange > 0 then Createcolor(238,210,238) else Color.LIGHT_RED);


#Prior Close

Addlabel (1, "YC: " + Round(Priorclose,2), color.LIGHT_GREEN);


#Open price

Addlabel (1, "O: " + Round(o,2), createcolor(254,216,177));


#High of Day

def high1 = Highest(h,1);

Addlabel (1, "Hi: " + Round(high1,2), color.CYAN);


#Low of Day

def low1 = Lowest(l,1);

Addlabel (1, "Lo: " + Round(low1,2), createcolor(178,255,102));


#Volume Today

def today = volume(period = AP);

Addlabel(1, "Vol: " + today, createcolor(206,177,128));


def difvol = today-YV;

Addlabel(1,"Difvol: " + difvol, color.PINK);


#Change From Open

def CFO = (c / o)-1;

def CFO1 = Round(CFO,3);

Addlabel(1, "CFO: " + AsPercent(CFO1), if CFO >0 then Createcolor(0,255,128) else createcolor(255,153,153));

#…………………………………………………………………………………………..

#Premarket High

def bar = BarNumber();

def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());


def ONhigh = if GlobeX and !GlobeX[1] then h else if GlobeX and h > ONhigh[1] then h else ONhigh[1];

def ONhighBar = if GlobeX and h == ONhigh then bar else Double.NaN;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];

AddLabel(1, "PMH: " + Round(OverNightHigh,2), color.CYAN);


#The PM gap down (from PM high) would show up with this code:
def PMGD = close - OverNightHigh;
Addlabel(pmopen, "PMGD: " + PMGD, color.PINK);

#…………………………………………………………………………………………..

#52 week high and low and percent differences from yesterday close

def HY = highest(HIGH (period = AggregationPeriod.DAY), 252);

def LY = lowest(LOW (period = AggregationPeriod.DAY), 252);

def YC = close(period = AggregationPeriod.DAY)[1];


def H2 = Round(100*(YC/HY),1);

def L2 = Round(100*(YC/LY),1);


AddLabel(1,"HY: " + HY, createcolor(239,222,205));

Addlabel(1,"LY: " + LY, createcolor(155,166,192));

Addlabel(1,"Hd: " + H2 + "%", createcolor(239,222,205));

Addlabel(1,"Ld: " + L2 + "%", createcolor(155,166,192));


#end code
 
Last edited:
S

Sonny

Active member
VIP
@soary

I have put the code for the other things you asked about. Keep in mind that if you take out code pieces from the whole codes, it will not work. If you look at page 1 of this thread, I put in time codes so that the intraday stats show up only starting at 9:30am. If you want something to appear for the whole day, you have to put a 1 as the first character in Addlabel parentheses.

Code:
#Premarket Open and difference between yesterday close and premarket open

def newDay = GetDay() <> GetDay()[1];
def start = newDay or SecondsTillTime(400) == 0;
rec premarketOpen = if start then open else premarketOpen[1];
def x = premarketOpen;
Addlabel(1, “PMO: “ + x, createcolor(212,197,178));

def YC = close(period=AggregationPeriod.DAY)[1];
def dif1 = x-YC;
Addlabel(1, “Dif1: “ + dif1, createcolor(197,239,161));

#Premarket High and Low

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !GlobeX[1] then h else if GlobeX and h > ONhigh[1] then h else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh then bar else Double.NaN;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];
AddLabel(pastten, "PMH: " + Round(OverNightHigh,2), createcolor(178,152,122));

def ONlow = if GlobeX and !GlobeX[1] then l else if GlobeX and l < ONlow[1] then l else ONlow[1];
def ONlowBar = if GlobeX and l == ONlow then bar else Double.NaN;
def OverNightLow = if BarNumber() == HighestAll(ONlowBar) then ONlow else OverNightLow[1];
Addlabel(1, “PML: “ + Round(OverNightLow,2), createcolor(225,146,171));
 
S

Sonny

Active member
VIP
@soary

Here is Average Volume code you wanted:

Code:
#Average Volume (100d) and difference between AV and today's volume
def AV = AggregationPeriod.Day;
def x = Average(volume(period=AV)[1],100);
def L = RoundDown(lg(x),0);
def a = Round((x/1000),1);
def b = Round((x/1000000),1);
def y = if L<6 then a else b;
Addlabel(L<6, “AV: “+y+"K", createcolor(227,170,124));
Addlabel(L>5, "AV: "+y+"M", createcolor(227,170,124));

def v = volume(period=AV);
def z = v-x;
def L2 = RoundDown(lg(z),0);
def a1 = Round((z/1000),1);
def b1 = Round((z/1000000),1);
def y1 = if L2<6 then a1 else b1;
Addlabel(L2<6, "Diff: "+y1+"K", createcolor(208,209,238));
Addlabel(L2>5, "Diff: "+y1+"M", createcolor(208,209,238));
 
S

Sonny

Active member
VIP
@convertiblejay

Here is the code for VWAP difference. It shows "AV" for above VWAP and "BV" for below it.

Code:
#VWAP Diff

input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};

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;

Addlabel(close>price, "AV", color.CYAN);
Addlabel(price>close, "BV", createcolor(255,235,209));
 
S

Sonny

Active member
VIP
Just FYI:
You can create your own colors for these labels by going to the website rgbcolorcode.com and making your own colors. You just put in createcolor(A,B,C), {A,B,C are numbers} wherever you need to insert the color.
 
C

convertiblejay

New member
Thanks for the code @Sonny once again. Reason why i asked is because i get faked out by using my own judgement when a candle goes below VWAP and ramps back up so with this code i can wait now for the label to change instead of guessing
 
Thread starter Similar threads Forum Replies Date
Shinthus Useful Candlestick Studies Indicators 16
J Quick look intraday setup BTD Member Submitted 4
S Watchlist Intraday strength % Questions 0
B Resetting intraday MAs Questions 3
J Abnormal Number Of Trades Intraday Indicator/Scanner Indicators 14

Similar threads

Top