title: sql loop through each row in a table
body: <p>I've created a program that generates buy and sell signals of stocks. I've also created logic that tests the different signals and provides the return for each trade. </p>
  
  <p>The next step is to simulate the strategy and its rules over a long period of time. All information is exported to text files and imported to a table in a SQL Server database. I've realized that I need to declare a number of variables such as <code>StartCapital</code>, <code>CurrentCapital</code>, <code>NumberOfPositions</code>, <code>PositionsLeft</code>. One of the columns is named <code>BuyPrice</code> and indicates when to buy and to which price, when this occurs <code>NumberOfPositions</code> should be subtracted by 1. </p>
  
  <p>The column <code>SellPrice</code> indicates when to sell and to which price, when this occurs <code>NumberOfPositions</code> needs to be added by one. The maximum of <code>NumberOfPositions</code> should be 5 and minimum 0. The desired result is to see how the <code>CurrentCapital</code> unfolds. </p>
  
  <p>I would very much appreciate any input and some kind of SQL code to start form. </p>