title: Trying to correctly configure entry orders in Pinescript Backtesting
body: <p>Hi I am writing a script in Pinescript for backtesting a simple StochasticRSI strategy. </p>
  
  <p>I have set up the code to enter a limit order when 20 > K > 80. The limit order moves dynamically with every candle and is based on the lowest high  or the highest low for the past 3 candles. </p>
  
  <p>For ease of debugging Ive plotted the limit order along with the stop order on the chart. But when I run the backtest my orders enter at the market price when a buy/sell condition is true. I've configured strategy.entry() with limit and stop parameters, but they seem to have no effect. </p>
  
  <p>How do I configure my entry orders to only enter at the limit order price during a buy/sell condition and not market price?</p>
  
  <pre><code>//@version=3
  strategy(title="StochasticRSI Strategy",
     shorttitle="SRSI",
     overlay = true,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=1,
     pyramiding=0)
  
  Debug = input(title='DEBUG', defval=1) 
  
  // ****************** INDICATOR SETUP ****************** \\
  
  // Inputs for indicators
  smoothK = input(title = 'Smooth K', defval = 3, minval = 1)
  smoothD = input(title = 'Smooth D', defval = 3, minval = 1)
  lengthStoch = input(title = 'Stochastic Length', defval = 14, minval = 1)
  lengthRSI = input(title = 'RSI Length', defval = 14, minval = 1)
  src = input(close, title="RSI Source")
  oversold = input(title='RSI Oversold Level', defval=20)
  overbought = input(title='RSI Overbought Level', defval=80)
  
  // Computation of algorithms
  rsi1 = rsi(src, lengthRSI)
  K = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
  D = sma(K, smoothD)
  
  // Plotting StochasticRSI
  plot(Debug ? na : K, color = aqua, title='K%')
  plot(Debug ? na : D, color = orange, title='D%')
  
  // Plotting RSI
  // rsi1_color = rsi1 &lt; oversold ? green : rsi1 &gt; overbought ? red : blue // change color of rsi if overbought/sold
  // rsi1_toggle = input(title="RSI On/Off", type=bool, defval=true)
  // plot(rsi1_toggle ? rsi1 : na, color=rsi1_color)
  // h0 = hline(overbought, title='Overbought')
  // h1 = hline(oversold, title='Oversold')
  // fill(h0, h1, color=purple, transp=80, title='Fill')
  
  
  
  // ****************** MONEY MANAGEMENT ****************** \\
  trade_value = ((strategy.netprofit + strategy.initial_capital) * input(title='% Equity per trade', defval=0.01)) // this will be a percentage of total equity normally 1-3%
  trade_quantity = trade_value/close // Should be current price at the time of exectuion ask or bid depending on direction
  profit = strategy.equity - (strategy.netprofit + strategy.initial_capital) // Positive if trade is in profit and negative if trade is at a loss
  ticksize = 10 // 10 ticks for every dollar 
  
  
  
  // ****************** STRATEGY ****************** \\
  
  // buy_condition = crossunder(rsi1, oversold)
  // sell_condition = crossunder(rsi1, overbought)
  buy_condition = K &lt; oversold
  sell_condition = K &gt; overbought
  
  
  // ****************** Limit Orders ****************** \\
  
  manual_limit_lookback = input(defval=5, title='Limit Lookback')
  limit_lookback = manual_limit_lookback
  limitbuffer = input(defval=10, title='Limit Buffer')
  limit_short = highest(low, limit_lookback) - limitbuffer
  limit_long = lowest(high, limit_lookback) + limitbuffer
  
  // ****************** Stop Loss ****************** \\
  
  stop_strategy = input(title='Stop Strategy', options=[1, 2, 3], defval=1)
  stop_lookback = input(title='Stop Lookback Period', defval=3)
  stop_buffer = input(title='S1 StopBuffer', defval=10) * syminfo.mintick 
  
  // Stop Loss Strategy #1 Use a manual input
  stop_loss_short = if stop_strategy == 1
      highest(high, stop_lookback) + stop_buffer
  
  stop_loss_long = if stop_strategy == 1
      lowest(low, stop_lookback) - stop_buffer
  
  // // Stop loss strategy #2 Use Average true range
  // else
  //     if stop_strategy == 2
  //         atr(14)*ticksize
  
  
  // // Stop loss strategy #3: 
  //     else
  //         if stop_strategy == 3
  //             trade_value*(input(title='% Risk per Trade', defval=1, minval=1))/100 // Percentage of risk for calculating stop
  
  
  // ****************** Take Profit ****************** \\
  
  profit_strategy = input(title='Profit Strategy', type=string, options=['P1', 'P2', 'P3'], defval='P3')
  
  // Take Profit Strategy #3: Use Opposite Signal
  strategy.close("SELL", when=(profit_strategy =='P3' and buy_condition))
  strategy.close("BUY", when=(profit_strategy =='P3' and sell_condition))
  
  
  // ****************** BACKTESTING CONFIGURATION ****************** \\
  
  if buy_condition and time &gt; timestamp(2019, 02, 23, 09, 30) // and strategy.position_size &lt; trade_quantity 
      // strategy.order("BUY", strategy.long, limit=limit_long, oca_name="Buy condition", oca_type=strategy.oca.cancel)
      strategy.entry("BUY", strategy.long, limit=limit_long, stop=stop_loss_long, when=strategy.position_size == 0)
      // strategy.order("BUY", strategy.long, qty=trade_quantity)
      // strategy.exit("Buy Exit", "BUY",  profit=take_profit, loss=stop_loss) // profit and loss are computed in pips
      // strategy.exit("Buy Exit", "BUY",  limit=close + trade_risk, stop=close - trade_risk) // limit and stop are price exits
  else
      strategy.cancel("BUY")
  
  
  if sell_condition and time &gt; timestamp(2019, 02, 23, 09, 30)  //and strategy.position_size &gt; trade_quantity 
      // strategy.order("SELL", strategy.short, limit=limit_short, oca_name="Buy condition", oca_type=strategy.oca.cancel)
      strategy.entry("SELL", strategy.short, limit=limit_short, stop=stop_loss_short, when = strategy.position_size == 0)
      // strategy.order("SELL", strategy.short, qty=trade_quantity)
      // strategy.exit("Sell Exit", "SELL", profit=take_profit, loss=stop_loss)
      // strategy.exit("Sell Exit", "SELL",  limit=close - trade_risk, stop=close + trade_risk) // limit and stop are price exits
  else
      strategy.cancel("SELL")
  
  
  // DEBUG
  // plot(Debug ? limit_short : na, color=yellow, style=stepline, title='Limit Short')
  // plot(Debug ? limit_long : na, color=yellow, style=stepline, title="Limit Long")
  // plot(Debug ? limit_long : na, color=yellow, style=stepline, title="Limit Long")
  
  plot(buy_condition ? limit_long : sell_condition ? limit_short : na, color=yellow, style=stepline, title='LO Debug')
  plot(buy_condition ? stop_loss_long : sell_condition ? stop_loss_short : na, color=red, style=stepline, title='SL Debug')
  // plot(buy_condition ? take_profit_long : sell_condition ? take_profit_short : 0, color=green, style=stepline, title='TP Debug')
  // StochRSI overlay
  // plotchar(buy_condition ? 1 : 0, color=green, location=location.belowbar)
  // plotchar(sell_condition ? 1 : 0, color=red)
  bcol = sell_condition ? red : buy_condition ? green : na
  bgcolor(bcol)
  
  </code></pre>