title: One of my Pine editor scripts doesn't seem to make trades
body: <p>I'm backtesting trade strategies on tradingview, and am using the pine editor to program them (with help from examples and youtube videos).
  So far I've made several ones that work in terms of correct entries and exits etc.
  Every time I get one in order I try to make it a bit more complex.</p>
  <p>The last one I'm working on doesn't seem to do anything.
  There are no trades in the &quot;Strategy Tester&quot; screen at all.
  I've gone through the code over and over again but I can't find out why.</p>
  <p>Here's what I find strange:</p>
  <ol>
  <li>I've got some plots on the end for the &quot;Trade Stop Price&quot; and &quot;Trade Target Price&quot; and those plot every time I've got a correct setup for entry. So it does recognize the entries.</li>
  <li>I didn't change the strategy.entry or strategy.exit parts, which I took over from the previous strategy which did work</li>
  </ol>
  <p>Hopefully someone can help me?
  Thank you in advance!</p>
  <p>(Also, if you see anything that makes you go &quot;wow, that's dumb&quot;, feel free to comment)</p>
  <p>Corove</p>
  <pre><code>// Previously 3 or more strong HA candles in same direction
  // Closed last HA with body between 40 and 60 percent of wick
  
  
  //@version=4
  strategy(&quot;Heikin Ashi Indecisive after strong move&quot;, overlay = true, initial_capital = 1000, default_qty_value = 2, default_qty_type = strategy.percent_of_equity)
  
  // input from user
  stopMultiplier = input(title=&quot;Stop Loss ATR&quot;, type=input.float, defval=1.0, tooltip=&quot;Stop loss multiplier (x ATR)&quot;)
  rr = input(title=&quot;Risk:Reward&quot;, type=input.float, defval=1.0, step=0.5, tooltip=&quot;Risk:Reward profile&quot;)
  
  // defined variables
  start = timestamp(2021, 10, 28, 0, 0)
  end = timestamp(2021, 11, 28, 0, 0)
  symbol = syminfo.tickerid
  period = &quot;5&quot;
  lookback = 2
  
  // calculate atr
  atr = atr(14)
  
  // get Heikin Ashi values
  heikinashiOpen = security(heikinashi(symbol), period, open)
  heikinashiClose = security(heikinashi(symbol), period, close)
  heikinashiHigh = security(heikinashi(symbol), period, high)
  heikinashiLow = security(heikinashi(symbol), period, low)
  
  // define a green (rising) and red (falling) Heikin Ashi candle
  rising = heikinashiClose &gt; heikinashiOpen
  falling = heikinashiClose &lt; heikinashiOpen
  
  // calculate candle- wick- and bodysizes
  candleSize = heikinashiHigh - heikinashiLow
  bodySize = heikinashiOpen &gt; heikinashiClose ? heikinashiOpen - heikinashiClose : heikinashiClose - heikinashiOpen
  upperWick = heikinashiOpen &gt; heikinashiClose ? heikinashiHigh - heikinashiOpen : heikinashiHigh - heikinashiClose
  lowerWick = heikinashiOpen &gt; heikinashiClose ? heikinashiClose - heikinashiLow : heikinashiOpen - heikinashiLow
  
  // define a Heikin Ashi with hard push in one direction
  hardRise = rising and (heikinashiLow == heikinashiOpen)
  hardFall = falling and (heikinashiHigh == heikinashiOpen)
  
  // define HA end of move candle
  indecisiveCandle = upperWick &gt; candleSize * 0.35 and lowerWick &gt; candleSize * 0.35
  
  // determine if we have a valid setup
  switchLongComing = (indecisiveCandle or rising) and hardFall[1] and hardFall[2] and hardFall[3] and not na(atr)
  switchShortComing = (indecisiveCandle or falling) and hardRise[1] and hardRise[2] and hardRise[3] and not na(atr)
  
  // check if we have confirmation for a trade
  validLong = switchLongComing and strategy.position_size == 0 and barstate.isconfirmed
  validShort = switchShortComing and strategy.position_size == 0 and barstate.isconfirmed
  
  // calculate stops and targets
  stopSize = atr * stopMultiplier
  lowestLow = lowest(low, lookback)
  longStopPrice = lowestLow - stopSize
  longStopDistance = close - longStopPrice
  longTargetPrice = close + (longStopDistance * rr)
  highestHigh = highest(high, lookback)
  shortStopPrice = highestHigh + stopSize
  shortStopDistance = shortStopPrice - close
  shortTargetPrice = close - (longStopDistance * rr)
  
  // save stops and targets for trade
  var tradeStopPrice = 0.0
  var tradeTargetPrice = 0.0
  if validLong
      tradeStopPrice := longStopPrice
      tradeTargetPrice := longTargetPrice
  if validShort
      tradeStopPrice := shortStopPrice
      tradeTargetPrice := shortTargetPrice
  
  // enter trades when a valid entry is found
  if time &gt;= start and time &lt;= end
      strategy.entry(id=&quot;Long&quot;, long=strategy.long, when=validLong)
      strategy.entry(id=&quot;Short&quot;, long=strategy.short, when=validShort)
  
  // exit trades whenever a stop or target is hit
  strategy.exit(&quot;Long Exit&quot;, from_entry = &quot;Long&quot;, limit = tradeTargetPrice, stop = tradeStopPrice, when = strategy.position_size &gt; 0)
  strategy.exit(&quot;Short Exit&quot;, from_entry = &quot;Short&quot;, limit = tradeTargetPrice, stop = tradeStopPrice, when = strategy.position_size &lt; 0)
  
  // graphical information
  plot(strategy.position_size != 0 or validLong or validShort ? tradeStopPrice : na, title = &quot;Trade Stop Price&quot;, color = color.red, style = plot.style_linebr)
  plot(strategy.position_size != 0 or validLong or validShort ? tradeTargetPrice : na, title = &quot;Trade Target Price&quot;, color = color.green, style = plot.style_linebr)
  inLongTrade = strategy.position_size &gt; 0
  inShortTrade = strategy.position_size &lt; 0
  notInTrade = strategy.position_size == 0
  bgcolor(notInTrade == false ? inLongTrade ? color.green : color.red : color.white)
  </code></pre>
  <p>EDIT:
  After some more testing I found out that this problem of not opening positions happens on some charts and not on others.
  The script will take trades on forex pairs for example, but not on most futures or stocks.
  Still no idea why...</p>