Accessing Seconds from 1min Chart ThinkOrSwim

evanevans

Active member
I'm trying to create a label to show projected number of shares traded (volume) by close of the current bar. Technically all I want to do is color a CurrentBarVolume label according to whether the projected volume of the current bar will be above or below the average of the last 30 bars.

The problem is, I can't get the number of seconds that have passed in the current minute (GetTime) so that I can do a calculated projection.

For example, if in the first 10 seconds of the current minute 100,000 shares have traded, than at that point you can project that 600,000 shares might trade by the close of the current bar.

So for my script, if that 600,000 number (for example) is above the average bar volume of the last 30 bars, I want to color the label green, otherwise light_gray.

Any help?

Many thanks
 
Also if you Buy when it does and Sell when it does, you will make close to what it does. I have done more than a strategy at times and less at other times. Mostly depends on the false signals, and what you do when they show. This strategy I'm hoping because it has more bars in a min, If I even wait till the next bar after the buy signal to confirm, it's not too long of a time and will still make most of what the strategy does. I'll let you know after real time testing.
 
@MattATM Why does this seam to only work on TSLA, I mean the strategy
Paper Trading does not work so good in the Tick Chart Time. To much delay, a few bars pass after signals.
Reg Trading Bars signals OK. Just going to be harder to test live, specialty with TSLA being the only stock I can get i to work on

Change lines
51 def min = Floor(SecondsFromTime(start) / AggregationPeriod.MIN);
52 def till = SecondsTillTime(end) / AggregationPeriod.MIN;
Then this strategy works on min charts
 
Last edited:
@MattATM Why does this seam to only work on TSLA, I mean the strategy
Paper Trading does not work so good in the Tick Chart Time. To much delay, a few bars pass after signals.
Reg Trading Bars signals OK. Just going to be harder to test live, specialty with TSLA being the only stock I can get i to work on

Change lines
51 def min = Floor(SecondsFromTime(start) / AggregationPeriod.MIN);
52 def till = SecondsTillTime(end) / AggregationPeriod.MIN;
Then this strategy works on min charts
@StockT8er I will look into it tomorrow sir...
Since you brought it up I suspect since the last FED meeting that the meaningful volume in the market is crazy low. I may be biased in this because I tried to close some options contracts today that increased in value considerably. It take over 30 minutes to close and some never closed!!! I think we are hanging in mid air even in tesla! So maybe what you are seeing is real and not a mistake????

I will try to work on this tomorrow. I am way behind.
Edit: I am not bearish or bullish in general we could see the president pump the markets but I mean since the FED basically said nobody do anything exchanges just slumped a little but from watching price movement don't you feel like volume is actually lower than it appears?
 
Hi Evenevens.

Was looking through some of posts on this site hoping to find a script that allows me to enter at market at a fixed $ value using hotkeys, and came across this thread. I am totally new here, so please forgive my forwardness.

If you dont mind me asking, what is this grey box you have here (upper left) showing the $risk, $stop and # of shares? Are these values something that constantly update in realtime as the price moves? Man this would save me a LOT of time, compared to plugging the share price into a separate spreadsheet to find number of shares then going back to active trader to enter share numbers.

Is this script available somewhere, or can you share it by chance?

Thanks,

Aza
 
Hi Evenevens.

Was looking through some of posts on this site hoping to find a script that allows me to enter at market at a fixed $ value using hotkeys, and came across this thread. I am totally new here, so please forgive my forwardness.

If you dont mind me asking, what is this grey box you have here (upper left) showing the $risk, $stop and # of shares? Are these values something that constantly update in realtime as the price moves? Man this would save me a LOT of time, compared to plugging the share price into a separate spreadsheet to find number of shares then going back to active trader to enter share numbers.

Is this script available somewhere, or can you share it by chance?

Thanks,

Aza
Hi Azakusa,
Yes, they do update in realtime. Although since a latest update of TOS, all my labels are not showing. Not sure why. And yes, there is somewhere here on this site, where I got that script. I may have slightly enhanced it, but it's here on UseThinkScript somewhere.
 
@MattATM Having looked back at this move that you reference, it stopped at precisely 3x daily ATR from the open. Also, it was almost precisely a 150% move down from the prev days lowest point based on the previous day's range. On the monthly volume profile on a daily chart it was very close to the value area high before the break higher on 8/26. Could be some other things but I think it was several these factors on the higher time frames that all converged together and played a role in its support.

edit: another thing, $TICKs were at the most extreme down to almost -1700, once that let off, $VOLD, $ADD, and the -VIX all started to stall then ease up

