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.

If you have imported the companion code properly, select MyMeanReversion1

strategy and click OK. The following code listing should now be on your screen.

{This algorithm trades in the direction of

the longer term trend but buys/shorts on dips

and rallies. The indicator BollingerB returns

the location of the current bars close in relation

to the 5-bar Bollinger Band. If the trend

is up and the current close is near the bottom

BBand it will buy. If the trend is down and the

close is near the upper BBand it will Short.}

Inputs:Length(5),mmStop(2000),triggerVal(0.25),triggerSmooth(3);

Vars: myBollingerB(0);

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

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;

If marketposition = 1 then

begin

If myBollingerB > 1 - triggerVal then sell("L-Exit")

next bar at market;

If c <= entryPrice - mmStop/BigPointValue then

sell("MML-Exit") next bar at market;

end;

If marketposition = -1 then

begin

if myBollingerB < triggerVal then

buyToCover("S-Exit") next bar at market;

if c >= entryPrice + mmStop/BigPointValue then

buyToCover("MMS-Exit") next bar at market;

end;

207

AN INTRODUCTION TO EASYLANGUAGE

A portion of the strategy or algorithm is shown in Figure 7.5.

You can easily see how the blocks of code are outlined. There’s a small box

with a ‘‘-’’ symbol and a vertical line connecting the related block of code together.

Outlining also allows you to hide the blocks of code if you wish to do so, again

adding to the readability of the code. You can hide the block of code that is being

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!