bwentzloff / trading-bot

Code seen in Cryptocurrency Trading YouTube video here: https://youtu.be/fpqzXgZjSqM
400 stars 262 forks source link

Backtest fail, Help #37

Open r-neri opened 6 years ago

r-neri commented 6 years ago

i am trying to run a backtest whit a startTime = 21/01/2018 14:00:00 (1516543200) endTime = 21/01/2018 23:45:00 (1516578300) on "BTC_XMR" pair on poloniex but the price that is returned was not correct, they seems to be from another date (I Told this because the prices are too diferent). I am using this parameters : -s 1516543200 -e 1516578300

These are the output (Partial, I remove the Entry Price: entrance to short the output): Price: 0.01778382 Moving Average: 0.01778382 Price: 0.01779416 Moving Average: 0.017788989999999998 Price: 0.01778603 Moving Average: 0.017788003333333333 Trade opened Price: 0.01783528 Moving Average: 0.0177998225 Trade closed Price: 0.01778879 Moving Average: 0.017797616 Trade opened Price: 0.01782878 Moving Average: 0.01780281 Trade closed Price: 0.01790495 Moving Average: 0.01781740142857143 Price: 0.01790028 Moving Average: 0.01782776125 Price: 0.01799615 Moving Average: 0.01784647111111111 Price: 0.01819673 Moving Average: 0.017892349999999998 Price: 0.01826543 Moving Average: 0.017944713333333334 Price: 0.01831097 Moving Average: 0.01800304 Price: 0.0181363 Moving Average: 0.01803648666666667 Price: 0.01818053 Moving Average: 0.018080013333333332 Price: 0.01818899 Moving Average: 0.018120036666666665 Price: 0.01820367 Moving Average: 0.018153227777777777 Price: 0.01819987 Moving Average: 0.018186515555555553 Price: 0.01819146 Moving Average: 0.018208216666666666 Trade opened Price: 0.01810712 Moving Average: 0.01819826 Price: 0.01802347 Moving Average: 0.018171375555555553 Trade closed Price: 0.01802243 Moving Average: 0.018139315555555556 Trade opened Price: 0.01806026 Moving Average: 0.01813086666666667 Price: 0.01809434 Moving Average: 0.018121289999999998 Price: 0.01793798 Moving Average: 0.018093399999999996 Price: 0.01789414 Moving Average: 0.018059007777777775 Trade closed Price: 0.01796811 Moving Average: 0.018033256666666667 Trade opened Price: 0.01796895 Moving Average: 0.018008533333333337 Price: 0.01796897 Moving Average: 0.017993183333333336 Price: 0.01782219 Moving Average: 0.01797081888888889 Trade closed Price: 0.01793247 Moving Average: 0.017960823333333334 Trade opened Price: 0.01791024 Moving Average: 0.017944154444444443 Price: 0.0179953 Moving Average: 0.017933149999999995 Trade closed Price: 0.01809091 Moving Average: 0.01795014222222222 Price: 0.01805406 Moving Average: 0.017967911111111113 Price: 0.01811778 Moving Average: 0.01798454111111111 Price: 0.01818379 Moving Average: 0.018008412222222225 Price: 0.01820467 Moving Average: 0.018034601111111114 Price: 0.01818194 Moving Average: 0.018074573333333333 Price: 0.0180701 Moving Average: 0.018089865555555557 Trade opened Price: 0.018107 Moving Average: 0.01811172777777778 Price: 0.01804641 Moving Average: 0.01811740666666667 Price: 0.01834212 Moving Average: 0.018145318888888887 Trade closed

On 21/01/2018 14:00:00 the price war arround the 0.02983 (0,0297 to 0,0300) What I am doing wrong?

r-neri commented 6 years ago

The execution of the Backtest above returned more than 1800 prices for a period of time about 9 3/4 hours (From 14:00:00 to 23:45:00) when the expected number was 9 3/4 x 12 ~= 117 prices (one of every 5 minuts). It seems that besides the values were wrong the number of prices returned were wrong too.

i used a period of 300 (("poloniex", "BTC_XMR", 300))

phixion1 commented 6 years ago

I'm not sure the answer to your issue, but maybe you could shed a bit of light on mine, seeing as you have working what mine is not. thank you and regards in advance basically I bot.py with -s -e but it comes back with tuple object "priceAverage" has no attributes

r-neri commented 6 years ago

