I am using
pinescript 4.0
In the chart below, I was executing a strategy
that uses the following:
if exec_long
// entry condition
if crossover(rsi, ema ) and inDateRange and close > close[1]
strategy.entry("MAN Long Entry Id", strategy.long)
The problem I am having is that the entry takes place at the top of the next candle ( see arrow pointing to the right). To me, this could mean money is lost (due to a late entry). How can I fix this so that the entry takes place at the exact time the RSI crosses over the EMA
(for both Shorts and Longs)?
TIA
EDIT
@e2e4 - thanks for the response. I will try the setting. Out of curiosity, can it be ran in a real-time/production environment?
I have added the example for a SHORT entry example. In the example, the position is "stopped out" because the entry takes place at the bottom of the candle. Being "stopped out" would not have happened if the entry took place at the top of the candle ( see picture SHORT #1) - OR - if it took place on the "dotted line" in the picture SHORT #2 (the goal was to keep the stop-loss amount as low as possible).
=> With that being said was wondering if you knew of any code on the Tradingview site that perhaps provides some kind of guidance (or code) to executing entries (using pinescript) that do not get "stopped out" due to the situation taking place with the LONG example (sent earlier) or with the SHORT example (shown in the pictures of SHORT #1 and SHORT#2)
TIA
Strategy and study scripts are executed with different logic. More info on broker emulator: https://www.tradingview.com/pine-script-docs/en/v4/essential/Strategies.html#broker-emulator
On TradingView, strategies are calculated on all the chart’s available historical data (backtesting), and then automatically continue calculations when real-time data comes in (forwardtesting). By default, during both historical and real-time calculation, code is calculated on the bar’s close. When forwardtesting, you have the option of configuring script calculation to occur on every real-time tick. To enable this, check the Recalculate On Every Tick option in the strategy’s Settings/Properties, or specify it in the script’s code using:
strategy(..., calc_on_every_tick = true)
You can set the strategy to perform one additional calculation after an order is filled. For this you need to check Recalculate After Order filled in the strategy’s Settings/Properties, or do it in the script’s code using:
strategy(..., calc_on_order_fills = true)
You may find this article from backtest-rookies useful, explains the delay of 1 and sometimes 2 candles between the signal and order execution: https://backtest-rookies.com/2017/11/15/backtesting-101-trades-delayed/