Mikey A. Leonetti
Mikey A. Leonetti

Reputation: 3352

Is there such a thing as process_orders_on_open in pinescript?

It seems that the default behaviour for pinescript is to open a strategy.entry order on the next bar. Is it possible to have strategy.entry open a trade at the beginning of the bar?

You can see this outlined in this script here

//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)

s = sma( open, 14 )

plot(s,color=color.green)
plot(open,color=color.blue)

longCondition = open>s
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = open<s
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)

You'll see that the trades come in "late." As in, the bar AFTER the blue line crosses the green.

Upvotes: 0

Views: 572

Answers (1)

bbnm
bbnm

Reputation: 1094

No such thing atleast on historical bars as far as I know. The candle needs to close to "confirm" the signal. You can however enable calc_on_every_tick.

strategy(..., calc_on_every_tick=true)

This will will enter trades on bars that are still "forming" (repainting) and when the bars have not closed, for present and future bars, not on historical bars.

Upvotes: 2

Related Questions