I am using pinescript to do the backtest with my strategy. In the bull market, how I can place a buy order when the price pulls back to the ema5 . In the bear market, how I can place a short order when price pull up to the ema5. I want the order can be executed immediately when price pull back to the ema5 not after the bar close
You do that with limit orders. strategy.entry()
has limit
and stop
arguments which you can use for this purpose.
strategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert) → void
limit (series int/float) An optional parameter. Limit price of the order. If it is specified, the order type is either 'limit', or 'stop-limit'. 'NaN' should be specified for any other order type.
stop (series int/float) An optional parameter. Stop price of the order. If it is specified, the order type is either 'stop', or 'stop-limit'. 'NaN' should be specified for any other order type.