31.07.2021 Views

Ultimate Algorithmic Trading System

Using automated systems for trading in stock markets

Using automated systems for trading in stock markets

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The money management order is placed by calling the Trade subroutine with

the following parameters: ExitLong, ‘‘ExitLongStop,’’ entryPrice − 2000/

myTickValue, stp, i. Here we are informing the Trade subroutine to liquidate

our long position on a stop at a price equivalent to the entryPrice − $2,000.

The trade price can be represented by a single variable name or it can be a

mathematical expression. In this case, we convert $2,000 to points by dividing

2,000 by myTickValue. Remember, you have got to make sure your units are

compatible. If you are working with prices, then you must convert dollars to a price

level. It would be a mistake in this case to forget to divide by myTickValue. Let’s

say you entered a trade in the DX at 129.050 and wanted to risk $2,000. If you

didn’t convert to points, then the exit price would be 129.050 – 2000. This doesn’t

make sense. Just remember to convert all dollar figures to points.

The time-based order is placed after the long position has been in a trade for more

than 10 days and is in a losing position. The variables barsLong and entryPrice are

keywords so don’t use them in an assignment statement—just look, don’t touch.

If barsLong > 10 tells the computer to ignore the ExitLong order until the

trade has been on for at least 10 days and the and myClose(i) < entryPrice

tells the computer to ignore the order if the position is in the profit. The orders

to exit a short position use the keyword barsShort, and the logic myClose(i) >

entryPrice.

If marketPosition = -1 Then

Call Trade(ExitShort, "ExitShortStop", entryPrice +

2000 / myTickValue, stp, i)

If barsShort > 10 And myClose(i) > entryPrice Then

Call Trade(ExitShort, "10dayShOut", myClose(i),

End If

End If

moc, i)

Once you type in your trading logic, simply return to Excel and go to the Data

worksheet and click on the Run System button.

■ Summary

All the tools that you need to calculate indicators, analyze price bar relations, manage

open trades, and execute them are all built into the ESB. The best way to learn

how to program your trading algorithms using VBA is by following along as many

examples as you can. The end of this chapter has a couple more simple examples

that you should be able to build upon.

163

USING MICROSOFT EXCEL TO BACKTEST YOUR ALGORITHM

www.rasabourse.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!