ssiqhGu.png
@Welkin If you still have this chart could you share it? I just emailed you constant_VWAP_for_welkin for your review. You should have my email from this message.
I am still not certain what to do for coloring this constant Volume. Maybe ATR 3.0 maybe look for a concentration of some type of Support & Resistance level? IDK? No need to make it Green or Red just say VolumeS&R or VolumeOpen
 
@Welkin If you still have this chart could you share it? I just emailed you constant_VWAP_for_welkin for your review. You should have my email from this message.
I am still not certain what to do for coloring this constant Volume. Maybe ATR 3.0 maybe look for a concentration of some type of Support & Resistance level? IDK? No need to make it Green or Red just say VolumeS&R or VolumeOpen
you've got mail!
 
@StockT8er If you have Bubble working right, can you pls share updated code. Thank you


I converted your study to a Strategy, hope you don't mind. Works pretty well. Still working on Bubble to work right
Setup the time as Range - TODAY 100 Ticks or Range DAY 100 Ticks

Code:
#[email protected]
#Attempt at Volume Projection and Buy/Sell Strength on low TICK charts
#Thanks to YungTraderFromMontana and evanevans for the ideas
#v9.6.2020


# Positioning --------------------------------------------------------

input usetimefilter = Yes;
input rthopen = 0932;
input rthclose = 1555;
def RTH = if usetimefilter == yes then if SecondsFromTime(rthopen) >= 0 and
               SecondsTillTime(rthclose) >= 0
            then 1
            else 0 else 1;

input StopLoss = Yes;
input stoplosspercent = .08;

input fastLength = 9;
input slowLength = 26;
input MACDLength = 3;
input averageType = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
def DiffCondition = (if Diff >= 0 then if Diff > Diff[1] then 1 else 2 else if Diff < Diff[1] then 3 else 4);

def NA = Double.NaN;
input Sentiment = {default None, Inertia, HeikenAshiTrend, AboveBelowMovAvg, AboveBelowHighVolTriggeredVWAP};
input strengthType = {CandleStrength, default OnBalanceVol};
input showCumulativeStr = no;
input showCumulativeStrDiff = yes;
input aggregationInSeconds = 60;
def aggtomin = aggregationInSeconds / 60;
input toggleProjection = {enabled, default disabled};
input elapsedPercentSmoothValue = 5;
input elapsedProjectionDivisor = 2;
input showVerticalExceedPrevCvol = yes;
input showVerticalCycleEndCvol = yes;

def start = 0000;
def end = 1600;
def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def t = tick_count;
def bull = c > c[1];
def bear = c < c[1];
def neutral = c == o;
def min = Floor(SecondsFromTime(start) / aggregationInSeconds);
def till = SecondsTillTime(end) / aggregationInSeconds;
def test = min != min[1];
def vc = if test and !test[1] then v else if !test then vc[1] + v else vc[1];

def b = ((c - l) / (h - l)) * v;
def s = ((h - c) / (h - l)) * v;
def cb;
def cs;
switch (strengthType){
case CandleStrength:
    cb = if test and !test[1] then b else if !test then cb[1] + b else cb[1];
    cs = if test and !test[1] then s else if !test then cs[1] + s else cs[1];
case OnBalanceVol:
    cb = if test and !test[1] and bull then v else if test and !test[1] and !bull then 0 else if !test and bull then cb[1] + v else cb[1];
    cs = if test and !test[1] and bear then v else if test and !test[1] and !bear then 0 else if !test and bear then cs[1] + v else cs[1];
}

def tickcount = if test and !test[1] then t else if !test then tickcount[1] + t else tickcount[1];
def prevtickcount = if test and !test[1] then tickcount[1] else prevtickcount[1];
def tickperminute = prevtickcount/aggtomin;
#AddLabel(1, prevtickcount, COlor.Magenta);
#AddLabel(1,tickcount,Color.MAGENTA);
#AddLabel(1,tickperminute+" TPM",Color.MAGENTA);

def secondselapsed = (AbsValue(till - Ceil(till)) * aggregationInSeconds);
def secondsleft = aggregationInSeconds - secondselapsed;
def multipliertest = aggregationInSeconds / secondselapsed;
def multiplier  = if IsInfinite(multipliertest) then NA else multipliertest;
def percntelapsed = Round(((secondselapsed / aggregationInSeconds) * 100), 0);
def cl = if test then 1 else cl[1] + 1;
def ch = if test then cl[1] else ch[1];
def prevcumulativehigh = if test and !test[1] then vc[1] else prevcumulativehigh[1];
def cvolpassprev = vc >= prevcumulativehigh and vc[1] < prevcumulativehigh;
def highestprevchigh = HighestAll(prevcumulativehigh);
def projectioncalc = vc * multiplier;

