1
votes

Is there an option to set on pine script such that when a new order command is submitted, it would cancel the previous unfulfilled one?

if secondbuycond and firstbuycond and (time >= testPeriodStart and time <= testPeriodStop)
    strategy.entry("buy", strategy.long, stop=((valuewhen(firstbuycond,open,0))*x))
    strategy.exit("Trailing Stop", "buy", trail_points= trailPoints, trail_offset= trailOffset, when= testType == 'Trail Points')
1

1 Answers

0
votes
//@version=3
strategy("My Strategy", overlay=true)

limit_price = 0

ts = timestamp(2018, 11, 13, 0, 0)
if (time > ts)
    limit_price := 999

ts2 = timestamp(2018, 11, 22, 0, 0)

// here new price will be set to replace an order
if time > ts2
    limit_price := 988

strategy.entry("BUY", strategy.long, limit=limit_price)

It's possible to replace just making an entry again with new price, but both entries must differ only in price (so the order ID and direction must be the same) I tested the stragegy above in CHMF, dayly resolution.