• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Getting data(volume) from a different timeframe than the current chart displayed?

lostcoastsurf

New member
Is it possible to get the data(volume) from the 1 minute timeframe when viewing the 15 minute chart? I would like to create a label that has the volume of the last 1 minute candle while viewing a 15 minute chart (or any larger timeframe than the 1 minute)

I noticed in the thinkorswim manual under MIN aggregation period it says, "aggregation period used in this example cannot be less than chart aggregation period." Does that mean it's not possible?

As a basic example here is what I have tried (finding the volume of the last 1' candle and comparing it to the previous 50 1' candles to see if there is a volume spike while viewing a 15' timeframe):

Code:
input length = 50;
def agg = AggregationPeriod.MIN;

def volbuzz = (volume[1]/Average(volume, 50)) * 100;

AddLabel(1, "Vol: " +
    Round(volbuzz, 0)
    + "%",
    if volbuzz >= 200 then color.MAGENTA
    else color.gray);

But when I switch the chart to the 15' (higher) timeframe the label doesn't show up.
 
Last edited:

BenTen

Administrative
Staff
VIP
You need to change the following:

Code:
def agg = AggregationPeriod.MIN;

to:

Code:
input = AggregationPeriod.MIN;

And then adjust the aggregation period accordingly when you switch between different chart timeframes. In ThinkorSwim, you can display data from a higher timeframe onto a lower timeframe but not the other way around.
 

lostcoastsurf

New member
I'm batting 0% now.... Can't get the volume from the 1' timeframe on a higher timeframe, and can't script plot a premarket level on the chart unless you want your VWAP and moving averages skewed by the premarket data!

But thank you for your help. Great site.
 

lostcoastsurf

New member
Take a look at my comment above to find out why.
I did. I changed the the aggregation to input, but when you switch to the 15' and select 1' for the aggregation period in settings it doesn't work (pull the data from the 1'), or are you just confirming what you said that you CAN NOT get data from the 1' onto the 15' minute (or any greater than 1' timeframe, e.g. 2', 5', 15', 30', 1hr...)?
 

Thalada

New member
VIP
Below is the code i just wrote for a MTF Trend label based on 9 and 21 EMA. It looks good on a 5 min chart, but when i move to a higher time frame all the labels disappear even though i have conditioned it. Any help will be greatly appreciated.

Code:
#MTF Trend label based on 9 and 21 EMA
#Author - ThalaDa

input fastlength = 9;
input slowlength = 21;

def TimeFrame5min = AggregationPeriod.FIVE_MIN;
def TimeFrame10min = AggregationPeriod.TEN_MIN;
def TimeFrame15min = AggregationPeriod.FIFTEEN_MIN;
def TimeFrame30min = AggregationPeriod.THIRTY_MIN;
def TimeFrame1hr = AggregationPeriod.HOUR;
def TimeFrameDay = AggregationPeriod.DAY;
def TimeFrameWeek = AggregationPeriod.WEEK;
def TimeFrameMonth = AggregationPeriod.MONTH;

#Get the Current timeframe of the chart
def curAg = GetAggregationPeriod();

#Get the MTF labels that needs to be displayer based on current chart timeframe
def displayX5 = TimeFrame5Min >= curAg;
def displayX10 = TimeFrame10Min >= curAg;
def displayX15 = TimeFrame15Min >= curAg;
def displayX30 = TimeFrame30Min >= curAg;
def displayXH = TimeFrame1Hr >= curAg;
def displayXD = TimeFrameDay >= curAg;
def displayXW = TimeFrameWeek >= curAg;
def displayXM = TimeFrameMonth >= curAg;


def AvgType = averageType.EXPONENTIAL;

def X5 = if displayX5 then MovingAverage(AvgType, close(period = TimeFrame5min), fastlength) > MovingAverage(AvgType, close(period = TimeFrame5min), slowlength) else 0;
def X10 = if displayX10 then MovingAverage(AvgType, close(period = TimeFrame10min), fastlength) > MovingAverage(AvgType, close(period = TimeFrame10min), slowlength) else 0;
def X15 = if displayX15 then MovingAverage(AvgType, close(period = TimeFrame15min), fastlength) > MovingAverage(AvgType, close(period = TimeFrame15min), slowlength) else 0;
def X30 = if displayX30 then MovingAverage(AvgType, close(period = TimeFrame30min), fastlength) > MovingAverage(AvgType, close(period = TimeFrame30min), slowlength) else 0;
def XH = if displayXH then MovingAverage(AvgType, close(period = TimeFrame1hr), fastlength) > MovingAverage(AvgType, close(period = TimeFrame1hr), slowlength) else 0;
def XD = if displayXD then MovingAverage(AvgType, close(period = TimeFrameDay), fastlength) > MovingAverage(AvgType, close(period = TimeFrameDay), slowlength) else 0;
def XW = if displayXW then MovingAverage(AvgType, close(period = TimeFrameWeek), fastlength) > MovingAverage(AvgType, close(period = TimeFrameWeek), slowlength) else 0;
def XM = if displayXM then MovingAverage(AvgType, close(period = TimeFrameMonth), fastlength) > MovingAverage(AvgType, close(period = TimeFrameMonth), slowlength) else 0;


AddLabel(displayX5, “X5”, if X5 then color.Green else color.Red);
AddLabel(displayX10, “X10”, if X10 then color.Green else color.Red);
AddLabel(displayX15, “X15”, if X15 then color.Green else color.Red);
AddLabel(displayX30, “X30”, if X30 then color.Green else color.Red);
AddLabel(displayXH, “XH”, if XH then color.Green else color.Red);
AddLabel(displayXD, “XD”, if XD then color.Green else color.Red);
AddLabel(displayXW, “XW”, if XW then color.Green else color.Red);
AddLabel(displayXM, “XM”, if XM then color.Green else color.Red);
 

Similar threads

Top