Progress Update 5: Starting Python
Yesterday, I ran into some programming problems with TradingView's PineScript. I have ran into some problems with PineScript leading up to yesterday, but this was completely absurd. My main algorithmic problem that I was trying to solve was the negating orders problem that I described in the last blog post. If my trading algorithm was capping it's losing trades and getting bigger winning trades, I want to encourage that by minimizing the amount of useless orders that go through. $0.01/contract fee doesn't sound like a lot, but hundreds of negating orders being put through over a 10.5 year back-test implies a lot of useless trades in which I just eat fees.
Which means that I can possibly complete the basic course before my 7-day trial ends and start the "Analyze Financial Data with Python" skill course I am aiming for.
In the last blog post, I figured out why the problem was occurring, but then the task was to solve it. I thought about it for a while yesterday and finally came up with an efficient solution. The first step was to find a way to see the pending orders that sit there waiting to execute at the close of the 4 hour bar. Once I have the information of all the pending orders, I would check to see if there is an even or odd amount of contradicting orders. If there is an even amount of contradicting orders (e.g. 1 buy order and 1 sell order) due to an indicator crossover and "un-crossover" within the same bar, then I would cancel both and let the algorithm stay in it's current position. If there is an odd amount of contradicting orders (e.g. 1 buy order and 2 sell orders) due to an indicator crossover and "un-crossover" followed by a change in position, then I would cancel the preceding orders and let the most recent one execute at the close.
This solution I have come up with is an efficient way to eliminate all the noise that the indicators listen to and could differentiate between just noise and noise with an important position change clumped together. Okay, I logically figured out why my algorithm was making unnecessary orders and eating fees. So why can't I fix it?
The problem with implementing this fix was that TradingView's Pinescript (which is the language built into TradingView that you use to create strategies) didn't have a function or way (that I could see) to view pending orders that were set to execute at the close. I essentially backed my semi-successful trading strategy into a corner with very few ways to get out. I wasted hours trying to figure out a way and even walked away from the computer to do other things to get my mind off it.
My eventual solution was to act like the algorithm. This "winning" strategy I have coded has run it's course in the Pinescript programming language. I had to cut my losses and get started right away on the process of porting it over to Python to eventually implement. The trick is, I don't know Python. But I do have 4.5 years (high school + 1st semester college) of Java programming experience. I just have to learn the small quirks that Python has and Java doesn't and learn how to use a discount broker's API.
This led me to CodeAcademy's Python courses. All the Python courses were a premium subscription only so I signed up for a free trial and then to be eventually charged $20/month billed annually. Realistically, I know that I can learn this entirely online for free and save myself $240. But what is special about CodeAcademy is that they give you certificates that you can put on a resume and integrate into your LinkedIn profile. So logically, paying $240 for as many courses as I can take in a year is a no-brainer. Compared to the thousands I spent for 1 online Microeconomics Summer course from my University.
So today I started the basic Python course and completed the Syntax, Functions, and Control Flow modules today. Which those 3 modules make up 21% of the course.
Once I complete both these courses, which I believe to be necessary to build this stock trading bot that I am tackling as a summer project, I can take any other course that interests me to add more skills under my belt and be able to show off on my LinkedIn. Over the course of the next few days, I will try to balance getting 3 Python modules done and read more trading books to gain more necessary info to create the perfect trading bot.
-Jamie


Comments
Post a Comment