Reputation: 1
I have discovered an inconsistency between my strategy and my indicator. If I make the measurements directly over the indicator, then I have the right entry point. If I do the whole thing within a strategy, then the trade is always delayed for one candle.
for more clearly:
My idea is very simple. If SAR moves from the top of the candle to the bottom of the candle, it is a buy position. If SAR moves from the bottom of the candle to the top of the candle, it is a sell position.
//@version=5
strategy("myStrategy", overlay=true,calc_on_every_tick = true, process_orders_on_close =true)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2, "Max Value")
SAR = ta.sar(start, increment, maximum)
plot(SAR, "ParabolicSAR", style=plot.style_cross, color=#f2f4f8,linewidth = 4)
if SAR[1]>high[1] and SAR<low
strategy.entry("Buy", strategy.long,comment="Buy",qty=1)
if SAR[1]<low[1] and SAR>high
strategy.entry("Sell", strategy.short,comment="Sell",qty=1)
If I analyze my strategy by my eyes, when SAR indicator draws its icon on chart (at opening point of the current candle), I open the position. But if I implement my strategy by pine script editor, it opens the position at the closing point of the current candle.
I wants the pine script immediately opens the position after SAR movement (at the open of candle not close of candle) (see the attached Screenshots)
Where does this difference come from and how can i set the trade in the strategy to the same candle as the indicator is drawing an arrow down/up?
Upvotes: 0
Views: 1074
Reputation: 21342
By default your strategy will enter a trade on open of the next candle. You can alter this if you set process_orders_on_close
argument of the strategy()
call to true
.
You can also do this via the properties window.
process_orders_on_close (const bool) When set to true, generates an additional attempt to execute orders after a bar closes and strategy calculations are completed. If the orders are market orders, the broker emulator executes them before the next bar's open. If the orders are price-dependent, they will only be filled if the price conditions are met. This option is useful if you wish to close positions on the current bar. This setting can also be changed in the strategy's "Settings/Properties" tab. Optional. The default is false.
By default the strategy are not executed on every tick. So, when you look at your chart in real-time, you might not see your plots. To enable calculations on each tick, you can set the calc_on_every_tick
argument of the strategy()
function to true
.
You can also do that via the properties window.
calc_on_every_tick (const bool) Specifies whether the strategy should be recalculated on each realtime tick. If true, when the strategy is running on a realtime bar, it will recalculate on each chart update. If false, the strategy only calculates when the realtime bar closes. The argument used does not affect strategy calculation on historical data. This setting can also be changed in the strategy's "Settings/Properties" tab. Optional. The default is false.
Upvotes: 1