It based on Richard Donchian strategy
We calculate the N using ATR(Average True Range) from Talib
Unit =0.01 of the account size / ATR
Here is the strategy and Add strategy is the core:
1st Buy: First time break Donchian upper limit(last 20 days max), buy 1 unit
2nd Buy: When price went up by 0.5N, we buy another 1 unit.
3rd Buy: Same, When price went up by 0.5N, we buy another 1 unit.
4th Buy: Same, but this is the last buy. We do not add anymore
SELL: when current price drop below 20 days min, we sell to 0.
Problems are:
- I record the 1st buy construct a DataFrame called 'recordme' but by the time we reach 2nd buy, 'recordme' is still empty for some reason. I cannot find why it is not recording?
2015-02-09 16:30 rebalance:61 INFO Empty DataFrame
Columns: [add_time, last_buy_price, symbols]
Index: []
2.following strategy went wrong when it sees a empty Series. Here I was trying to substract a value instead of a Series. I don't know if we fix the 1 problem, this will be solved accordingly.
I've asked help once of this strategy, but it doesn't seem to fix the problem
from: if cur_price > add_price and add_unit < 4:
to: if cur_price > add_price[-1] and add_unit[-1] < 4:
I don't think its the prime problem though.
Notes:
True Range = Max(High-Low,abs(High-PreClose),abs(PreClose-Low))
ATR = MA(TrueRange, 20)
N = (PreN[-19:] + True Range) / 20