• Memorial Day Sale! Claim the biggest discount of the year with $50 off VIP using code MEM50. Sign up here.

How to add a moving average into a study from different time frames?

dsohi11

New member
VIP
Anyone know how this please let me know? If the question is confusing also let me know thanks in advance.
 
Solution
You can use the aggregation period. Here's an example from the docs to plot the 15m close on your chart.
https://tlc.thinkorswim.com/center/...gregationPeriod/AggregationPeriod-FIFTEEN-MIN
There are limits to what you can do. You can't plot the 1m on a 5m chart, nor the 30m on a 2h chart. But you can go the other direction and plot the 30m on a 5m chart if you want.

Code:
plot 15m_EMA = MovAvgExponential(price = close(period = AggregationPeriod.FIFTEEN_MIN));

In this example, I've plotted the 15m ema by calling the price for the function using a secondary aggregation period. This one is simple, but illustrates the point I hope.

Ask more if you need,

-mashume

mashume

Well-known member
VIP
Lifetime
You can use the aggregation period. Here's an example from the docs to plot the 15m close on your chart.
https://tlc.thinkorswim.com/center/...gregationPeriod/AggregationPeriod-FIFTEEN-MIN
There are limits to what you can do. You can't plot the 1m on a 5m chart, nor the 30m on a 2h chart. But you can go the other direction and plot the 30m on a 5m chart if you want.

Code:
plot 15m_EMA = MovAvgExponential(price = close(period = AggregationPeriod.FIFTEEN_MIN));

In this example, I've plotted the 15m ema by calling the price for the function using a secondary aggregation period. This one is simple, but illustrates the point I hope.

Ask more if you need,

-mashume
 
Solution

a1cturner

Active member
VIP
I created a label for this based on Ripsters EMA clouds. I’ll jump on the computer later and post it here. It’s mostly complete but any input from anyone else on the forum would be greatly appreciated.

If it’s not posted in the next hour or two send me a DM because I probably forgot haha
 

SuryaKiranC

Well-known member
Last edited:

a1cturner

Active member
VIP
What I promised. See if that is helpful for you. I just add one for each time frame needed.

#MACD Histogram Cross
#Justin Turner

Declare Upper;

input time_frame = AggregationPeriod.DAY;

def lookback = 1;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;
def time_select = (close(period = time_frame));

def value = MovingAverage(averageType, time_select, fastLength) - MovingAverage(averageType,time_select, slowLength);
def avg = MovingAverage(averageType, Value, MACDLength);

def bull_cross = value crosses above avg;
def bear_cross = value crosses below avg;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

AddLabel (yes,
if Time_Frame == aggregationPeriod.YEAR then "Yr-"
else if
Time_Frame == aggregationPeriod.QUARTER then "Qtr-"
else if
Time_Frame == aggregationPeriod.MONTH then "Mo-"
else if
Time_Frame == aggregationPeriod.WEEK then "Wk-"
else if
Time_Frame == aggregationPeriod.FOUR_DAYS then "4D-"
else if
Time_Frame == aggregationPeriod.THREE_DAYS then "3D-"
else if
Time_Frame == aggregationPeriod.TWO_DAYS then "2D-"
else if
Time_Frame == aggregationPeriod.DAY then "D-"
else if
Time_Frame == aggregationPeriod.FOUR_HOURS then "4H-"
else if
Time_Frame == aggregationPeriod.TWO_HOURS then "2H-"
else if
Time_Frame == aggregationPeriod.HOUR then "1H-"
else if
Time_Frame == aggregationPeriod.THIRTY_MIN then "30m-"
else if
Time_Frame == aggregationPeriod.TWENTY_MIN then "20m-"
else if
Time_Frame == aggregationPeriod.FIFTEEN_MIN then "15m-"
else if
Time_Frame == aggregationPeriod.TEN_MIN then "10m-"
else if
Time_Frame == aggregationPeriod.FIVE_MIN then "5m-"
else if
Time_Frame == aggregationPeriod.FOUR_MIN then "4m-"
else if
Time_Frame == aggregationPeriod.THREE_MIN then "3m-"
else if
Time_Frame == aggregationPeriod.TWO_MIN then "2m-"
else if
Time_Frame == aggregationPeriod.MIN then "1m-"
else "-",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
AddLabel (yes,
if
bull_lookback then "MACD Bull X"
else if
bear_lookback then "MACD Bear X"
else if
bull_lookback within 2 bars then "MACD Bull XX"
else if bear_lookback within 2 bars then "MACD Bear XX"
else "MACD",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
 

ranjodhsingh

New member
What I promised. See if that is helpful for you. I just add one for each time frame needed.

#MACD Histogram Cross
#Justin Turner

Declare Upper;

input time_frame = AggregationPeriod.DAY;

def lookback = 1;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;
def time_select = (close(period = time_frame));

def value = MovingAverage(averageType, time_select, fastLength) - MovingAverage(averageType,time_select, slowLength);
def avg = MovingAverage(averageType, Value, MACDLength);

def bull_cross = value crosses above avg;
def bear_cross = value crosses below avg;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

AddLabel (yes,
if Time_Frame == aggregationPeriod.YEAR then "Yr-"
else if
Time_Frame == aggregationPeriod.QUARTER then "Qtr-"
else if
Time_Frame == aggregationPeriod.MONTH then "Mo-"
else if
Time_Frame == aggregationPeriod.WEEK then "Wk-"
else if
Time_Frame == aggregationPeriod.FOUR_DAYS then "4D-"
else if
Time_Frame == aggregationPeriod.THREE_DAYS then "3D-"
else if
Time_Frame == aggregationPeriod.TWO_DAYS then "2D-"
else if
Time_Frame == aggregationPeriod.DAY then "D-"
else if
Time_Frame == aggregationPeriod.FOUR_HOURS then "4H-"
else if
Time_Frame == aggregationPeriod.TWO_HOURS then "2H-"
else if
Time_Frame == aggregationPeriod.HOUR then "1H-"
else if
Time_Frame == aggregationPeriod.THIRTY_MIN then "30m-"
else if
Time_Frame == aggregationPeriod.TWENTY_MIN then "20m-"
else if
Time_Frame == aggregationPeriod.FIFTEEN_MIN then "15m-"
else if
Time_Frame == aggregationPeriod.TEN_MIN then "10m-"
else if
Time_Frame == aggregationPeriod.FIVE_MIN then "5m-"
else if
Time_Frame == aggregationPeriod.FOUR_MIN then "4m-"
else if
Time_Frame == aggregationPeriod.THREE_MIN then "3m-"
else if
Time_Frame == aggregationPeriod.TWO_MIN then "2m-"
else if
Time_Frame == aggregationPeriod.MIN then "1m-"
else "-",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
AddLabel (yes,
if
bull_lookback then "MACD Bull X"
else if
bear_lookback then "MACD Bear X"
else if
bull_lookback within 2 bars then "MACD Bull XX"
else if bear_lookback within 2 bars then "MACD Bear XX"
else "MACD",
if bull_lookback then createcolor (0,204, 0)
else if
bear_lookback then createcolor (204, 0, 0)
else if
bull_lookback within 2 bars then createcolor (0, 153, 0)
else if
bear_lookback within 2 bars then createcolor (153, 0, 0)
else
color.white);
could you please provide shareable link
 

Similar threads

Top