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.

if marketPosition <>-1 and linearRegSlope(c,linearSlopeLength)

< 0 then

Sellshort("ShortEntryLevel") tomorrow at shortLevel stop;

If marketPosition =-1 then

begin

buyToCover("S-ATR-Stop") next bar at entryPrice+numAtrStop

*avgTrueRange(atrLen)

stop;

if maxContractPoints >= numAtrProfThreshold *

avgTrueRange(atrLen) then

begin

value1 = entryPrice - (maxContractPoints-numAtrTrail *

avgTrueRange(atrLen));

buyToCover("S-Trail-Stop") next bar at value1 stop;

end;

end;

This algorithm incorporates a volatility-based protective and trailing stop. EL

keeps track of the maximum profit a position achieved during the duration of a trade,

and stores it in the keyword maxContractProfit. The profit is expressed in terms

of dollars, and to get it in terms of points you have to divide by the bigPointValue

of the underlying instrument. If the maxContractProfit achieves a level equal to,

in this case, five ATRs, then a trailing stop is engaged to trail the highest point in the

trade by two ATRs. If you don’t want to use volatility in the stop calculations, you

can use dollars. Here is the snippet of the code that engages the trailing stop:

if maxContractPoints >= numAtrProfThreshold*

begin

end;

avgTrueRange(atrLen) then

value1=entryPrice + (maxContractPoints-numAtrTrail *

avgTrueRange(atrLen));

sell("L-Trail-Stop") next bar at value1 stop;

223

AN INTRODUCTION TO EASYLANGUAGE

If the maxContractPoints is greater than the threshold profit level, then the

trailing stop level is calculated using the following formula:

value1 = entryPrice + (Highest level during trade – 2*ATR)

As the market continues to climb, so does value1 staying 2 ATR below the highest

point achieved. Once the market stops climbing, value1 locks into place and waits

for the market to take out the trailing stop.

Once you master just the fundamentals of programming and a few concepts

that are intrinsic to a particular language, you then have most of the tools to test

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!