'Pine script strategy open trade as at crossover not at bar close

I am trying to enter position right at the cross of current price EMA200 and not at the bar close price. I dont care if the price has retracted. Is there any way to achieve this?

strategy('EMA200 5 min', overlay=true, process_orders_on_close=true)
ema_200 = ta.ema(close, 200)

// For LONG check if previous bar crossed over EMA200 and set order when current bar crosses EMA200
cross_over = ta.crossover(close[1], ema_200)
cross_over_touch = ta.cross(close, ema_200)

// Long Take Profit
long_tp_inp = input.float(1, title='Long Take Profit %', step=0.1, group='Set Take Profit %') / 100
long_take_level = strategy.position_avg_price * (1 + long_tp_inp)
// Long Stop Loss 
long_sl_inp = input.float(0.5, title='Long Stop Loss %', step=0.1, group='Set Take Profit %') / 100
long_stop_level = strategy.position_avg_price * (1 - long_sl_inp)

// Strategy Execution
entry_long = cross_over and cross_over_touch and inDateRange
entry_price = ta.valuewhen(ta.cross(close, ema_200), close , 1)

strategy.entry(id='Long', direction=strategy.long, when=entry_long, limit=entry_price)
strategy.exit('Take Profit/ Stop Loss', 'Long', stop=entry_price, limit=long_take_level)

The line where I set limit=entry_price doesnt seem do do anything.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source