PacktPublishing / Learn-Algorithmic-Trading

Learn Algorithmic Trading, Published by Packt
MIT License
802 stars 302 forks source link

basic_trend_following #5

Closed Emptytolose closed 3 years ago

Emptytolose commented 3 years ago

In line 72, when defining the Sell_entry rationale for the first case (Short Entry) shouldn't we have: apo > apo_value_sell_entry? Since an APO above the threshold points to an uptrend in prices and thus a good moment to short the stock.

jiripik commented 3 years ago

Hello:

thank you for your question.

First of all, the source code in this git repository is not consistent with the source code in the book.

In the git repository, we define APO_VALUE_FOR_BUY_ENTRY = 10 # APO trading signal value above which to enter buy-orders/long-position APO_VALUE_FOR_SELL_ENTRY = -10 # APO trading signal value below which to enter sell-orders/short-position while in the book we define as APO_VALUE_FOR_BUY_ENTRY = -10 # APO trading signal value below which to enter buy-orders/long-position APO_VALUE_FOR_SELL_ENTRY = 10 # APO trading signal value above which to enter sell-orders/short-position

See the opposite signs.

Second, you're right. The code is correct in the book. if ((apo > APO_VALUE_FOR_SELL_ENTRY and abs(close_price - last_sell_price) > MIN_PRICE_MOVE_FROM_LAST_TRADE) # APO above sell entry threshold, we should sell

The git repository will be fixed.