######################
#Inertia
input inertiaLength = 20;
input inertiaPrice = close;
def inertia = Inertia(inertiaPrice, inertiaLength);

######################
#Heiken Ashi
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
HAhigh = Max(Max(h, HAopen), HAclose[1]);
HAlow = Min(Min(l, HAopen), HAclose[1]);
HAclose = ohlc4;

######################
#Above Below Moving Average
input movAvgPrice = close;
input movAvgType = AverageType.EXPONENTIAL;
input movAvg1Length = 20;
input movAvg2Length = 30;
input movAvg3Length = 40;
input movAvg4Length = 50;
def MA1 = MovingAverage(movAvgType, movAvgPrice, movAvg1Length);
def MA2 = MovingAverage(movAvgType, movAvgPrice, movAvg2Length);
def MA3 = MovingAverage(movAvgType, movAvgPrice, movAvg3Length);
def MA4 = MovingAverage(movAvgType, movAvgPrice, movAvg4Length);
def MA12test = MA1 > MA2;
def MA23test = MA2 > MA3;
def MA34test = MA3 > MA4;

######################
#Sigma Vol Filters
input avgVolLength = 20;
input volAverageType = AverageType.SIMPLE;
input Sigma2 = 2.0;
input Sigma3 = 3.0;
def VolAvg = MovingAverage(volAverageType, v, avgVolLength);
def sDev = StDev(data = v, length = avgVolLength);
def VolSigma2 = VolAvg + Sigma2 * sDev;
def VolSigma3 = VolAvg + Sigma3 * sDev;

######################
#VWAP
def vconf = if v > VolSigma3 then 1 else if v > VolSigma2 then 1 else 0;
def VolumeSum = if vconf then v else CompoundValue(1, VolumeSum[1] + v, v);
def VolumeVwapSum = if vconf then v * vwap else CompoundValue(1, VolumeVwapSum[1] + v * vwap, v * vwap);
def volumeVwap2Sum = if vconf then v * Sqr(vwap) else CompoundValue(1, volumeVwap2Sum[1] + v * Sqr(vwap), v * Sqr(vwap));
def VW = if !IsNaN(c) then VolumeVwapSum / VolumeSum else VW[1];

######################

def cvolpassprevsig = if cvolpassprev then vc else NA;
#def CVol = vc;
def prevchigh = prevcumulativehigh;
def cycleavg = Round(TotalSum(if test and !test[1] then ch[1] else 0) / min, 1);
def cyclehigh = ch;
def cyclelength = cl;

def projection;
switch (toggleProjection){
case enabled:
    projection = if (projectioncalc >= highestprevchigh) and (percntelapsed < elapsedPercentSmoothValue) then projectioncalc / elapsedProjectionDivisor else projectioncalc;
case disabled:
    projection = NA;
}
#ycleavg.Hide();
#cyclehigh.Hide();
#cyclelength.Hide();

def bsdiff = prevchigh + (cb - cs);
#bsdiff.SetHiding(!showCumulativeStrDiff);
def bsdiffaboveztest = bsdiff > prevchigh;
#bsdiff.AssignValueColor(if bsdiffaboveztest and bsdiff > bsdiff[1] then Color.GREEN else if bsdiffaboveztest and bsdiff <= bsdiff[1] then Color.DARK_GREEN else if !bsdiffaboveztest and bsdiff < bsdiff[1] then Color.RED else Color.DARK_RED);
def cbuy = cb;
#cbuy.SetHiding(!showCumulativeStr);
def csell = cs;
#csell.SetHiding(!showCumulativeStr);

def Pos;
def Neg;
switch (Sentiment){
case None:
    Pos = NA;
    Neg = NA;
case Inertia:
    Pos = inertia > inertia[1];
    Neg = !Pos;
case HeikenAshiTrend:
    Pos = HAclose > HAopen;
    Neg = !Pos;
case AboveBelowMovAvg:
    Pos = MA12test and MA23test;
    Neg = !Pos;
case AboveBelowHighVolTriggeredVWAP:
    Pos = close > VW;
    Neg = !Pos;
}

# PrevDayClose -------------------------------------------------------

input stopbuyPrevClose = No;
input aggregationPeriod = AggregationPeriod.DAY;
def showOnlyLastPeriod = yes;
def prevPrice = open(period = aggregationPeriod)[-1];
def price3 = open(period = aggregationPeriod);
def DailyOpen = if showOnlyLastPeriod and !IsNaN(prevPrice) then Double.NaN else price3;

