AddOrder On First Candle Of Each Day

StockFibber

New member
Hi, I want to add an order at the first candle of each trading day, but currently what I have is only posting an order on the first day and none of the subsequent days. I plotted "dayopen", "daytime" and "secondstillTime(start)" to see if they are doin what I expect and it looks like they are. When I have a 5 day, 1 minute chart setup, only the first day gets an order, how do I get an order on the first candle every day?

Screenshot 2024-02-18 150552.png


Code:
# day_open1

def na = Double.NaN;

# open/close times  (EST)
input start = 0930;
input end = 1600;
input shares = 5;
input ProfitTargetPcnt=0.05;

def dayopen = if secondstillTime(start) == 0 then 1 else 0;
def daytime = if secondsfromTime(start) >= 0 and secondstillTime(end) > 0 then 1 else 0;

def openbar = if !daytime then na
 else if dayopen then hlc3
 else openbar[1];


AddOrder(OrderType.BUY_TO_OPEN,dayopen, open[-1], shares, Color.YELLOW, Color.YELLOW);

plot z1 = openbar;
z1.SetDefaultColor(Color.green);
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z1.hideBubble();
 
Solution
This is the intended operation of the ToS AddOrder() function. WIthout making some changes, it will only place a single 'open' order of any sort. It will place additional orders after you have 'closed' the open position.

To change this behavior, per the manual page here:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder

you need to open the global settings page by clicking the bottom left button in this screen shot:

bbAggU9.png


This box then opens:

mXRKy9h.png


Setting the radio button to "regardless of the entry that generated the order" will allow the same script (in your case the same BUY_TO_OPEN AddOrder() call to 'open' additional...
This is the intended operation of the ToS AddOrder() function. WIthout making some changes, it will only place a single 'open' order of any sort. It will place additional orders after you have 'closed' the open position.

To change this behavior, per the manual page here:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder

you need to open the global settings page by clicking the bottom left button in this screen shot:

bbAggU9.png


This box then opens:

mXRKy9h.png


Setting the radio button to "regardless of the entry that generated the order" will allow the same script (in your case the same BUY_TO_OPEN AddOrder() call to 'open' additional positions up to the number specified in the top box. If you set the number to 2, your script will buy at the open twice, if you set it to 7, then 7 order may be placed.

-mashume
 
Solution

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
381 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