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.

moc—Market On Close order. Execute the order at the closing price of the

bar. Specify myClose(i) as the trade price.

mkt—Market order. Executes at the opening of the bar. Specify myOpen(i)

as the trade price.

The final argument is always the letter i, the current bar in the loop.

If marketPosition <> 1 Then

Call Trade(Buy, "BB-Buy", upBand, stp, i)

End If

This order is only placed if the current marketPosition is not equal to 1 or long.

In other words, don’t place a Buy order if you are already long. Unfortunately, this

version of the ESB doesn’t allow pyramiding; however, future versions will have

this capability. Entering a short position uses the same subroutine but the arguments

are different:

If marketPosition <> -1 Then

Call Trade(Sell, "BB-Short", dnBand, stp, i)

End If

162

USING MICROSOFT EXCEL TO BACKTEST YOUR ALGORITHM

Here we are trying to Sell short at the lower Bollinger Band on a stop. That’s it

for the trade entries. Simple, thus far? Once you get into a trade, this algorithm has

three different ways to exit:

A $2,000 money management stop—any time the market moves $2,000 against

the position it is exited.

Time-based market order (MOC)—if the position is not profitable after 10 bars,

the trade is exited on the close.

Reversal if the opposite side of the Bollinger Bands is penetrated before an exit is

executed.

If marketPosition = 1 Then

Call Trade(ExitLong, "ExitLongStop", entryPrice -

2000 / myTickValue, stp, i)

If barsLong > 10 And myClose(i) < entryPrice Then

Call Trade(ExitLong, "10dayLgOut", myClose(i),

End If

End If

moc, i)

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!