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.

prevAvg2 and today’s avg1 must be greater than today’s avg2—a crossover.

There are a few different ways you could accomplish this, but until you become

more comfortable with Python, the PSB, and lists, I would suggest simply offsetting

the indicators to get the values you need. This is highly inefficient, but I don’t think,

unless you are doing it a lot, you will see a degradation in performance.

If you are using limit orders, just make sure you test the worst-case scenario.

Most limit orders are not executed unless the price penetrates and trades one tick

through the limit price. So you know how it important it is to use >= and <= in

your price comparisons for stop orders. In limit orders forget the = sign. Like this:

#Long Exit - Profit

if mp >= 1 and myHigh[i] > entryPrice + profAmt and

barsSinceEntry > 1:

price = max(myOpen[i],entryPrice + profAmt)

tradeName = "L-Prof"

202

USING PYTHON TO BACKTEST YOUR ALGORITHM

Usingjustthe> sign informs the PSB to make sure the market action penetrates

the entryPrice + profAmt. In reality, there is a chance that a limit order will

be filled if the order is touched. But we always want worst-case scenario when

developing a trading algorithm. There is a bunch more Python code in the appendix

and a few tutorials on the website. This version of the PSB is really in its infancy.

I will continue to enhance it into the future by including some basic graphing utilities

and loading it into a more sophisticated IDE.

■ Summary

I love Python, and it really is a great language for quants and quant wannabes. It is

the language to learn if you are new to programming. You will hear things out there

about how it is inferior to C# and other faster languages. Unless you are an HFT

trader, don’t take these criticisms seriously. Others may complain that Python is not

a purely objective language due to its deviations from the philosophy of ‘‘OO.’’ I look

at Python as means of getting something done quickly and accurately. Traders need

to concern themselves with trading concepts more so than programming theory.

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!