Afterhours entry and exit after X amount of points ?


New member
I'm Long time lurker, first time poster. Tried searching and googling my answer but couldn't seem to. Perhaps I'm thinking about this wrong and you can teach me how to code it properly. I'm trying to back test a strategy but I need help in setting up the entry and exit conditions.

Im attempting to do the adjustments to the halftrend indicator here


So I'm trying to only allow trading on after hours so 4 pm to 9.30 am ,

For the Entry : no entry signal should be executed as entry unless it appears after 4pm till 9.30 am ,

And for the exit : i want the exit to be a profit target of 5 dollars above the entry price and the stoploss at 5 dollars bellow the entry price

And i need to note that the entry signals can be both short and long , and only one position is allowed at a time

So as the picture states , if the signal is short , then the entry have a profit target x point bellow entry , and stop loss X points above , if non of the points where hit by the time a new signal appears , the position is closed on the close of the bar with the new signal and a new position is open

Can i get help on this please!
Last edited by a moderator:


New member
Would it also be possible to adjust another code but on this one , instead of closing a position upon the closing of a bar with a signal , wait for the position to hit the target or stop loss first before starting the new position
this would be great help to me

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
230 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.