# how to add a different timeframe level condition?

#### oldyoungguy

##### New member
VIP
I have the following thinkscript and I plan to use it in 1 minute charts.

def mve13 = MovAvgExponential("length" = 13);

def mve24 = MovAvgExponential("length" = 24);

plot Buy =mve13 crosses above mve24;

Now I want to add another condition that should come from the 5 minutes timeframe. The condition is this:

def isGreen = HeikinAshiDiff() > 0;

So the result plot statement may look like this:

plot Buy =mve13 crosses above mve24 && isGreen;

But how can I tell thinkScript to get the "isGreen" from a higher level timeframe?

Solution
I have the following thinkscript and I plan to use it in 1 minute charts.

def mve13 = MovAvgExponential("length" = 13);

def mve24 = MovAvgExponential("length" = 24);

plot Buy =mve13 crosses above mve24;

Now I want to add another condition that should come from the 5 minutes timeframe. The condition is this:

def isGreen = HeikinAshiDiff() > 0;

So the result plot statement may look like this:

plot Buy =mve13 crosses above mve24 && isGreen;

But how can I tell thinkScript to get the "isGreen" from a higher level timeframe?

In this situation where there is not an aggregationperiod that is available in using the reference to...
I have the following thinkscript and I plan to use it in 1 minute charts.

def mve13 = MovAvgExponential("length" = 13);

def mve24 = MovAvgExponential("length" = 24);

plot Buy =mve13 crosses above mve24;

Now I want to add another condition that should come from the 5 minutes timeframe. The condition is this:

def isGreen = HeikinAshiDiff() > 0;

So the result plot statement may look like this:

plot Buy =mve13 crosses above mve24 && isGreen;

But how can I tell thinkScript to get the "isGreen" from a higher level timeframe?

In this situation where there is not an aggregationperiod that is available in using the reference to the HeikinAshiDiff() indicator, you need to include the relevant portions of the indicator in your scipt to def isgreen. See below.

Ruby:
``````def mve13 = MovAvgExponential("length" = 13);
def mve24 = MovAvgExponential("length" = 24);

input agg = AggregationPeriod.FIVE_MIN;
def o = open(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def c = close(period = agg);

def haclose = (o + h + l + c) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (o[1] + c[1]) / 2);
def HAdiff = haclose - haopen;

def isGreen = HAdiff > 0;

plot Buy =mve13 crosses above mve24 && isGreen;
# End Code``````

87k+ Posts
228 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?