title: How to Keep two long and short opposed positions open in tradingview pinescript?
body: <p>this is a simple code to show you what I mean, there are stop losses for both long and short positions but the problem is that I want to be able to open short positions without closing the already opened long position. as you've probably guessed, I want to test this strategy when the market is tight and you could make profit on, either way, it just needs two accounts.</p>
  <pre><code>strategy(&quot;bothways&quot;, overlay=true)
  
  leverage=input(5,&quot;leverage&quot;,step=.25)
  partoftrade=input(1,&quot;partoftrade&quot;,step=.01)
  StoplosssS=input(0.025,&quot;StopLOSS SHORT&quot;,step=0.001)
  StoplosssL=input(0.025,&quot;StopLOSS LONG&quot;,step=0.001)
  pertpS = input(0.02,&quot;TP Short&quot;,step=0.01)
  pertpL = input(0.02,&quot;TP Long&quot;,step=0.01)
  narrow=bbw(open,20,2)&lt;0.005
  red=open&gt;close
  green=open&lt;close
  longCondition = narrow and green
  if (longCondition and strategy.opentrades&lt;2)
      strategy.entry(&quot;L&quot;, strategy.long,qty=(strategy.equity/1)*partoftrade*leverage/open,oca_name=&quot;ocg&quot;,oca_type=strategy.oca.cancel)
  strategy.exit(&quot;LE&quot;,from_entry=&quot;L&quot;,profit=close*pertpL/syminfo.mintick,loss=open*StoplosssL/syminfo.mintick,oca_name=&quot;ocg&quot;)
  
  shortCondition = narrow and red
  if (shortCondition and strategy.opentrades&lt;2)
      strategy.entry(&quot;S&quot;, strategy.short,qty=(strategy.equity/1)*partoftrade*leverage/open,oca_name=&quot;ocg&quot;,oca_type=strategy.oca.reduce)
  strategy.exit(&quot;SE&quot;,from_entry=&quot;S&quot;,profit=close*pertpS/syminfo.mintick,loss=open*StoplosssS/syminfo.mintick,oca_name=&quot;ocg&quot;)    
  </code></pre>
  <p>thanks for help</p>