New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.
From what I can find there is no Supertrend indicator built into the scanning system. So I am trying to write one myself that identifies when the Supertrend indicator is bullish, but I am getting an error, not sure what I'm doing wrong here:
[((daily max(7,close) + daily min(7,close)) / 2) + (3 * ATR(7)) < close]
I am getting this:
Could not parse "" located in the clause "((DAILY MAX(7,CLOSE) + DAILY MIN(7,CLOSE)) / 2) + (3 * ATR(7))"
0
Comments
Although Stockcharts does add new indicators from time to time, I don't see Supertrend either. But it does seem to resemble Parabolic SAR, if that interests you.
As for the scan, this passes syntax:
// begin
[group is sp500]
and [[[daily max(7,close) + daily min(7,close)] / 2] + [3 * ATR(7)] < close]
// end
but check whether the groupings are what you want.
When you group things, the scan language [unlike most other languages] wants square brackets -> [ ], not parens.
The parens -> ( ) are reserved for built-in functions like max( ), and indicators/overlays like sma(... ) or MACD Line( ...) .
Also, the errors from the editor approximate where the error is, but the error is not always identified very helpfully. In this case, it would have been the first parens that triggered the error, but you would never guess why from the error message.
Can't Parse is usually a ( ) issue but also can just be that the system can't do what you are asking.
[ ] issues usually result with an error message about mis-matched brackets.
I'd say that the "Supertrend" can also be like the the Chandelier Exit or Keltner Channel, which also use the ATR value in their plot.
and [[[daily max(7,close) + daily min(7,close)] / 2] + [3 * ATR(7)] < close]
Run it against
[[exchange is NYSE] or [exchange is NASD]]
and change the date offset a few times. Some days you get hits, some days you don't. If you get hits, the logic is valid.
What I'm trying to do is take the maximum price (over the last 7 days) plus the minimum price (over the last 7 days) and average that out; and then add the ATR of the last 7 days * 3, and compare that to the last close. If that's lower than the last close, it's in an uptrend.
Ultimately I want to isolate those stocks that had a recent crossover of their close from above to below (which would be a buy signal), which I know how to do if I can get this part working right.
To get the Close to be > 3 times ATR 7 plus the middle price channel is going to be a large rapid movement. On ThinkorSwim, it appears that they use a moving average of the ATR instead of the raw ATR number in their SuperTrend line calculation. And they allow you to pick the MA but many I've seen talk Hull MA.
So perhaps use + 3 * EMA(7,ATR(7)) or + 3 * HullMA(7,ATR(7)) on the ATR side of the equation, and the Middle Price Channel on that Min/Max side of the equation.
Most indicators/overlays introduce some kind of lag - either calculated like an MA or "imposed", like price channels. Max and min don't have a lag - they are as of the current bar, so if there is a big jump, it's included in the calculation. That makes it a higher hurdle to generate a signal because the big jump is included. But if you don't include the current bar, the current bar behavior is compared to only the previous bars, which should make a signal easier to reach.
P.S.
@CarissaT
I ran this for the past few days (including mid day today) and got some good hits.
[group is sp500]
and [[[1 day ago max(7,close) + 1 day ago min(7,close)] / 2] + [3 * 1 day ago ATR(7)] < close]
https://www.backtestzone.com/webapp
The Supertrend buy/sell trigger seemed to generate the most consistent positive results vs. buy and hold for the stocks I'm interested in swing trading. When I have less tequila in my system I'll wrap my head around the details and provide a better response on what works well for this indicator. I've thrown in a few other criteria like moving average crossovers etc. but have yet to find one that works better than the Supertrend. That being said I've only been swing trading for a year and there are a lot of indicators that I haven't tried to wrap my head around yet.
and [[[1 day ago max(7,close) + 1 day ago min(7,close)] / 2] + [3 * 1 day ago ATR(7)] < close]
I often double or triple my results (so I get more), and then use some type of RANKING to sort
and [
[[[1 day ago max(7,close) + 1 day ago min(7,close)] / 2] + [3 * 1 day ago ATR(7)] < close]
OR [[[2 days ago max(7,close) + 2 days ago min(7,close)] / 2] + [3 * 2 days ago ATR(7)] < close]
OR [[[3 days ago max(7,close) + 3 days ago min(7,close)] / 2] + [3 * 3 days ago ATR(7)] < close]
]
The others seem to be buyouts, with no further upside potential because price has jumped to the buyout price, or buying climaxes (or short squeezes) in (probably) manipulated stocks.
So, it would probably work best in well established mid to large cap cyclical stocks, probably belonging to an index, that have a period of accumulation (a more or less orderly price range running horizontally slightly above its 52 weely low channel for several weeks, maybe a few months) and then breaking the quarterly or annual upper price channel (see ELBT beginning 10/7/24 scan hit date for a good example).
Any erratic chart - random wide price bars and gaps in both directions, random volume variations - should probably be avoided. Institutions don't buy those stocks, and that's what you need for big gains.