def length3 = 1;
def displace3 = -1;
def PrevDayClose;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PrevDayClose = Double.NaN;
} else {
    PrevDayClose = Highest(close(period = aggregationPeriod)[-displace3], length3);
}
def pclose = if stopbuyPrevClose == yes then if PrevDayClose < close then 1 else 0 else 1;

def BuyStr = Round(cb, 0);
def SellStr = Round(cs, 0);
#def BuyStr = (cb / vc);
#def SellStr = (cs / vc);
def VDiff = Round(((BuyStr - SellStr) / BuyStr) * 100, 2);

def entryPrice = EntryPrice();
def pstoploss = entryPrice * (stoplosspercent / 100);
def pStopSell = entryPrice - pstoploss > close;

def StopSell = if StopLoss == 1 then pStopSell else 0;
def EOD =  RTH == 1 > SecondsTillTime(2000);
def BuyorderPrice = open[-1] + ((close[-1] - open[-1]) / 2);
def SellorderPrice = open[-1] - ((open[-1] - close[-1]) / 2);

# Buy_Signals --------------------------------------------------------

def BuySignal1 = VDiff>2;
def SellSignal1 = VDiff<-2;
def BuySignal2 = bsdiffaboveztest and bsdiff > bsdiff[1];
def SellSignal2 = !bsdiffaboveztest and bsdiff < bsdiff[1];
def BuySignal = BuySignal1 and BuySignal2 and Diff > Diff[1];
def SellSignal = SellSignal1 and SellSignal2 and Diff < Diff[1] and DiffCondition == 3;

AddOrder(OrderType.BUY_TO_OPEN, RTH and BuySignal[-1], price = buyorderprice, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "CDS_LE_G");

AddOrder(OrderType.SELL_TO_CLOSE, SellSignal[-1], price = sellorderprice, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "CDS_SE");

AddOrder(OrderType.SELL_TO_CLOSE, StopSell[-1], price = sellorderprice, tickcolor = GetColor(7), arrowcolor = GetColor(7), name = "CDS_SL");

AddOrder(OrderType.SELL_TO_CLOSE, EOD, price = sellorderprice, tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "CDS_EOD");

#input showBreakoutSignals = no;
def begin = rthopen;
# Entry Calculations.  Note: Only parses on a Strategy Chart
def entry = EntryPrice();

input showSignal = no;
plot Buy_Signal = RTH and BuySignal[0];
Buy_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy_Signal.SetDefaultColor(Color.CYAN);
Buy_Signal.SetLineWeight(4);
Buy_Signal.HideTitle();
Buy_Signal.SetHiding(!showSignal);

plot Sell_Signal =  RTH and SellSignal[0];
Sell_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Sell_Signal.SetDefaultColor(Color.MAGENTA);
Sell_Signal.SetLineWeight(4);
Sell_Signal.HideTitle();
Sell_Signal.SetHiding(!showSignal);

#Vertical Lines
#AddVerticalLine(showVerticalExceedPrevCvol and !IsNaN(cvolpassprevsig), "                 " + secondselapsed + "s / " + aggregationInSeconds + " | " + percntelapsed + "%", Color.CYAN);
#AddVerticalLine(showVerticalCycleEndCvol and test, "Lngth " + cyclelength[1] + "  CVol " + prevcumulativehigh + "  B/S " + Round((cb[1] / vc[1]) * 100, 0) + "/" + +Round((cs[1] / vc[1]) * 100, 0) + "%", Color.GRAY, Curve.FIRM);

#Labels

input showCycleLengthLabel = yes;
input showPrevCycleLengthLabel = yes;
input showCycleAvgLengthLabel = no;
input showTotalCyclesLabel = no;
input showSecsElapsedLabel = yes;
input showCumulativeVolLabel = yes;
input showBuyStrLabel = yes;
input showSellStrLabel = yes;
input showPrevCVolLabel = yes;
input showRelToPrevCVolLabel = yes;
input showProjectedVolLabel = yes;
input showProjMultiplierLabel = no;


