P
Pensar
Active member
VIP
Thanks, @henry1224 ! Should now be fixed. I ran it through my code editor and corrected it.
Thanks for the quick fix@Pensar I keep getting an error message with change from Open
@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.
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.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.
Here is the chart study code for what you asked:Can someone add the 52 Week high and low stats in a label and percentage that price is away from high and low. Thanks
#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));
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!
........................................................................................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.
#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
#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));
#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));
#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));
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
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 |