Add Time Frame to These Upper Studies

a1cturner

Well-known member
I am trying to add a time frame input so that the indicator does not change when I am switching between different charts with different time frames.

My end goal is to see if the MACD crossed on the daily chart while I'm looking at the 10 minute chart or if it crossed on the hourly chart while I'm looking at the daily chart etc. My plan is to add an indicator for the MACD cross using a 10 minute, 1 hour, daily, and weekly time frames. This is an upper study.

I am also trying to keep my doji indicator on a daily time frame when I switch to a 10 minute, hourly chart etc.

I do understand the input Time_Frame = getaggregationperiod.Day code but I don't know where to put the Time_Frame further down in the code.

---------------------------------------------
#MACD Cross
#Justin Turner

Declare Upper;

def lookback = 1;
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, 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
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 "-",
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);

------------------------------------------------
#Doji
#Justin Turner

Declare upper;

def Doji = reference Doji(bodyFactor = 0.1);

addlabel (yes,
if
Doji within 1 bar then “D1”
else if
Doji within 2 bars then “D2”
else
“-“,
if
Doji within 1 bar then color.dark_green
else if
Doji within 2 bars then createcolor (153, 153, 0)
else
color.white);
 
Solution
Calculations is based off of close, Just the following.

Ruby:
input aP = AggregationPeriod.FIFTEEN_MIN;

add this ☝️ after "Declare Upper;" line.

Ruby:
close(period = aP)

Replace where ever you see close, with ☝️
Calculations is based off of close, Just the following.

Ruby:
input aP = AggregationPeriod.FIFTEEN_MIN;

add this ☝️ after "Declare Upper;" line.

Ruby:
close(period = aP)

Replace where ever you see close, with ☝️
 
Solution

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

Thank You. That helped get it on my MACD study but is it even possible to put in on my Doji study if I don't have a close value?

#Doji
#Justin Turner

Declare upper;

def Doji = reference Doji(bodyFactor = 0.1);

addlabel (yes,
if
Doji within 1 bar then “D1”
else if
Doji within 2 bars then “D2”
else
“-“,
if
Doji within 1 bar then color.dark_green
else if
Doji within 2 bars then createcolor (153, 153, 0)
else
color.white);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
463 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