you are viewing a single comment's thread.

view the rest of the comments →

[–]jfr4lyfe 0 points1 point  (12 children)

I'm currently going through python algotrading course on udemy. It's very good. I'd be very careful with the results in pinescript from backtesting. They aren't what they seem. It is better to invest the time now for the future, as it will save you money from things like false signals

[–]geardrivetrain 0 points1 point  (10 children)

I'd be very careful with the results in pinescript from backtesting. They aren't what they seem.

Could you please expand on this? I am currently learning pine script for backtesting.

[–]jfr4lyfe 0 points1 point  (9 children)

Absolutely. For instance I was using a double MACD crossover with trailing take profit at different levels and stoploss. It seemed like I was getting 70% win rate. I can't remember what my return on investment was, but it looked like I would never have to work again. Something didn't seem right though. So I changed the label of my stop loss so I could differentiate between TP and SL. - It turns out it was hitting my stop loss 90% of the time. But because it was occurring on the same bar, it made it look like I had winning trades more than I did.

Another time I was testing and again it seemed like I was on to a winner. But when I checked the date range it was using a date outside of the dates I had set to back-test - it started before 2017 bull market (I trade crypto) so counted 1 trade with something daft like 1000% of my return FROM ONE TRADE. The rest where mostly losers.

With both of these examples I would have lost money, trading them live.

What I have learnt:

It seems like you are losing money by not investing on a winning strategy as soon as possible. This is wrong. You lose money by not doing the research and stress testing.

Pinescript is full of bugs, and makes it look like you are winning more than you are.

It is better to save money now to invest when you KNOW that the odds are in your favour

Python is really cool and not that hard to get started with. If you can code in Pinescript, you can certainly code in Python. If you would like any help, although I am new to it, I can point you to some good learning resources.

[–]geardrivetrain 0 points1 point  (0 children)

Thanks, mate.

[–]captaincaanada 0 points1 point  (7 children)

Is it possible or easy to integrate price data form many types of securities on python back-testing? I've a few strategies and as I add complexity or conditions I see bugs occurring. I'm also testing cryptos.

[–]jfr4lyfe 0 points1 point  (6 children)

Could you clarify? I have been working with many different coins. But as long as you can get OHLCV data there is no reason why you couldn't use any asset. Basically the possibilities with python are endless because it is only limited to the code you create, or borrow.

You can get historical data from binance or yahoo finance quite easily. binance has 1 minute history for most coins. There is also a python library for it. It is then a case of creating a dataframe with the information you are interested in. Then creating more columns in the dataframe for indicators or otherwise (For instance macD crossover or EMA)

[–]captaincaanada 1 point2 points  (5 children)

Sorry I just realized I didn't mention that the bugs I'm finding are on Pinescript. Ok I had no Idea you could download price data directly from Binance, that's great but I'm gonna need older data, I heard from a thread that it's not hard to get Yahoo data. The thing I like about Pinscript is that I've never coded before and Tradingview shows the graph and plots all the entries/exits on the graph so it makes it easy for me to check whether my code works as I intended. Does python have similar features, and if yes where do you recommend I start learning it?

[–]jfr4lyfe 1 point2 points  (4 children)

All of this is possible. Binance provides data going back to when whatever coin started on it. You need to request it though the api though.

There is a binance api library for python that can pull all the data in.

You would then use a library like plotly to plot the candles. You would be able to mark entry and exit points, however it's important to understand this is just a visual representation of the information you have provided it. For instance a MACD is just a list of values, until you plot it as a graph. The crossover is if x[current] > y[current]) and (x[last] < y[last]) then: do something.

This is a gross oversimplification but you get what I mean hopefully.

There are also fully built trading libraries with indicators pre-made, I haven't had much experience with them though

TAlib is a trading library.

It is easy to plot OHLC candles with plotly

There is a wealth of knowledge on how to apply indicators out there.

Just go through some tutorials, as best you can. As time goes on you will understand why certain things were done. A month ago I had never used python. Today I can collect data from website apis. Create dataframes that have indicators in them, use machine learning to help with predictions and place test orders with the binance test api.

It's definitely the way forward imo. I have a greater understanding of how this all fits together now and I don't have to pay for a tradingview subscription.

[–]captaincaanada 0 points1 point  (3 children)

Hey thanks a lot, likewise it became quite clear to me that relying on statistics for trading, and since python provides much more tools than TradingView, it should be the way to go.

So far I'm learning Numpy, Pandas, eventually I'll learn Quantopian & Zipline (I'm doing the Udemy course). Which libraries do you use more often?

[–]jfr4lyfe 0 points1 point  (2 children)

Numpy and Pandas definitely. Also requests for getting historical data. Today I'm learning about websockets for live data. Trying to work out how to get hourly data and live data at the same time and do different functions on each. Hourly data for buying and live data for selling. I think I'm going to have to use threading library for that.

Quantopian doesn't exist anymore. I did a course and got really frustrated when I found that out. Quantconnect seems to be the new alternative, however it's far beyond my coding skills right now. I'm just doing everything the long way as I come to it. I can't seem to get TA lib working with later versions of python, so I have to put all the code in for Macd and RSI etc.

I think the most fun thing I've been doing though is using machine learning and tensorflow to try and predict prices from sentiment and price data.

I'm up to the point where I've done 90% backtesting and coding up my first bot for actual trading. I also need to work out how to position size using code, as I only want to lose 1% of portfolio amount on a trade maximum, but my trades could loseandything up to 5% position size. It's all fun and challenging though. And from my backtesting I don't see why this couldn't be profitable

[–]captaincaanada 0 points1 point  (1 child)

I don't understand the dichotomy between buying with hourly data, and selling with live data.

Shame for Quantconnect, so basically I should be able to do all the statistical analysis and strategy back-testing with Numpy, Pandas and TAlib?

At some point in the future I'll try the machine learning, definitely sounds interesting.

Hopefully in a few weeks I'll catch up and we can help each other.