# Showing Crossovers for Different Aggregation Periods

#### grapetux

##### Member
Hi Traders, Happy MDW too all
I wanted to create a simple study to plot an arrow when there is a 20x50ema crossover from a one minute chart agg period, while viewing my standard 5min chart. I typically just trade \$PY on a 5min chart, but have found very trade-able signals (typically reversals) from the 20/50 crossover from one minute time period.

Just want to make sure my logic is sound.. Is it possible to be viewing one particular time frame, but referencing other agg periods and display the results?
Here's the code I've sliced together thus far, but its only displaying the crossover from the 5min chart, or whatever time period I select to view in TOS. Hope Im explaining myself ok, appreciate any help. Cheers

###
declare upper;

INPUT AGGREGATIONPERIOD = AGGREGATIONPERIOD.one_min; ??
input ema1_len = 20;
input ema2_len = 50;
input averageType = AverageType.EXPONENTIAL;

def ema1 = MovAvgExponential(length=ema1_len);
def ema2 = MovAvgExponential(length=ema2_len);

def bull_cross = ema1 crosses above ema2;
def bear_cross = ema1 crosses below ema2;

plot ArrowUp = bull_cross;
plot ArrowDn = bear_cross;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.RED);

Solution
Hi Traders, Happy MDW too all
I wanted to create a simple study to plot an arrow when there is a 20x50ema crossover from a one minute chart agg period, while viewing my standard 5min chart. I typically just trade \$PY on a 5min chart, but have found very trade-able signals (typically reversals) from the 20/50 crossover from one minute time period.

Just want to make sure my logic is sound.. Is it possible to be viewing one particular time frame, but referencing other agg periods and display the results?
Here's the code I've sliced together thus far, but its only displaying the crossover from the 5min chart, or whatever time period I select to view in TOS. Hope Im explaining myself ok, appreciate any help. Cheers

###
declare upper...
Hi Traders, Happy MDW too all
I wanted to create a simple study to plot an arrow when there is a 20x50ema crossover from a one minute chart agg period, while viewing my standard 5min chart. I typically just trade \$PY on a 5min chart, but have found very trade-able signals (typically reversals) from the 20/50 crossover from one minute time period.

Just want to make sure my logic is sound.. Is it possible to be viewing one particular time frame, but referencing other agg periods and display the results?
Here's the code I've sliced together thus far, but its only displaying the crossover from the 5min chart, or whatever time period I select to view in TOS. Hope Im explaining myself ok, appreciate any help. Cheers

###
declare upper;

INPUT AGGREGATIONPERIOD = AGGREGATIONPERIOD.one_min; ??
input ema1_len = 20;
input ema2_len = 50;
input averageType = AverageType.EXPONENTIAL;

def ema1 = MovAvgExponential(length=ema1_len);
def ema2 = MovAvgExponential(length=ema2_len);

def bull_cross = ema1 crosses above ema2;
def bear_cross = ema1 crosses below ema2;

plot ArrowUp = bull_cross;
plot ArrowDn = bear_cross;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.RED);

You can have higher aggregations display on lower aggregation charts, but not lower aggregations on a higher aggregation chart.

I have made: 1) correction to syntax for aggregationperiod; 2) added input for price, and included price in the movingaverage, so that you can use the aggregation input in your code3) changed ema1/ema2 to movingaverage() which allows your input averagetype to be utilized and changable to other types of averages; 4) added.a lineweight input so you can adjust the size of the arrows.

Ruby:
``````declare upper;

input AGGREGATIONPERIOD = AggregationPeriod.FIVE_MIN;
input lineweight = 5;
input ema1_len = 20;
input ema2_len = 50;
input price    = FundamentalType.CLOSE;
input averageType = AverageType.EXPONENTIAL;

def ema1 = MovingAverage(averageType, Fundamental(price, period = AGGREGATIONPERIOD), ema1_len);
def ema2 = MovingAverage(averageType, Fundamental(price, period = AGGREGATIONPERIOD), ema2_len);

def bull_cross = ema1 crosses above ema2;
def bear_cross = ema1 crosses below ema2;

plot ArrowUp = bull_cross;
plot ArrowDn = bear_cross;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetLineWeight(lineweight);
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.RED);
ArrowDn.SetLineWeight(lineweight);``````

You can have higher aggregations display on lower aggregation charts, but not lower aggregations on a higher aggregation chart.

I have made: 1) correction to syntax for aggregationperiod; 2) added input for price, and included price in the movingaverage, so that you can use the aggregation input in your code3) changed ema1/ema2 to movingaverage() which allows your input averagetype to be utilized and changable to other types of averages; 4) added.a lineweight input so you can adjust the size of the arrows.

Hey SleepyZ, thanks for your prompt response and helpful edits to the code. Look forward to using it this coming week.

I had another question in the same arena if you're up for it.

I wanted a simple custom watchlist study, that displayed when a ticker's current price is trading above its 9ema for a 5 min agg period, to monitor the top holdings of SPY for quick reference in an intraday setting.

Will below do the trick? Not sure if the same rules you mentioned before apply to watchlists..

INPUT AGGREGATIONPERIOD = AGGREGATIONPERIOD.Five_MIN;
def x = ExpAverage(close, 9);
def price = close();
Plot signal = if close > x then 2 else 1;signal.AssignValueColor(if signal == 2 then Color.dark_Green else if signal == 1 then Color.dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if signal == 2 then Color.dark_Green else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);

I'm not getting any error messages, but just curious again if my logic is correct and this will work.

Hope you're enjoying the wknd.
Cheers

Hey SleepyZ, thanks for your prompt response and helpful edits to the code. Look forward to using it this coming week.

I had another question in the same arena if you're up for it.

I wanted a simple custom watchlist study, that displayed when a ticker's current price is trading above its 9ema for a 5 min agg period, to monitor the top holdings of SPY for quick reference in an intraday setting.

Will below do the trick? Not sure if the same rules you mentioned before apply to watchlists..

INPUT AGGREGATIONPERIOD = AGGREGATIONPERIOD.Five_MIN;
def x = ExpAverage(close, 9);
def price = close();
Plot signal = if close > x then 2 else 1;signal.AssignValueColor(if signal == 2 then Color.dark_Green else if signal == 1 then Color.dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if signal == 2 then Color.dark_Green else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);

I'm not getting any error messages, but just curious again if my logic is correct and this will work.

Hope you're enjoying the wknd.
Cheers
The ToS platform does not allow for aggregation periods to be used in watchlists or scans.
The platform limits their use to charting functions.

The ToS platform does not allow for aggregation periods to be used in watchlists or scans.
The platform limits their use to charting functions.
Ok thanks for clarifying. What would be the default agg period then for the watchlist? Whatever time period I happen to be viewing?

Are there pre defined options found in the gear icon for customize watchlist , or using the time frame setup on the chart window?

Last edited by a moderator:
Ok thanks for clarifying. What would be the default agg period then for the watchlist? Whatever time period I happen to be viewing?

Are there pre defined options found in the gear icon for customize watchlist , or using the time frame setup on the chart window?
For watchlists and scans: define your aggregation by clicking on one of the 18 pre-defined options.
• Click on the gear icon to customize watchlist
• The watchlist aggregation button is located to the right of the watchlist name

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