Hello phixion1 Thank you. I saw your question, but I don´t know what is wrong . Indeed i dont know python. But i installed the version 3.6 to test the code posted here. With many costs i realized that the code posted here was wrote using an old version of Python. So i made some version adaptations on code to run the bot. I started with part 1, and then part 2 and finally part 3. I recomend you to follow the videos on youtube on channel Cryptocurrency Trading like this one https://www.youtube.com/watch?v=fpqzXgZjSqM If a can help with more things dont hesitate. Good lucky.

r-neri commented 6 years ago

phixion1 are you using the -s and -e attributs with the unix datatime? like in this example -s 1516543200 -e 1516578300 ?

phixion1 commented 6 years ago

yes I have been using the -s unix datetime -e unix datetime to try and backtest. same thing every time "AttributeError: 'tuple' object has no attribute 'priceAverage'" ive tried every iteration of the backtest command line prompts as I could. no luck, so ive been resorting to testing on live data points with simulated trade. slow. tell me about it. all other modules work but backtest.py . but now I try the MACD test on live data points....

#if (len(openTrades) < self.NumSimulTrades):
        #if (self.indicators.MACD(self.prices,24) < self.indicators.MACD(self.prices,12)):
            #self.trades.append(BotTrade(self.currentPrice,stopLoss=.0))
    #for trade in openTrades:
        #if (self.indicators.MACD(self.prices,24) > self.indicators.MACD(self.prices,12)):
            #trade.close(self.currentPrice)

gives me error "24 index is out of bounds" I try to do like so, but I am noob. doesn't work so I have pounded out for now

phixion1 commented 6 years ago

I wish we knew the answers to each others questions :). shucks. I have books coming. Sick of building houses in the Montana Winters. I'm diving in. it would just be nice to have a "teacher figure" XD

phixion1 commented 6 years ago

I'd like to also add here: Brian Is AWESOME. So glad he's offering the opportunity like this to get a foot in the door.!!!

r-neri commented 6 years ago

Ok Guys I realize that botchart.py is using a fixed date despite I use de -s and -e parametes on bot.py See: class BotChart(object): def init(self, exchange, pair, period, backtest=True): self.pair = pair self.period = period

    self.startTime = 1491048000  <<<<<<<<<< FIXED date
    self.endTime = 1491591200  <<<<<<<<<< FIXED date

When i debug the bot.py using the -s and -e parameters i observed that only the self.startTime on bot.py is correctly set, the endTime variable is set to ´false´ despite i use an Epoch datevalue on -e parameter.

Any guess How i can resolve this? Sorry but i dont know anything of python i am triying to learn now. Thank you.

r-neri commented 6 years ago

Phixion1 where do you found a MACD code to test?

phixion1 commented 6 years ago

its in botindicators, its not working though cause I cant properly feed data points through EMA at this point.

On Thu, Jan 25, 2018 at 4:54 AM, r-neri notifications@github.com wrote:

Phixion1 where do you found a MACD code to test?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bwentzloff/trading-bot/issues/37#issuecomment-360445420, or mute the thread https://github.com/notifications/unsubscribe-auth/AiBO1RNanmTvq0kk0axqt9P-dclFDp-Qks5tOGtngaJpZM4Rox22 .

ghost commented 6 years ago

Hi. I'm also trying to work on getting EMA indicator to work. Any more progress on EMA?

ghost commented 6 years ago

At the moment, i've progressed to get this error with EMA: ValueError: The truth value of an array with more than one element is ambiguous.

ghost commented 6 years ago

forgot to include which line of code the error is reporting, in botstrategy under evaluatePositions def: if (self.currentPrice < self.indicators.EMA(self.prices,15)):

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

jstep commented 6 years ago

@cbearden11 The error ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() is because you are passing self.prices as an array with more than one element. For your comparison you could use self.prices[-1] to only compare current_price to the last element in the array.

ghost commented 6 years ago

jstep, Thanks for that help! I worked around this by adjusting botindicators.py, in the def EMA section, at the end: return a[:1] it only returns 1 value of the EMA sequence, but gets around the error for now. I'm still trying to understand how EMA works as well.

jstep commented 6 years ago

Good job @cbearden11, but you're going to want to use [-1] instead of [:1]. The former will access the last element of the list while the latter will access from the zeroth element to the first element. Still one element, but not the one you want.

jstep commented 6 years ago

If you guys want a MACD indicator (and many others) check out the TA-Lib library https://github.com/mrjbq7/ta-lib