You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter showstopper
- Start date

Code:

```
input ShowTodayOnly = no;
def Today = if GetDay() == GetLastDay() then 1 else 0;
#Plot yesterday's high / low
plot prevClose = if ShowTodayOnly and !Today then Double.NaN else close(period = "day" )[1];
prevClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevClose.SetDefaultColor(Color.UPTICK);
prevClose.SetLineWeight(1);
```

Try using the scanner with it.

Thank you for the response, I have the code for previous day close but how do I use it conjugation with 5min close as these are two different timeframes and scanner only allows 1 timeframe?

This is what I have

But this doesn't work as it errors out with this "Secondary period not allowed: 5 min"

This is what I have

Code:

```
input ShowTodayOnly = no;
def Today = if GetDay() == GetLastDay() then 1 else 0;
#Plot yesterday's high / low
def prevClose = if ShowTodayOnly and !Today then Double.NaN else close(period = "day" )[1];
Plot data = close(period = AggregationPeriod.FIVE_MIN) crosses above prevClose;
```

But this doesn't work as it errors out with this "Secondary period not allowed: 5 min"

Last edited by a moderator:

@showstopper In that case I'm not sure if it's possible.

@showstopper In that case I'm not sure if it's possible.

It's possible.

As you are both aware, the scanner does not support the full feature set that Thinkscript does. In this case, you know that secondary aggregations are not allowed. So, if you cannot use close(period = "day" )[1], then another way must be found.

What if we set a variable to remember the close of the last 5 minute bar from yesterday?

Ruby:

`def closeYesterday = if getday() <> getlastday() then close else closeYesterday[1];`

Here's a visualization of that code.

When using that definition in the scanner, ensure that the aggregation is set to "5 min" and that "Include Extended-Hours Trading session" is

1. How do I make it remember previous day's high? Basically I want to apply the same (if 5min close crosses above Previous day high)

2. How will the following work close 5min crosses below SVEPivots()."S3" The problem here is SVEPivots is taking daily aggregation but I want close of 5min.

Do you know how can 1 and 2 be coded?

I have this code - but it's not fetching the right results. To reiterate what I want is I want to scan for stocks which are crossing above their yesterday's high of the day on a current 5 min candle.

def highYesterday = if getday() <> getlastday() then high else highYesterday[1];

Plot data = close(period = AggregationPeriod.FIVE_MIN) crosses above highYesterday;

Oops. I spoke too quickly without thinking.def highYesterday = if getday() <> getlastday() then high else highYesterday[1];

Plot data = close(period = AggregationPeriod.FIVE_MIN) crosses above highYesterday;

You can use any of the below definitions for yesterday's daily values on an intraday chart.

Ruby:

```
def today = GetDay() == GetLastDay();
def mktOpen = SecondsFromTime(0930) == 0 or GetDay() <> GetDay()[1];
def yOpen = if today then yOpen[1] else if mktOpen then open else yOpen[1]; #yesterday's open
def yHigh = if today then yHigh[1] else if mktOpen then high else if high > yHigh[1] then high else yHigh[1]; #yesterday's high
def yLow = if today then yLow[1] else if mktOpen then low else if low < yLow[1] then low else yLow[1]; #yesterday's low
def yClose = if today then yClose[1] else close; #yesterday's close
```

Last edited:

Remember, this is just like the first example you had. You cannot use secondary aggregation periods in the scanner.

So, set the scan to 5 min time frame and do NOT check extended hours.

def highYesterday = if getday() <> getlastday() then high else highYesterday[1];

Plot data = close crosses above highYesterday;

Actually, I did try that as well. The problem here is the results which are showing up on scanner doesn't match the criteria I want. Ex: At the moment GS is showing up on the scanner. Yesterday's high of GS was 210.85 current 5 min price of GS is 209.35-209.50. I hope I am able to cite the problem statement correctly here.

see above. I edited my post just as you were writing this one. I misspoke earlier.Actually, I did try that as well. The problem here is the results which are showing up on scanner doesn't match the criteria I want. Ex: At the moment GS is showing up on the scanner. Yesterday's high of GS was 210.85 current 5 min price of GS is 209.35-209.50. I hope I am able to cite the problem statement correctly here.

