Algorithmic Trading Tips 03.



When using strategies that only define buy and sell signals (and not the size of the trade) your backtest over a range of stocks has only limited value. You may wish to invest the same amount of capital with each trade to balance your risk, and that`s what this Trading Tips shows you.

One share may cost only a few cents, the other maybe over 100 euros. Only if your strategy does not buy the same number of shares in each value, but instead assesses the same capital, the backtest becomes meaningful. And this is exactly what you can do with the following code.


PS_Members (10),

PS_Capital (1000000),

PS_Method (global,​​ local,​​ none),

Lot_Size (10);

Variables:​​ cap,​​ con;


// redistribution of portfolio p/l equally to all stocks

if​​ PS_Method ​​​​ =​​ global​​ then​​ cap​​ =(PS_Capital​​ +​​ globalclosedequity)​​ /​​ PS_Members;


// redistribution of single stock p/l to single stock

if​​ PS_Method​​ =​​ local​​ then​​ cap​​ =(PS_Capital)/​​ PS_Members​​ +​​ closedequity;


// do not redistribute p/l

if​​ PS_Method​​ =​​ none​​ then​​ cap​​ =​​ PS_Capital​​ /​​ PS_Members;


if​​ close<>0​​ then​​ con​​ =​​ round(cap/close/​​ Lot_Size,0)*​​ Lot_Size;

The script starts with defining some inputs for the right position sizing. You may change these according to your needs. The first input is called ‘PS_Members’. It defines how many stocks you will trade. For a single stock strategy this value is 1, if you want to trade all FTSE100 stocks (for example) then set to 100. As you can see the default setting for this input is 10.

Second step is to define the capital for the whole portfolio. The default setting for ‘PS_Capital’ is 1,000,000.

Third, is to decide what happens with profits and losses. They can be ignored by choosing ‘none’ from the ‘PS_Method’ option. In this case the strategy always uses the given initial capital. If you want to reinvest the P & L of a given security to this security then select ‘local’. If you would like to redistribute the Portfolio P&L equally to all portfolio members then select ‘global’.

Fourth, and the final step, is to define the lot size of the security. If you want to buy in steps of 1, then set this to 1, if you always want to buy 100 stocks as a bundle then set it to 100.

Watch the video and see how this script is used in conjunction with a sample strategy. The video also shows you how to copy and paste the script into Tradesignal® to make it available for any of your strategies or one of the many pre-build strategies Tradesignal is shipped with. Here are all the steps to explain how to make use of the script:

  • 01. Right-hand side; click ‘Strategies’ and choose ‘New Strategy…’.
  • 02. In the next box click the first option ‘Use the Equilla Formula Language’.
  • 03. Enter a name of your choice for the script; e. g. “Position Sizing’ and click on ‘Done’. A new blank editor window opens, the so called ‘Equilla Editor Window’.
  • 04. Copy script from PDF and paste it into the ‘Equilla Editor Windows’. Click on ‘Save’ and finally click the ‘Compile Script’ button on top of the program window.
  • 05. Open up a single chart or a portfolio (in my case I use the FTSE 100 Index) and apply one of Tradesignals’ trading strategies. Just for demonstration purpose I took the Moving Average Double Crossover strategy. Afterwards apply this, just created, ‘Position Sizing” script.

You can clearly see that in this example my position sizings are all now proportional; which means the amount of money invested is equal for each stock.“.

I can further fine tune or alter the strategy settings very quickly by accessing ‘Properties’ on the right of the screen and changing the options. Fast and easy when you know how.