Todays 15 minute bar HL2 closes below displaced SMA from daily bars

trader11

New member
Todays 15 minute bar HL2 closes below displaced SMA from daily bar data? I know how to do it with daily bars closing price crossing below the displaced daily SMA, but not for 15 minute bars, which gives a timely signal
 
Solution
typos

Code:
declare upper;
input SMALength = 12;
input Displace = 3;
def FifteenMin_HL2 = HL2(period = AggregationPeriod.FIFTEEN_MIN);
def Day_CLOSE = close(period = AggregationPeriod.DAY);
def Day_SMA = SimpleMovingAvg(price = Day_Close, length = SMALength, displace = Displace);
plot enter = if FifteenMin_HL2 crosses above Day_SMA then LOW else double.nan;
plot exit = if FifteenMin_HL2 crosses below Day_SMA then HIGH else double.nan;
enter.SetPaintingStrategy(paintingStrategy = PaintingStrategy.ARROW_UP);
exit.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
This might work. It's always good practice to be as verbose in your code as you need to be. I like to go step by step rather than try to pack it all into a single line.

Be warned, I typed this into the posting-editor here at useToS, not into ToS, so there may be typos. Adjust your SMALength and Displacement according to your needs.

From the ToS docs concerning SimpleMovingAvg():
Displacement: The displacement of the SMA study, in bars. Positive values signify backward displacement.

Code:
declare upper;
input SMALength = 12;
input Displace = 3;
def FifteenMin_HL2 = HL2(AggregationPeriod=FIFTEEN_MIN);
def Day_CLOSE = CLOSE(AggregationPeriod=DAY);
def Day_SMA = SimpleMovingAvg(price = Day_Close, length = SMALength, displace = Displace);
plot enter = if FifteenMin_HL2 crosses above Day_SMA then LOW else double.nan;
plot exit = if FifteenMin_HL2 crosses below Day_SMA then HIGH else double.nan;
enter.setPaintingStrategy(PaintingStragegy.ARROW_UP);
exit.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Happy Trading,
mashume
 
Hey I didnt see your post. I see what youre trying to do but TOS aint having it
It gives me back this :

def FifteenMin_HL2 = HL2(AggregationPeriod=FIFTEEN_MIN);
def Day_CLOSE = CLOSE(AggregationPeriod=DAY);

no such parameter aggregationperiod at 4:22
no such parameter aggregationperiod at 5:17

guessing it dont like these two time periods mixing
aint i dont need paint bars

i want to catch intraday move (from a close of a15 minute bar) that goes below a displaced daily SMA. Anyone>? is this too much >?
 
Last edited by a moderator:
typos

Code:
declare upper;
input SMALength = 12;
input Displace = 3;
def FifteenMin_HL2 = HL2(period = AggregationPeriod.FIFTEEN_MIN);
def Day_CLOSE = close(period = AggregationPeriod.DAY);
def Day_SMA = SimpleMovingAvg(price = Day_Close, length = SMALength, displace = Displace);
plot enter = if FifteenMin_HL2 crosses above Day_SMA then LOW else double.nan;
plot exit = if FifteenMin_HL2 crosses below Day_SMA then HIGH else double.nan;
enter.SetPaintingStrategy(paintingStrategy = PaintingStrategy.ARROW_UP);
exit.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Solution
Hi Mashume,
Again, my dumbass didnt see your post, I apologize !! Thank you for your esteemed feedback on the code, I am getting an error "Exactly one plot expected".
Also, is this to be used as a custom scan? I legitimately only want the code to check for when 15 minute bars close below the displaced moving average.
And I wont be charting so idk what paint bars is all about,

Thanks for your feedback
I will turn on notifications in case you respond again!
 
also btw, it doesnt like secondary period again.
"secondary period not allowed 15 min"
this is when I erase plot exit and exit painting strat code
The ToS platform does not allow multiple timeframes to be used in the scan hacker, watchlists, conditional orders, etc...
This code is only for plotting on a chart.
 
Then how can I know when an sma is crossed by price within an intraday framework?
thanks
Not sure that I understand your question. The ToS platform does not provide the ability to scan for daily SMA crossed by 15 min price.
Multiple timeframes can not be used in scans, watchlists or conditional orders. Your script can only be plotted on a chart. If you leave the chart open, you could set up an alert.
https://usethinkscript.com/resources/how-to-add-alert-script-to-thinkorswim-indicators.9/


FYI: The scanner works fine as long as you are scanning for a 15 min SMA crossed by 15min price. Just use the built-in functions. No custom script is required.
 
Last edited:
Not sure that I understand your question. The ToS platform does not provide the ability to scan for daily SMA crossed by 15 min price.
Multiple timeframes can not be used in scans, watchlists or conditional orders. Your script can only be plotted on a chart. If you leave the chart open, you could set up an alert.
https://usethinkscript.com/resources/how-to-add-alert-script-to-thinkorswim-indicators.9/


FYI: The scanner works fine as long as you are scanning for a 15 min SMA crossed by 15min price. Just use the built-in functions. No custom script is required.
Then the only way would be to displace the 15 Min EMA to be synchronous with the Daily displacement, something like a -350 displacement on a 15 minute Globex chart. Problem is Id have to figure out the value for RTH stocks

Annnndd the value Id need to input into the scan would change each day, admittedly it would work, but wow.. is there another platform that supports this scan with two time frames?
😄
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
481 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top