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.

sl = Param("ShortLen",9,9,100);

il = Param("InterLen",19,19,200);

mmStop = Param("StopDollars",3000,3000,6000);

Buy = MA(C,sl) > MA(C,il) ;

Short = MA(C,sl)< MA(C,il);

Sell = short;

Cover = buy;

ApplyStop(stopTypeLoss,stopModePoint,mmStop/PointValue,0);

132

INTRODUCTION TO AMIBROKER’S AFL

The variables sl and il are defaulted to 9 and 19, respectively. The Param

function allows the user to change the variables to values between 9 and 100 and 19

and 200, respectively. The variable mmStop defaults to 3000 but can be changed to

values ranging from 3000 to 6000. The array Buy is filled with 1s when the moving

average of sl (shortLength) is greater than the moving average of il (intermediate-

Length). The Short array is filled when the opposite happens. This is a very simple

double moving average crossover system. The ApplyStop function tells AmiBroker

to stop out on the close any time the current position reaches a loss of $3,000. The

close is checked in this particular case. The ApplyStop function has many different

ways of exiting a position: stop loss, trailing stop, or a profit objective. Here are

three examples:

ApplyStop(stopTypeLoss, stopModePercent,2, True );

/* single-line implementation of Chandelier exit */

ApplyStop(stopTypeTrailing, stopModePoint, 3*ATR(14), True, True );

/* N-bar stop */ ApplyStop( stopTypeNBar, stopModeBars, 5 );

This is a very powerful function and can fulfill almost every possible criterion to exit

an existing position with a stop.

Referring back to MySecondAlgo, you might have noticed these two lines of

code:

Buy = Cross(shortMav,longMav);

Short = Cross(longMav,shortMav);

The keyword Cross is actually a function call. The function gives a ‘‘1’’ or true

on the day that the shortMav crosses above the longMav. Otherwise, the result

is false or zero. To find out when shortMav crosses below longMav, simply reverse

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!