title: How to create strategy for Risk to Reward ratio
body: <p>I am struggling with an R/R ratio strategy. I need a standard 1.5 Win/Lose ratio. As a stop-loss, I am using the low of the previous swing low before the entry level. Here is the code.</p>
  <pre><code>//@version=4
  strategy(&quot;TEST&quot;,&quot;T&quot;, true)
      
  
  //₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿  ₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿
  
  
  fastlen = input(12, &quot;Fast Length&quot;, group=&quot;MACD&quot;)
  slowlen = input(26, &quot;Slow Length&quot;, group=&quot;MACD&quot;)
  siglen  = input(9, &quot;Signal Length&quot;, group=&quot;MACD&quot;)
  mcd_src = input(close, &quot;Source&quot;, group=&quot;MACD&quot;)
  _bar    = input(1, &quot;Swing Bar#&quot;, minval=1, group=&quot;Stop Loss Option&quot;)
  
  //₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿  ₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿₿
  
  [fast, slow, hist] = macd(mcd_src, fastlen, slowlen, siglen)
  
  pivot_low_stop  = pivotlow(_bar, _bar)
  
  float entry_lvl = 0.00
  entry_lvl := valuewhen(strategy.opentrades == 1, strategy.position_avg_price, 0)
  float long_sl = 0.00
  long_sl   := valuewhen(strategy.opentrades == 1, pivot_low_stop, 0) 
  
  profit = (entry_lvl - long_sl) * 1.5 + entry_lvl
  
  long = barstate.isconfirmed and fast and slow &lt;= 0 and crossover(fast, slow)
  
  if long
      strategy.entry(&quot;Long&quot;, true)
  strategy.exit(&quot;Long&quot;, profit=profit, limit=long_sl)
  
  
  
  plot(entry_lvl,&quot;Entry Level&quot;, color.yellow, 2, plot.style_linebr)
  plot(long_sl,&quot;Stop Loss Level&quot;, color.red, 2, plot.style_linebr )
  plot(profit, &quot;Profit Level&quot;, color.green, 2, plot.style_linebr) 
  </code></pre>