0

How can one make a strategy entry order immediately after all conditions were satisfied? E.g. if(open_price > _some_condition) strategy.entry(...) I used "strategy(...process_orders_on_close=true)”, but I would like to make an order not on this bar’s close price, but on this bar’s open price (so immediately).

On the "Strategies" page (https://www.tradingview.com/pine-script-docs/en/v4/essential/Strategies.html#broker-emulator) it says "Unlike in real trading, the emulator only fills orders at chart prices, which is why an order can only be filled on the next tick in forwardtesting and on the next bar or later in backtesting, i.e., after the strategy calculates". Does anyone know how to overcome this issue and place an order on the spot? Otherwise backtesting does not provide rear-life and useful data.

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
Nikita Sydorenko
  • 11
  • 1
  • 2
  • 3

3 Answers3

0

Scripts calculate on the close of historical bars, so you can't detect a condition on the close and go back in time to place an order on the bar's open.

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
0

the open price for the current bar is the close price for the last bar. So using your example, you would have:

if(close[1] > _some_condition)

which is the same as

if(close > _some_condition)

but with the latter, if you are using the condition to execute an order, then you will likely execute multiple orders as the "close" price is the current price until the next bar starts. Meaning the condition could be satisfied multiple times as the price fluctuates.

So if you are wanting to use the condition to execute an order then the first example would be the way to go

Yugenswitch
  • 125
  • 2
  • 5
0

By default, they only execute when the realtime bar closes, but the calc_on_every_tick parameter of the strategy declaration statement can be set to true to modify the strategy’s behavior so that it executes each time the realtime bar updates, as indicators do. The behavior described here for indicators will thus only apply to strategies using calc_on_every_tick=true.

https://www.tradingview.com/pine-script-docs/en/v5/language/Execution_model.html#events-triggering-the-execution-of-a-script