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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

standard deviations. In our example, we are using the closing prices, a five-bar

lookback, and positive one and negative one standard deviations.

myBollingerB = BollingerB(c,5,1,-1);

The BollingerB function returns a value between a negative value and a positive

value and 1.00 which indicates the location of the current bar’s close in relation to

the upper and lower Bollinger Bands. The lower the value, the closer it is to the

lower band. The higher the value, the closer it is to the upper band.

If MarketPosition = 0 and

close > average (close,200) and

average(myBollingerB,triggerSmooth) < triggerVal then

buy("LongReversion") next bar at market;

If MarketPosition = 0 and

close < average (close,200) and

average(myBollingerB,triggerSmooth) > 1 - triggerVal then

sellShort("ShortReversion") next bar at market;

216

AN INTRODUCTION TO EASYLANGUAGE

You might not be able to tell by this code snippet, but EL follows the bar-by-bar

programming paradigm. The keyword If might have given you a hint, though. If you

have read the chapter on AmiBroker, you know you usually don’t use the keyword

If when dealing with array programming. When you use the data arrays (open, high,

low, close, volume, or opInt) without an index variable you are simply looking at

the very last day of data up to that point in the master loop.

C is the same as C[0]. The [0] is optional. Since there is an implied index, you

can be assured you are not dealing with array programming. The lack of the index

for the last value in the arrays makes EL look more like English. Take a look at the

following line of code:

If close > average(c,200) then buy next bar at open;

Doesn’t this look like English? You bet it does. Hence, the name EasyLanguage.

The language is simple on the surface, but can become much more complicated as

the complexity of the algorithm increases. This is a good thing—EasyLanguage isn’t

necessarily easy, but it’s not weak by any stretch of the imagination. And it’s getting

more powerful every year.

These lines of code direct TradeStation to check the current market position, and

if it is flat, to check if today’s close > the 200-bar moving average and the 3-bar

moving average of myBollingerB is less than the triggerVal. In this example,

the triggerVal is set to 0.2. If the criteria are met, then a market order to buy is

placed for the next bar’s open. A similar criterion is used to initiate a short position

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!