Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

pine script - Strategy to open order at end of day and close order at open of the next day on the daily chart

This is a snippet of the script. The strategy is meant for the daily chart and each bar is for the day. The script will look to see if DI+ or DI- is on top. If DI+ is on top, enter a long position at the end of the day and close the position at the open of the next day. If DI- is on top, open a short position and close the position at the open of the next day. I've gotten close, but "process_orders_on_close" closes the position using the close price instead of the open.

I'm stump and not even sure if this is possible. Any help would be greatly appreciated. Thanks!

@version=4

strategy("Sam's Strategy", overlay=true, process_orders_on_close = true,initial_capital=10000)


plot(plus, color = color.green, title="plusDI")
plot(minus, color = color.red, title="minusDI")

overallLong = bool(na)
overallShort = bool(na)


Decision = bool(na)
//ADX enters zone between DMI for the first time
//  if green above red, go calls
Decision := if plus > minus
    Decision := true
    overallShort := na
    overallLong := true
//  if red above green, go puts
else if minus > plus
    Decision := true
    overallLong := na
    overallShort := true
else
    na

strategy.close_all()
//strategy part

if (afterStartDate and overallLong)
    strategy.entry("GG-EL", long=true)
if (afterStartDate and overallShort)
    strategy.entry("GG-ES", strategy.short)
question from:https://stackoverflow.com/questions/65866839/strategy-to-open-order-at-end-of-day-and-close-order-at-open-of-the-next-day-on

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...