Specific entry date and time

Melch20

New member
In the ToS Charts page, I have this code in Strategies for selling one vertical put spread:

Code:
def sell=if close()<open and close[1] then 1 else 0;

AddOrder(type = OrderType.SELL_AUTO, condition = sell, price = close, tradeSize = 100);

The code works and 1 options contract is sold (there is an arrow with the tekst -100 and the FloatingPL shows the correct P&L bars). But to me, it looks like the moment of selling the option contract is at a random day and time.

How can I add a specific date and time for selling the vertical put spread to this code? For example sell on date 5/7/21, time 9.03pm?

I will use this very simple strategy to start understanding backtest trading bull put spreads. I will add a trailing profit/loss to my strategy later.
 
Last edited:
the sell condition is triggered when the def sell = formula is true, when a candle closes red, which is quite often.
there is nothing in the formula to specify date or time.
close[1] isn't a boolean value, it isn't being compared to anything. so i think it will be interpretted as a non 0 , so true.

here is a study to experiment with. it lets the user specify a date and time, then draws an arrow on that bar.
Ruby:
# enter_date_time_01

# halcyonguy
# 2021-06-17
# specify a date and time. draw an arrow on that bar

input time1 = 1000;     # HHMM , 24 hour EST
input date1 = 20210617; # YYYYMMDD

# does the current time and date match desired?
def timez = SecondsFromTime(time1) == 0;
def datez = ( date1 == GetYYYYMMDD() );
def desiredbar = timez and datez;

plot z1 = desiredbar;
z1.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
z1.setDefaultColor(color.cyan);

#addchartbubble( 1 , low, "T" + timez + "\nD" + datez + "\n" + desiredbar, color.cyan, no);
#
 
Thank you very much. This strategy let you specify the date and time you want to enter the trade. I use this strategy for back testing bull put spreads on the Charts page. It sells one options contract.

Code:
# enter_date_time_01

# halcyonguy
# 2021-06-17
# specify a date and time. draw an arrow on that bar

input time1 = 1300;        # HHMM , 24 hour EST
input date1 = 20210420;    # YYYYMMDD

# does the current time and date match desired?
def datez = ( date1 == GetYYYYMMDD() );
def timez = SecondsFromTime(time1) == 0;

#def desiredbar = datez and datez;

addOrder(OrderType.SELL_TO_OPEN, condition = datez and timez,  1);
 
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
216 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