Secondary aggregation not allowed in scans


Category:
0
0

Hello, I have created a script that alerts for any stock price getting close to previous day’s close. it work as far as I ave tested. However when I convert it to study I cannot use it for  Aggregate Period 5 min. I can only use for aggregate Period Day. The error I get is Secondary Period not allowed: Day

Any help would be greatly appreciated

code for Study

def MarketOpenTime = 930;
def aggregationPeriod = AggregationPeriod.DAY;
def length = 1;
def displace = -1;
def showOnlyLastPeriod = yes;
def prevDayClose;
def HOD = high(period = AggregationPeriod.DAY);
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
prevDayClose = Double.NaN;
} else {
prevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}
plot reachingClose = SecondsFromTime(MarketOpenTime) > 1 and low > prevDayClose and low <= prevDayClose + (prevDayClose * 0.3 / 100) ;
reachingClose.SetDefaultColor(Color.GREEN);
reachingClose.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

def SoundAlert = reachingClose and close[-1] <> reachingClose;
Alert(SoundAlert, “Price Reaching Previous Close of Day” + GetSymbol(), Alert.ONCE, Sound.Ding);
#AddLabel(yes, close crosses prevDayClose or close equals prevDayClose, Color.RED);
#AddLabel(yes, prevDayClose, Color.BLUE);
#AddLabel(yes, prevDayClose + (prevDayClose * 0.3 / 100), Color.PINK);
#AddLabel(yes, prevDayClose – (prevDayClose * 0.3 / 100), Color.PINK);

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on October 14, 2019 5:55 pm
1458 views
0

"Converting Study to Scanner" is not the best title for this question. There are many examples of converting studies into scans in the Q&A forum. How is your's different? That's what your question title needs to include. Otherwise how are viewers supposed to understand that your post is different from all the others that have already been asked?

The other issue is that you posted you question in the wrong topic. You posted this in the "Frequently Asked Questions" topic when it should have been posted in the "Stock Scanners" topic. These details are important because your question is going to help the rest of our audience avoid this problem. But if you use the wrong title and post in the wrong topic you are helping no one.

I will fix all of those items before providing a solution. But doing so will break the URL link to this question. The new question title will be: "Secondary aggregation not allowed in scans". Which is the phrase you should have used when searching for this solution in the first place.

( at October 15, 2019 9:27 am)
0
Private answer

You have found that secondary aggregation periods are not supported for custom scans. The only way to work around this limitation is to re-write your code so that it no longer uses secondary aggregation periods. So while you thought you were asking how to convert a study to scan, the real issue is how to convert your code to no longer use secondary aggregation periods.

The solution is quite complex. Since you posted your own code I will take that to mean you are trying to learn. So rather than provide the solution for you I will provide a link to a previous post that captures the previous day close without using a secondary aggregation period:

https://www.hahn-tech.com/ans/stocks-crossing-above-previous-day-close-after-1030/

 

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on October 15, 2019 9:46 am