title: Shortening code with a for loop is possible?
body: <p>I have a strategy including 20 poses pyramiding, and i follow the all pose seperately like this.</p>
  <pre><code>strategy.entry(&quot;BUY1&quot;, strategy.long, when= PoseCount==1 and PoseCount[1] !=1 and barstate.isconfirmed, alert_message = message_long_entry)
  .....
  strategy.entry(&quot;BUY20&quot;, strategy.long, when= PoseCount==20 and PoseCount[1] !=20  and barstate.isconfirmed, alert_message = message_long_entry)
  
   
  strategy.entry(&quot;SELL1&quot;, strategy.short, when= PoseCount==-1 and PoseCount[1] !=-1  and barstate.isconfirmed, alert_message = message_short_entry)
  ....
  strategy.entry(&quot;SELL20&quot;, strategy.short, when= PoseCount==-20 and PoseCount[1] !=-20  and barstate.isconfirmed, alert_message = message_short_entry)
  
   
   
  strategy.close(&quot;BUY1&quot;, when= PoseCount==-1 and PoseCount[1] !=-1   and barstate.isconfirmed, alert_message = message_long_exit)
  .....
  strategy.close(&quot;BUY20&quot;, when= PoseCount==-20 and PoseCount[1] !=-20   and barstate.isconfirmed, alert_message = message_long_exit)
  
  
  strategy.close(&quot;SELL1&quot;, when= PoseCount==1 and PoseCount[1] !=1  and barstate.isconfirmed, alert_message = message_short_exit)
  ....
  strategy.close(&quot;SELL20&quot;, when= PoseCount==20 and PoseCount[1] !=20  and barstate.isconfirmed, alert_message = message_short_exit)
  
   
  strategy.exit(&quot;BUY1 TP/SL&quot;,  &quot;BUY1&quot;,    limit=long_profit_level,  stop=long_stop_level ,     alert_message = message_long_exit) 
  ....
  strategy.exit(&quot;BUY20 TP/SL&quot;,  &quot;BUY20&quot;,    limit=long_profit_level,  stop=long_stop_level ,     alert_message = message_long_exit) 
  
  
  strategy.exit(&quot;SELL1 TP/SL&quot;,  &quot;SELL1&quot;,   limit=short_profit_level,  stop=short_stop_level ,   alert_message = message_short_exit)
  ....
  strategy.exit(&quot;SELL20 TP/SL&quot;,  &quot;SELL20&quot;,   limit=short_profit_level,  stop=short_stop_level ,   alert_message = message_short_exit)
  </code></pre>
  <p>I want to shorten this structure using for loop. I tried the following but failed. Thanks in advance for your help.</p>
  <pre><code>for x = 1 to 20
     strategy.entry(&quot;BUY&quot; + tostring(x), strategy.long, when= PoseCount==x and PoseCount[1] !=x and barstate.isconfirmed, alert_message = message_long_entry)
     strategy.entry(&quot;SELL&quot; + tostring(x), strategy.short, when= PoseCount==-x and PoseCount[1] !=-x  and barstate.isconfirmed, alert_message = message_short_entry)
     strategy.close(&quot;BUY&quot;+ tostring(x), when= PoseCount==-x and PoseCount[1] !=-x   and barstate.isconfirmed, alert_message = message_long_exit)
     strategy.close(&quot;SELL&quot;+ tostring(x), when= PoseCount==x and PoseCount[1] !=x  and barstate.isconfirmed, alert_message = message_short_exit)
     strategy.exit(&quot;BUY TP/SL&quot;+ tostring(x),  &quot;BUY&quot;+ tostring(x),    limit=long_profit_level,  stop=long_stop_level ,     alert_message = message_long_exit) 
     strategy.exit(&quot;SELL TP/SL&quot;+ tostring(x),  &quot;SELL&quot;+ tostring(x),   limit=short_profit_level,  stop=short_stop_level ,   alert_message = message_short_exit)
  </code></pre>
  <p><strong>edit</strong></p>
  <p>still same error (Mismatched input 'to' expecting 'end of line without line continuation') with the following</p>
  <pre><code>for x = 1 to 20
       strategy.entry(&quot;BUY&quot; + tostring(x), strategy.long, when= PoseCount==x and PoseCount[1] !=x and barstate.isconfirmed, alert_message = message_long_entry)
  
  for x = 1 to 20    
       strategy.entry(&quot;SELL&quot; + tostring(x), strategy.short, when= PoseCount==-x and PoseCount[1] !=-x  and barstate.isconfirmed, alert_message = message_short_entry)
     
  for x = 1 to 20      
       strategy.entry(&quot;SELL&quot; + tostring(x), strategy.short, when= PoseCount==-x and PoseCount[1] !=-x  and barstate.isconfirmed, alert_message = message_short_entry)
     
  for x = 1 to 20  
       strategy.close(&quot;BUY&quot;+ tostring(x), when= PoseCount==-x and PoseCount[1] !=-x   and barstate.isconfirmed, alert_message = message_long_exit)
     
  for x = 1 to 20      
       strategy.exit(&quot;BUY TP/SL&quot;+ tostring(x),  &quot;BUY&quot;+ tostring(x),    limit=long_profit_level,  stop=long_stop_level ,     alert_message = message_long_exit) 
    
  for x = 1 to 20
       strategy.exit(&quot;SELL TP/SL&quot;+ tostring(x),  &quot;SELL&quot;+ tostring(x),   limit=short_profit_level,  stop=short_stop_level ,   alert_message = message_short_exit)
  </code></pre>