AddLabel(showCycleLengthLabel, "Cycle Length: " + cyclelength[1], Color.GRAY);
AddLabel(showPrevCycleLengthLabel, "Prev Cycle Length: " + cyclehigh, Color.GRAY);
AddLabel(showCycleAvgLengthLabel, "Cycle Avg Length: " + cycleavg, Color.GRAY);
AddLabel(showTotalCyclesLabel, "Cycles Since Start: " + min, Color.GRAY);
AddLabel(showSecsElapsedLabel, "Secs " + secondselapsed + "/" + aggregationInSeconds + "   " + percntelapsed + "%", Color.YELLOW);
AddLabel(showCumulativeVolLabel, "CVol: " + vc, Color.WHITE);
AddLabel(1, "BuyStr: " + Round(cb, 0) + " / " + Round((cb / vc) * 100, 2) + "%", Color.GREEN);
AddLabel(1, "SellStr: " + Round(cs, 0) + " / " + Round((cs / vc) * 100, 2) + "%", Color.RED);
AddLabel(showPrevCVolLabel, "Prev CVol: " + prevcumulativehigh, Color.WHITE);
AddLabel(showRelToPrevCVolLabel, "x" + Round(vc / prevcumulativehigh, 2) + " Prev CVol", Color.WHITE);
AddLabel(showProjectedVolLabel and toggleProjection == toggleProjection.enabled, "Proj Vol: " + Round(projection, 0), Color.DARK_ORANGE);
AddLabel(showProjMultiplierLabel and toggleProjection == toggleProjection.enabled, "Proj Multiplier x" + Round(multiplier, 2), Color.DARK_ORANGE);

AddChartBubble(!IsNaN(close) and IsNaN(close[-1]), high,
        if RTH and  VDiff < 0 then
        " * S E L L _ A L E R T * " + " * Strenght " + VDiff + "% " else
        if VDiff > 0 then
         " * B U Y _ A L E R T * " + " * Strenght " + VDiff + "% " else
        " * H O L D * ",
        if VDiff+10 >0 then Color.GREEN  else
        if VDiff>0 then Color.DARK_GREEN else
        if VDiff-10<0 then Color.RED else
        if VDiff<0 then Color.DARK_RED else
        Color.YELLOW);

#CVol.SetDefaultColor(Color.DARK_GRAY);
#CVol.AssignValueColor(if toggleProjection == toggleProjection.disabled and Pos then Color.GREEN else if Neg then Color.RED else Color.GRAY);
#CVol.SetLineWeight(2);
#prevchigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#prevchigh.SetDefaultColor(Color.YELLOW);
#projection.SetDefaultColor(Color.DARK_ORANGE);
#projection.AssignValueColor(if Pos then Color.GREEN else if Neg then Color.RED else Color.GRAY);
#projection.SetLineWeight(2);
#cvolpassprevsig.SetPaintingStrategy(PaintingStrategy.POINTS);
#cvolpassprevsig.SetLineWeight(3);

#AddCloud(if showCumulativeStr then cbuy else NA, csell, Color.GREEN, Color.RED);
#AddCloud(if showCumulativeStrDiff then bsdiff else NA, prevchigh, Color.GREEN, Color.RED);
#AddCloud(projection,   CVol,   CreateColor(0, 100, 200),   CreateColor(0, 100, 200));
#AddCloud(CVol,   0,   Color.DARK_GRAY,   Color.DARK_GRAY);
#AddCloud(CVol,   prevchigh,   Color.YELLOW,   Color.BLACK);
 
@StockT8er Thanks for that strategy... I was looking some details

Code:
######################
#Sigma Vol Filters
input avgVolLength = 20;
input volAverageType = AverageType.SIMPLE;
I guess this portion about "avgVolLength" is given for the number of ticks and not for Minutes so the result may be incoherent... According to volume average in 1 min within the tick chart ... Am I overlooking something?... Could you confirm please..
 
@StockT8er Thanks for that strategy... I was looking some details

Code:
######################
#Sigma Vol Filters
input avgVolLength = 20;
input volAverageType = AverageType.SIMPLE;
I guess this portion about "avgVolLength" is given for the number of ticks and not for Minutes so the result may be incoherent... According to volume average in 1 min within the tick chart ... Am I overlooking something?... Could you confirm please..
That's a good question I have no idea
 
@StockT8er Thanks for that strategy... I was looking some details

Code:
######################
#Sigma Vol Filters
input avgVolLength = 20;
input volAverageType = AverageType.SIMPLE;
I guess this portion about "avgVolLength" is given for the number of ticks and not for Minutes so the result may be incoherent... According to volume average in 1 min within the tick chart ... Am I overlooking something?... Could you confirm please..
TD's tick data is dependent on their data source and is received in "bulk package". Sometimes there will be a difference in it compared to other data sources. However the larger time frame will normally fix this error. If you want true tick data you will have to find a different broker and platform and take note that you will probably have to pay for this kind of data and obtain a subscription. If tick is important you may want to look into https://www.cqg.com/
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
494 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top