see above. I edited my post just as you were writing this one. I misspoke earlier.

Awesome, this works. Thanks a lot for taking the time out to help me. Thank you so much.

Code:

```
#### Start Agg1
input agg1 = AggregationPeriod.min;
def o1 = open(period = agg1);
def h1 = high(period = agg1);
def l1 = low(period = agg1);
def c1 = close(period = agg1);
#def haclose = (o1+h1+l1+c1)/4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def trend1 = if haClose > haOpen then 1 else if haClose < haOpen then -1 else 0;
#### End Agg1
#### Start Agg2
input agg2 = AggregationPeriod.Five_min;
def o2 = open(period = agg2);
def h2 = high(period = agg2);
def l2 = low(period = agg2);
def c2 = close(period = agg2);
def haclose2 = (o2+h2+l2+c2)/4;
def haOpen2 = if haOpen2[1] == 0 then haClose2[1] else (haOpen2[1] + haClose2[1]) / 2;
def haHigh2 = Max(high, Max(haClose2, haOpen2));
def haLow2 = Min(low, Min(haClose2, haOpen2));
def trend2 = if haClose2 > haOpen2 then 1 else if haClose2 < haOpen2 then -1 else 0;
#### END Agg 2
#### TRADE LOGIC
def BuyCondition = if trend1 ==1 and trend2 ==1 then 1 else 0;
plot Buy = BuyCondition;
#plot Sell = if BuyCondition <> 1 then 1 else 0;
#### END TRADE LOGIC
```

All I want to do is to write code that flags when the ohlc4 closes above the upper Bollinger Band on a 5 minute chart.

I'm pulling my hair out.

Thanks very much in advance for any help you can give me.

Bob

post you code so we can where the error come in

ToS provides a thorough explanation: https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation

Code:

```
def today = GetWeek() == GetLastWeek();
def mktOpen = SecondsFromTime(930) == 0 or GetWeek() <> GetWeek()[1];
def yOpen = if today then yOpen[1] else if mktOpen then open else yOpen[1]; #yesterday's open
def yHigh = if today then yHigh[1] else if mktOpen then high else if high > yHigh[1] then high else yHigh[1]; #yesterday's high
def yLow = if today then yLow[1] else if mktOpen then low else if low < yLow[1] then low else yLow[1]; #yesterday's low
def yClose = if today then yClose[1] else close; #yesterday's close
def loworhigh = (close crosses yHigh) or (close crosses YLow);
plot test4 = loworhigh;
test4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
```

Hi,

I need some help with my Scanner , TOS is not allowing to have an another period. I want to scan for below criteria .

Please help me

I need some help with my Scanner , TOS is not allowing to have an another period. I want to scan for below criteria .

Please help me

Code:

```
input price = FundamentalType.CLOSE;
input aggregationPeriod = AggregationPeriod.HOUR;
#input aggregationPeriodD = AggregationPeriod.DAY;
input length8 = 8;
input length34 = 34;
input length5 = 5;
input length13 = 13;
input averageType1 = AverageType.EXPONENTIAL;
input averageType2 = AverageType.EXPONENTIAL;
input crossingType = {default above, below};
def avg8 = MovingAverage(averageType1, Fundamental(price, period = aggregationPeriod), length8);
def avg34 = MovingAverage(averageType2, Fundamental(price, period = aggregationPeriod), length34);
def avg5 = MovingAverage(averageType1, Fundamental(price, period = AggregationPeriod.DAY), length5);
def avg13 = MovingAverage(averageType2, Fundamental(price, period = AggregationPeriod.DAY), length13);
def Crossabove513Daily = Crosses(avg5, avg13, crossingType == crossingType.above);
def Crossabove834Hour = Crosses(avg8, avg34, crossingType == crossingType.above);
plot mylist = Crossabove513 and Crossabove834;
```

Last edited:

Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|

How to Fix "importing shared item" Error in ThinkorSwim | Tutorials | 2 | ||

Ichmoku Study Needing a little fix | Questions | 4 | ||

How to Fix ThinkorSwim Stuck on Installing Updates | Questions | 21 | ||

M | thinkScript Expected Double Error: How to Fix? | Questions | 10 | |

D | Combo Williams Vix Fix Indicator for ThinkorSwim | Indicators | 2 |