
Get every episode summarized
Each time Tina Huang publishes, we email you a written briefing from the transcript — the topics, who appeared, and any specific claims, with the ad reads skipped.
Email me new episodesFree for 3 shows. No card needed.
About this episode
Tina Huang is made possible by:
“Jake, you're promised me that he will guarantee that I'm not losing all my money.”From the transcript
Get every episode summarized
Each time Tina Huang publishes, we email you a written briefing from the transcript — the topics, who appeared, and any specific claims, with the ad reads skipped.
Email me new episodesFree for 3 shows. No card needed.
Hosts & guests
Transcript ready
3,124 searchable segments. Every word is indexed and playable.
Full transcript
Tina Huang — We code a trading bot live! @jacobamaral | Tina Huang. Machine-transcribed; use the interactive transcript above to jump the player to any line.
I think we're live now. Hey, everyone. How's it going? Sound check. Can you guys all see and hear us? Test test. Yeah. Streams live. We look good. Steven, how's it going? Sandtosh, the dream team. Got so excited to trade with you. Yeah, me too. I'm so excited as well. Jake, you're promised me that he will guarantee that I'm not losing all my money. Isn't that, isn't that right? Yeah. I didn't have to go back on that. Oh, no. Just FYI, I fund in my account with 25k because that's how much we needed to, um, to allow like day trading, but I didn't actually know that you could fund it with less. So, so Jake, you got promised me I can't afford 25k loss.
Yeah, I know, no, no. Well, we'll, we'll pray you know, one share, uh, we'll keep it low, maybe under a thousand, um, where your, your life savings are still intact. Sounds good. Sounds good. All right. Let's like hang around for maybe like five minutes or so, and then we can get started to see if people are going to trickle in. Hey, we're pretty good. We're 58 people already. Hey, everyone. Hey, Andrew, how's it going? Phoebe? Let's go. Hi, Nick from um, Katsuo to show. Katsuo to show. I'm sorry, I'm trying my best. How's it going? Good morning. Hey, everyone. What time is it? Uh, it is currently 10 a.m. for me and a 11 a.m. for you. Jake, right? That's correct. Wow. You got that right. That was a spot on. Look at me. I can do time differences. Wow. I'm not going to be a little bit more comfortable. Andrew, I think this is a fan of yours. Right? Uh, Jacob. Welcome, Andrew.
Why don't we do go to Jake or Jacob? I seem both. It's a good question. Um, my legal name is Jacob, but everyone calls me Jake. So I don't carry the way, but I would say Jacob. Like a Nick. I'm going to be dang. I was about to write my prophetic high coup. Wait, right? Oi, it's Sunday. Is that right? Finish your high coup, Savi. What's good? It is. Thanks for joining. Hey, the mods are here too. Hey, Farhan. How's it going? Savi, we have time. We still have like four more minutes. You can, you can write your high coup. 8 30 p.m. Wow. That's late. Yeah, 8 30 p.m. I appreciate it. I really, really appreciate that you're joining. That's dedication right there. Respect. Um, what? What will be the programming language you're going to use? So we're going to be using Python. And don't worry, we're going to start all the different strategies and explain, you know, this is the code we're using.
We're also going to be explaining the API and everything. And this isn't just for you guys. It's also for me. Don't worry. We'll be going super fast. Will we be able to watch this later? Yeah, the stream will still be on later on as well. So do not worry about that. I would call them. Yeah, cup. Interesting. I'm okay with that name too. I'm going to show you guys. I can call you wherever you want. Trunk, man, it's one a.m. And Australia dropping to say hi. Who watched her pretty. Hey, thanks so much for dropping by. Really appreciate it. Yes. Go to bed. Go to bed. It's all good. Still going to be here when you wait up. Kiddo, how's it going? So excited. Yes. Me too. Hey, Sebi. Sebi's high coup is here sitting. Okay. I'm going to meet your high coup. So I letる涂 at red clear. Okay.
Can you get me a barb엔 or a barb peninsula from U.S., weather up there being there now and everywhere. I'm really under a tree of mine. I think the world is a straight line. It's the summer ofcks 69. Will you be my Valentine dedicated to my love pudding. Putting, you gotta be here. Jake, this is true. I, uh, that's not one of my strong students. So, Sebi, that was amazing. Well done. Sebi, maybe you can write one for Jake too. I think they'll make him feel very flattered. Yeah. I make me feel very welcome onto this stream, but you don't have to if you're busy with stuff. Oh, by the way, a context in case you don't know Jake, putting, so Sebi has a love affair with putting, you know, their wonderful friend of ours on the stream. But putting likes to run away from Sebi, because Sebi just wants to eat him all the time. I think putting the guy, I, I, I don't actually don't know if putting the guy. I don't know if I will, we're putting. It's developing, the relationship's developing. It's in the works. That's true. Sebi, you just have to knock it off, right?
It's all about consistency. Well, we talked about here having consistency. You just got to keep pursuing without being creepy though, or getting arrested because that's bad. Yeah, I, yeah. Tina knows what she's talking about. Let's go to Python. Awesome. Love it. Yeah. Sorry, I'm like lagging a little bit. Uh, okay, cool. I think I'm good now. Okay, shall we get started? I want to see this one more minute. It's one more minute. Let's chat for one more minute. Albert Paso, I think he's so much for making this interesting content. Yeah, I was just, I just want to say thank you so much for Jake for coming on. I appreciate it so much. Like there's no way that I could have done this by myself. So I was so happy. Awesome. Thank you for having me on. I'm excited to more of these live streams. I'm loving the live streams. I don't know. They're way more fun, right? Yeah, because you get to interact with people. And it's just like, yeah, I really love to after doing live streams. I just get so after as well. Yeah. And it's more like it's more genuine, right?
Because like it's not scripted. So it's like you're doing the live stream and you're trying to build value or you create content. And you know, sometimes stuff doesn't go your way or it does. And you get that kind of genuine reaction. So that's what I like the most. Exactly, exactly. And then you know, if you say something wrong, then too bad. Too bad it's going up. It's going up anyways. So I think you get like the true personality as a people. Yeah. Yeah. All right, we're at 10.5. Should we get started? Let's do it. Let's do it. Let's get going. All right. So I'm just going to briefly tell you guys the agenda for today. So where's the agenda? I can't find it. We might get a question. OK, so we're going to start off just just introducing himself. And then we're going to go and explain what it is that we're going to be doing today. We're going to be taking it real slow. So really explaining the code of also the APIs that we're going to be using. And then we're going to get started. And while we're getting started, the agenda is, so first, like, actually code and explain the strategy we're going to be using.
We're going to start off with an RSI strategy. And then we're going to test the strategy. And then we're going to pick the best one. And then because it is a Sunday today, so unfortunately, we can't actually run it live. But what we will do is we'll pick the ones that we want to run. And then on Monday, I will run it for a week. And then after that, we're actually thinking we might do a reaction video. We might do some, I will W do some sort of video to show you guys what happens. And see how much money we win, we're lose. How does that sound, everyone? I hope that sounds like an exciting agenda. I'm super excited to get started. All right, so shall we get started? Why don't Jake view the four of yours? Let's do it. Hello, everybody. My name is Jacob. Nice to meet you. Thanks again for Tina for having me on the live stream here. I use software to invest. I build custom software solutions for people in the financial markets. I also use algorithms and automated trading
bots to invest my own money. And I have a YouTube channel as well, where I show people how to code trading bots. I show people how much money I make or lose per month. And people have seen that, which is very interesting. But yeah, I just love of sharing my knowledge. And I have a big passion for building algorithms and automated investing. So that's me. And yeah. Yeah, awesome. Check out Jake's channel. He has all the trading bots that he's built. And I think everything you have got is open source as well. If you actually post your code for everything. Pretty much everybody build. I'm like, here's the GitHub. I just want to give people that foundation so they can start on their own. And it's cool because I get a lot of comments and emails later saying that they use one of my bots and they built on top of it. Now they have their own system. And that makes me feel really good. So it's really cool. Yeah. That's that incredible, amazing free resource out there. So you guys definitely go check out Jake's channel. Also, if you do a lot of coding with you, videos,
and you've done your first live as well. So if you guys want to actually have a walk through video, so Jake's the guy. Awesome. Thank you. All right. Let's see. Champion of Whiz. He said while reading the script. I don't think you're reading a script. Are you kidding me? He got me. No, I'm not. I'm not reading a script. But if it seems like I am, then I need to do better at being a normal person. But good catch, good catch. That's pretty funny. I think it's just that you talk, you speak well. You don't say, um, to make it. So I think it's a compliment. All right. So why do I let you, Jake, also explain what it is that we're going to be doing today. Oh, and I also just wanted to, I forgot to mention earlier in the, like, feel free. If we want this to be like a super interactive session. So please, like, feel free to drop comments, ask questions, talk to each other. You know, we're going to, we're not going to just be like, say here is this code and not talk to the one. Like we want this to be like a super interactive session as well.
Yeah, that's, that'd be really boring if we did that. Like, really boring. I know. All right, Jake, floor is yours. What is it? What is it that we're doing today? Do you also want to share your screen? Do you want to do that up to it? Not yet, not yet. Cool. But today, guys, today, so this is what's going down. Today is going to be awesome. We're building a automated training system, 14a, utilizing the TD Ameritrade API. So TD Ameritrade is like a big financial company. You can buy and sell stocks with their platform. But we're going to be building an automated training system using RSI, which is an indicator or a strategy. And it's actually going to buy and sell stocks for Tina. And we're going to code it today. We're going to explain how the code works and actually start coding it as well and finish it, essentially. And then, you know, run it for a period of time in the future. And hopefully make a video in the future of what the results were, right? How much did it make? How much did it lose? So today is going to be the start of that. So we kind of have the base code already set up.
We have it kind of connected to the API and getting data, which we'll explain. And then I'm actually going to do some back testing where we test the strategy historically and see how well it does and tweak it a little bit so we get better results. And that way, when we run it live, we kind of have an optimized, we have a good trajectory for hopefully a better edge in the market, better potential profit. So that's kind of the plan for today. I think we were going to start with explaining the code and then kind of going from there. That was good. That was good. Anyone have any questions? Feel free to ask. Norma, will you upload the code? Yeah, I feel like I'll upload the code, right, Jake? Why not? Do it. Go with the open source. Open source. That's what the cool kids are doing, right? That's what I heard. That's what I heard. I don't know. I'm not going to. I guess we'll do that if that's what the cool kids are doing. Cool. Do you want to share your screen? And we can explain the code.
Yeah, let's do it. I think I have to do more share screen that we actually have. Yeah, let's. All right, can you guys see? I can see you can see. I'm checking the stream. I want to make sure I'm checking the stream. I'm waiting for it to catch up. See if they can see. I think the lag that I have here. Oh, you know what? You know I screwed up Jake. I screwed up. No, it's working. It's working. You can see. But I mean, the stream latency, I wanted to. I forgot to put it at low latency. So it's at normal latency. So we have a few seconds to wait. OK, that's fine. Yeah, OK, we'll roll with it. OK, so everyone should be able to see now. I think we're good. Yep, everyone's singing a chat. We can. Awesome.
OK, so I'm going to explain the code. Step number one, explain this code. So how does it work? So it's in Python. At the top, we have all our libraries that we need, all of our imports. So the main one that we need is called TDA. And this is an open source library that uses the TD Ameritrade API. So once again, TD is a bank. They also, you can also buy stocks through them. And they have their own API. So if you want to buy and sell stocks through software, you can use their API instead of downloading the app and using, I think they're most popular apps called Thinkorswim. But so you can use their API to kind of have more control and do it automatically. So we have our imports here. We have their authorization import. So they use, I believe it's OAuth, but basically, you log into the website. Sorry, sorry to interrupt. There's people asking you to zoom in a little bit. Oh, zoom in. Yeah, sure thing. Let's go 200%.
I think that's. Let me know if you guys can see better. I think that's a lot of code. Wow. It's not that much. It just because I'm zoomed in, it looks like a lot. That's the secret. Yeah. All right, let me know in the chat if you guys can see better. I did 200%. Can you hide the messages from us because it overlaps? The messages? Perfect. Kids is perfect. Andrews is perfect. Awesome. All right. So we have our imports here, TD Ameritrade, and then we use their authorization import as well. So basically, you can log into their website and use OAuth. And once you log in with your TD Ameritrade log in account, they will actually send you an access and refresh token. And those tokens you can use to make trades on your behalf or access your positions and stuff like that.
So that's kind of the big part of using the TD Ameritrade API. And then there's streaming. So streaming is when you want to get real-time stock data, stocks are trading all throughout the day. And you want to be able to get those that data in real time to submit trades or to do logic for your trading system. So that's what the TDA streaming library is. And then we also implement the equities and orders libraries. So equities and other named for stocks. And this allows us to buy and sell stocks, basically being able to submit orders in an easily readable way. Because submitting an order for a stock, there's lots of options. And with these imports, it allows us to kind of make it easier for the programmer to easily submit a trade. So we got those. Those are the main kind of library that we're using. We have a couple others. So I won't go through everyone, but I'll just mention a couple.
So PyTZ, this is for time zone. It's not really a major issue if you're just using it for yourself. But I always like to put it into an Eastern time zone just so it kind of lines up with the market hours and stuff like that. We actually have, I don't know if you guys sort of selenium. This is another really popular library. But this allows you to basically open Google Chrome or a browser and get kind of results from that browser. So we actually use selenium to, initially, when you run this bot, it will actually open up Google Chrome and go to the TD Ameritrade login. And then once you log in there, it will send back the tokens and we use those tokens to access the API. So it allows us to kind of open a Chrome automatically and kind of speed things up. And then we have some other common ones like pandas and numpy. And we use TA. This is going to be our RSI import TA.
So technical analysis is a library for common indicators in kind of trading. So stuff like RSI, MACD, simple moving average crossover that stuff. So yeah, that's kind of the imports. Let's go down a little bit. So we have two classes here. We have the bar class and a bot class. So the bar class, I'll try and explain this as simple as possible. But actually, I'm going to pull up a, it's going to pull up a chart here and drag it over. Give me a second. Bear with me. So pull that up. And let me know if you can see trading view here.
Or have you still see my code? I think we still see the code. Well, actually, no, I just, so I think that was the last guy. I can see pretty new now. So I can be sure people will see it. OK, let me know in the chat if you guys can see the chart. Are we getting tons? Oh, yeah, we're good. Yeah, I see. OK, we're good. So this may look really confusing. I know. I'll try and make it as simple as possible. But anytime there's this price movement in an asset, like a price can go up and go down. It can stay the same. Most traders use kind of these candlesticks to show that price movement. So say you have Apple stock, for example. And it's trading out $100 per share. In one minute, it might go up to $101. And it might go down to $99. So these candlesticks kind of show that price movement. So in this example here, I'll zoom in as much as possible. So we'll do say daily.
So here we have a red bar. And when it's red, it means the price movement went down during that time frame. So right now, we're on daily candles, meaning every day a new candlestick is drawn. And what this is saying is this candlestick opened at this price, right? Where my kind of cross-air is. And it closed at this price below it. So it went down in value. And then you can also see that it kind of has wicks, like an actual candlestick. So these mean that it actually went up to this price, but it didn't close there. And same thing, it went down to this price, but it closed up here. So and it was red because it closed below the open. Now when it's green, that means it opens here and closes up here. And this will be for May 6, which was two days ago. And yesterday, May 7, kind of thing. So these candlesticks are a way of showing price movement for a certain time frame. Let me know in the chat if you're still confused,
but I just wanted to show you what a bar or a candlestick looks like. And bar and candlestick are kind of synonymous. They're the same word, essentially. So we use a bar class to store these prices. The open price, the low price, high, close, and then the volume as well as the date. And this allows us to keep track in history of what those bars did, right? Now we know, OK, if we looked back yesterday, what was the bar for that day? And this helps us kind of understand. So kids has understood. Awesome. Great. Much science. Much science. I got it. Good one. You know, I'm late, but what does the bot do? So actually, Jake, I'll let you explain. So the bot will essentially automatically place trades by and sell stocks based on a strategy. And we're going to use the RSI to determine that strategy. The RSI is an indicator. So we're just explaining the code right now. And I think we'll start actually showing you
the strategy and how it works. That's the bar class. And then finally, we have our bot class where we set up some initial variables as well. Like stuff like account size, our RSI indicator, which I'll explain how RSI works. And I'm showing my API key. Awesome. That's great. It's not a big deal. It's another account. Basically, we used TD Ameritrade to be our main API. And we pass in our API keys in the self.client variable. And then we save that and update our account size with the results. So actually, when this code runs, Google Chrome will actually automatically open and say, hey, you need to log into TD Ameritrade. And it will actually bring back the, it will save the access and refresh token so we can use it in the future. And then it will say, all right, you successfully logged into your TD Ameritrade account. Awesome. Enter the symbol you want to trade.
So every stock has a symbol. Stuff like Apple is AAPL, stuff like Tesla's TSLA. It's just a short form kind of word to reference that company with a stock, right? So it's you'd enter your symbol you want to trade. So in our back test that I'm going to do for Tina, we're actually going to choose which symbol to trade because sometimes, you know, trading the first stock off your head with the strategy isn't always the best. It's not always going to give you the best result. So sometimes you got to kind of tweak it and try to multiple different basket of stocks to see which ones are the best for that strategy. And then lastly, we say, all right, enter the bar size you want to trade in minutes. So our code is going to execute every time a certain time frame has passed, right? So if we put in one year, every one minute, it's going to execute. It's going to calculate the RSI. It's going to either buy or sell if it's, you know, in the right logic. If we put 60, it's going to happen every 60 minutes every hour. So we can kind of choose.
We can actually fine tune how often we want it to trade. And generally what I find is, you know, from my success, longer time frames are going to be more successful. So I have a lot of trading systems and trading bots that trade on 60 minute, 120 minute, or daily candles. They're not trading as often because if you trade too often, like every minute, sometimes you kind of get too many, not quality trades, right? And then there's stuff like commissions as well. So anyways, we can choose what bar size we want to trade with. And then we enable our stream client and this allows us to get that stock data, get the data for that stock in real time. So that's that. Let me know if I'm going too fast in the chat. And then we call, we actually run it using Async IO. And this allows us to run it asynchronously, which means our program can receive data from TD Ameritrade, but not stop. It can keep running in real time.
So it's kind of like the opposite of synchronous. It happens at the same time kind of in parallel. So it's not blocking our application from continuing to run while we wait for data. OK, so that's that. Here in our read stream function, we say, basically, we say, all right, we want the symbol data that we want. So say Tina entered Apple here for the self-symbol variable. Now it's actually going to stream data for Apple. And because of Sunday, we're not going to get any results because the market's not open. The market is open Monday to Friday. So but on Monday, tomorrow, she would get data. So this says, all right, TD Ameritrade, I want you to subscribe, subscribe to Apple Data. So do it here. And then we say, all right, any data we get, we're going to call our on-bar update function. And this is where most of the magic's going to happen. This is where the bot's going to calculate the RSI. And it's going to buy or sell if the logic hits. OK, so we do that. And we say, all right, we're streaming real time data now. And then we go to our last function called on-bar update.
And this function is called every time we get a bar. So every time TD says, all right, there's an update in Apple price. Here you go. It's going to send it to this function. And here we calculate stuff like the RSI. And also, we're going to code our strategy here essentially. So for every bar we get, we calculate the current time. So what the current bar time is. And essentially, this if statement here, line 114, is like where we're going to be writing all of our code. Because this if statement is saying, all right, if the bar we're getting, if it's been one minute or if it's been 60 minutes, whatever Tina's selected in her bot, this is what's going to run. So we check the difference in minutes from the bar, because we might get a bar every say five seconds. But we want to wait until say 60 minutes have passed or a minute has passed before we run this. So this if statement here, line 114, is kind of we're going to be running all over code. And here we get all of our bars here. And this is where we calculate our RSI.
So we use the TA module library. And we all the previous bars that we have, we throw it into there. And it does the calculations automatically for us. And then it actually prints the RSI, the most recent RSI. And this is where our strategy is going to lie, because we need this RSI to determine if we're going to buy our cell. So right here, like right here is where our entry point is going to be. And we're going to start coding our entry and exit logic. And then the rest of the code is just updating the bars, updating the open price, the high price, the low price, as I showed you in the chart previously. So this doesn't really matter right now. This is kind of, I would say like right here, is we're going to start writing the majority of our code, because we have the RSI. OK, now when do we buy and when do we sell? So sorry, that was really long. I'm going to take a breather. Is everyone confused or was this too much? I want to see what everyone's thinking.
Yeah, I thought that was really clear to me. I'm actually really surprised that there was the TA, like the technical analysis module, because I was expecting that we have to calculate all from scratch. I think this is so nice. Yes. You just have to get that function there. So I think if anybody else has any questions, I think there's a little bit of lag. But I do have a question for me starting off. So if you scroll up a little bit. Yep. The if minutes, if greater than zero, self dot bar size. So would you mind explaining a little bit about what that is doing? Absolutely. So what this is saying is it has, so on the left, on the left of the end, we basically say, all right, if minutes difference is greater than zero. So minutes difference is the current bar that we're getting. So say we're like, all right, we want Apple stock. It's going to give us a time for that bar, right? So it's going to say, all right, here's your Apple stock
for 9 PM, for example. So we take that 9 PM, which is bar time. And we actually subtract it with when we ran the application. So this self dot initial bar time is, when we run the application, it actually tells us, all right, started running at X date. So we want to make sure that it's greater than zero, meaning that sometime has passed since we ran the application. And then right here, after this end statement on the right side, basically what we're saying is, is the difference in minutes divisible by our bar size? So for example, say you selected 60 minutes. That means we want the bar for every 60 minutes, every hour. So the difference in minutes needs to be at least 60 before we can run this if statement, right? So this is dividing the difference in minutes, and I rounded down using mat.floor with the bar size. So once this minutes difference is 60 or greater, and it's divisible by 60, right?
We can run this application, right? And the reason why we do this is because your results, your profit and loss will be very different if you traded one minute candles versus 60 minute. Because if we did one minute, every minute, this if statement is running, right? And it might make more trades, and it might make worse trades, it might make better trades. Versus if we did 60 minutes, it's going to trade a little bit less technically, and it allows more time to pass. So that's kind of what that if statement does. All right, I see make sense. And this is also how we can actually control the frequency of the trades, right? So it doesn't just blow up my entire account. Yeah, we don't want that to happen exactly. Oh, in case if anybody's not script-related with Python, just in case people don't know, like the percentage sign is a mod symbol, just in case people correct coming from other coding languages. Cool. I mean, that is pretty clear to me. Let's see if anybody else, why everybody else is thinking. Okay, so what's RSI?
Yeah, we can go into a little bit more detail about what RSI is after seeing if everybody else understands like the code structure. Andrew, you got most of it. Awesome, Mike, it's cool. Jessica, that was clear for me. Via new relative strength, it does. Good so far. Jake, you're a great explainer. Awesome. Everybody understands that you're talking about. Sebi, no, that sounds terrible. That was the worst trade deal. No, we're trading. We're trading. We're trading. I remember that. That was such a funny meme. Oh, God. Mehl, how do we make a decision based on RSI? Yeah, I think we can go into a little bit more detail about exactly how to implement that strategy because that's actually what we didn't implement yet. The part about how we're going to decide based on the RSI. Andrew, will the bot have some sort of GUI? Where will it be purely running in the files we code? I think right now it's just on the files, right? Jake, if I'm not right. Correct, yeah. A GUI would be much more of a lengthy process.
So in order to keep time short, it's just going to be in the command line. But maybe we'll do GUI in the future. It's a lengthy process. Yeah, I think when you're in danger, what do you think that you need? It does have GUI that doesn't it? Yeah, I was actually going to show that next kind of how the strategy is going to work. And then from a chart perspective, and then we'll actually start coding it. So yeah, I think that's the plan. I just wanted to see if anyone else had any questions about the code before I move forward. I think it looks like we're good. I think most people, the questions are just about like what RSI's and how our news are are so I can maybe move you to move on to that. Yeah. Okay, sweet. So yeah, the RSI is what's called an indicator. And an indicator is a way of mathematically showing some type of result from say candlestick.
So I'll show you an example of what the RSI looks like. I'm actually going to pull up an indicator here. I'm going to pull up a chart. Okay, so you guys kind of know how candlesticks work right now, right? So we can see the price movement from this is Apple stock. So we can see that the green and red bars. And if you guys still don't understand candlesticks, let me know in the chat there. But on the bottom here, we have this RSI chart. And this RSI is, like I said, it's called an indicator. And it basically it calculates, it has a formula to calculate, say, the average of these bar movements. Okay, so it has a formula and it will actually draw on a separate chart what those results are. Okay, so there's thousands of indicators that many of people have created and they use some type of formula to show some type of price movement, right? Could be forecasting, it could be an average, it could be a deviation, for example. It's just, it's all math essentially. So RSI is one of those indicators, you know, is it the best?
No, we'll see from the back test, but it's a way of creating a strategy. And we have to see if it's going to be profitable or not. But anyways, there's thousands of them. We chose RSI because I think Tina's heard about it. And it's one more of the more simple indicators. So I think it's a great starting place. So in this chart, go ahead. I was going to say I also just linked to invest the pdf page. I want that once to check out the formula for it. It's one of the simpler ones to understand. Yeah, yeah, give this a read. It's pretty good. Okay, so we're going to use this RSI indicator to essentially have the entry and exits, right? Where we buy and where we sell. Okay, the most common rule, which I think we'll start with, Tina, is when the RSI goes below the 30 level, right? We essentially buy. And we sell when it goes to the 70 level, right? And these 30 and 70 levels are, they're not set in stone, but whoever created the RSI, I think that person, I don't know who it is.
That's what he hypothesized. That's what his thesis was that this was a good trading system to buy at 30 and sell at 70. So that's, I think that's where we're going to start a strategy. And then from there, we'll actually code it. And then we'll actually run a back test and see what the performance was. And try and optimize the values a little bit better because, you know, maybe buying at 30 and selling at 70 isn't the best way to do it. Maybe it's 40 and 80. Maybe it's 33 and 67, for example. So we can actually optimize those values and try, try different scenarios and then pick the best one and then use that to run it live. How does that sound, guys? Harold says I love trading bots. Awesome. Thank you so much for supporting the channel. Really, really appreciate it. You know what? We'll use that money towards our trading law as well. Let's do it. Get some returns. Yeah, we'll get you some returns, Harold. We're losses. We'll try our best.
Thanks again. I think so, it was one of anybody have any questions about RSI. Just wanted to make sure that people understand what's going on there. Now is the time to ask before we start actually building it out. Well, people are potentially asking questions. I was curious, Jake. You're doing a backtesting all in Inditrator, right? Because I don't think you can do it on the TD one without a clue. Correct. Yeah, so I've, for my clients, I built custom backtesting engines for TD. It's just four time purposes I didn't want to show it to you because it's a lot to set up. But yeah, I'm using Inditrator to backtest just because, personally, I use Inditrator with my own money. And it's a simple way to backtest that you can run really quickly. So I'm going to be using Inditrator to show Tina the backtest results as well as, you know, optimizing because it's basically an all-in-one software to do that for you.
Their main kind of offer is, you know, easily create strategies and backtest them and run them live for their customers. So I think it's a really great platform. And I like it very much. I feel like I'm going to be so of this platform. Got to, like, I hope you have a referral link. I'll use your referral link after this. I don't. I don't. I wish I did. You can at least take a percentage of mine because I'm so sold on this now, especially because looking at the TD API, I'm just like, it's going to be a pain to actually code all the backtesting stuff. Yeah, it's a lot of work. Cool. I think we're all clear. Perfect. Perfect. Pretty clear. Don't forget to mention this is not financial advice. Yes, yes, yes. It is not financial advice, Jacob as well. You must say it's this is all entertainment purposes. Yeah, don't take financial advice from us. We don't know what's happening. Yeah. Cool. Oh, and just in case somebody doesn't know backtesting here,
he's just referring to pretending that we're in a a past day and then see how your your algorithm, I guess your trading bot performs from that period of time. So correct. Cool. I'll show you guys starting now. Let's do it. Yeah. So I'm going to hop back to the actual code. And initially, what I want to do is starting from here line 126, I want to start using the RSI to to make trades. So what we have to do, pretty much, I'll write in the comments here to do it. We need to submit a trade, right? Enter a trade and exit a trade, essentially. And we want to use the RSI to do that. So I want to code the entry and exit for the trade.
So right now we have the RSI, right? Which is this line 123 here, self to RSI. This is a list. So it's not the recent value to get the recent value. I have this print here saying, hey, no print the last RSI, essentially. So once we have that kind of last RSI value, basically what we're going to say is, hey, if the RSI is less than equal to 30, we're going to buy. And if it's greater or equal to 70, we're going to sell. We have to take it one step further and check if we're in a position already. So if we're, if it's greater or equal to 70 and we're in a position, we actually, we're actually holding that stock, we want to sell, right? And same thing for 30, we don't want to buy multiple times. We just want to buy once if we're in a position or not. Okay. So basically we got to do an if statement saying, if the RSI is less than or equal to 30 and we are not in a position. Bye. Okay. So to do that, we're going to have a,
if statement saying, if pretty much this, the most recent RSI, is less than equal to 30 and we're not in a position. So we're going to have to create a variable to say, and we're going to set this Boolean to say, all right, how we submitted a buy order, then we are in a position. So I think we'll set this in above the, yeah, in the class saying, in position. I'll come back down here and say, and not in position, then we want to submit a buy order. Okay. Now to do a buy order, I have to give me one second here. I don't know off the top of my head how to, how to do it through great API. So I'm just going to pull up some code here on the my other screen and, and find it.
So it is, do, do, do, do, do, do. We want this. Oops. Just bear with me for one second. Keeper going crazy in the chat. Answer some questions through. Got any other efficient indicator apart from our sign where we're using RSI here? Yeah, there is a lot of indicators. I think by definition, you'll have to, the word efficient, right? Like that's, that's something that is debatable about what that really means. There's a lot of different indicators and some of them are more useful than others. But really what it comes down to is like, you know, this is as we'll probably later see, this is not going to work super well because if it were, everybody will be making bank on the stock market, which is using RSI, right? Because it has to be a lot, a lot of other indicators of you like where other factors are going into it as well. But via Nuke, thanks so much for listing some of the other indicators as well that people generally use.
Okay, I think I found it here. So we're going to create an order. And it is going to call tga.orders.equities.equity. Equity underscored by, so we're going to submit a market order. And there's different order types. I'm not going to explain all of them for now, but I'll explain the market order. Essentially what a market order does is it submits an order and whatever the current price that stock is valued at, it's pretty much submitting to that price. So we get filled pretty much instantly. And there's no, there's no weight. There's no delay. So this is just for ease of use. For this example, it's, it's a good, a good one because we're going to get filled immediately, meaning we're going to submit our order to the market. The market's going to say, all right,
you know, you wanted to buy Apple at X price. Here you go. But that price can change, obviously, very drastically, right? So there's other limit, there's other order types where you want to get filled at an exact price. So it's either that price or nothing. But in this case, we're always going to get filled because with what we're trading, there's a lot of trades going on. And with the market order, it's going to ensure that we get filled pretty much almost immediately. Just for ease of use, but there's like thousands of order types. Okay, so we're going to submit a buy market order. And we type in the needs of the symbol. So our symbol that we chose earlier is what it's going to use. So we're going to pass in self.symbol. And then we can also pass in the quantity. So we just want to trade one share for now, just so we don't bankrupt Tina. Just one share of that symbol. So stocks trade at different levels. Obviously, you have something like Apple that's trading out $100 of share. It has something like Tesla that's trading at $600 of share. So it's going to submit
one share or an order for one share. So if Tina submits an order, a buy market order for Apple, it's going to get filled at, you know, whatever, I think it's trading out $130. So of her account, you know, $130 is now into that stock. All right, and she's holding that stock. So we're just going to do one share to keep it small. And we are going to set in position. You go to true. That way it doesn't submit multiple orders. It just does it once. And then we're good to go. Okay, obviously, they're, you know, if you wanted to do really, really good code, the better way would be to after we submit the order, constantly check our current account positions and see, all right, are we in Apple stock right now? Right? That would be probably the best option to do. Obviously, for time purposes, we're not going to do that. A simple variable is sufficient enough. But if we had a strategy that was trading multiple different stocks, we probably want to check our current account to see if we're in
positions for Apple stock, Tesla stock, whatever it may be, and really keep track of those. But because we're just trading one symbol right now, you know, this imposition Boolean should do the trick. So that's our buy order. Okay, the RSI is less than equal to 30 and we're not in a position. Right, it's going to submit an order by market order and set imposition to true. Okay. Now we need to do what's the next step. We have to do our exit order, right? So if the RSI is greater or equal to 70 and we are in a position, we sell. Okay, so I'm just going to pretty much copy this code actually this whole thing. And let me know if I'm going too fast guys. I apologize if I am. I think they're good. I'm modding the chart now. I think everybody is. I feel bad. I feel like I'm taking over.
No, it's all good. You know, I was actually a little nervous because I thought I was going to be the one coding. So I was like looking at this morning going like, oh man, I kind of figure everything out. But this is great. See, I'm not, I guess like, this is what I'm saying when you're live streaming. I'm just like saying stuff. That's complete truth. Just saying stuff and people. And we're like, it makes us sound. You know, we you guys thought that we were super organized coming in, but it was really pretty much just like, we're just waiting it right now. That's how we roll. Nothing wrong with it. Okay, and the only difference is we are doing a sell market order, right? When it's greater than equal to 70 and we are in position. Okay, and we're still doing one share and that symbol. Okay. So we said to false good. True. Yep. I think we're all good here. So this, this these if statements guys, right?
These are going to happen every whatever the bar size we set to. Okay, so once again, if we set it to one minute every 60 seconds, these if statements are going to run. It's going to check the RSI. It's going to calculate the RSI. It's going to check if it's below 30. If not continue, if it is, it's going to buy that sort of thing. So I think the next step is Tina. We have the initial code. I think it's time to run our back test and to see what kind of the results the results are and kind of optimize it because we don't know if 30 and 70 are going to be the best, right? So I think that's the next step. I'm just reading the chat here. I'm not quite understanding why in line 129, it is not in position. Good question. Okay, so BW, we want to so before we buy, we want to check that we're not in a position,
so we don't have duplicate orders, right? We want this bot just to buy one share, one stock at a time, and not submit duplicate orders. So that's what we have the not in position because we want to make sure that once it buys, it never buys again until it sells that position, kind of things have reset. So that's why we have the nod in there. Other questions. Mohammed, is machine learning effective? Yeah, I'm sure it is. I've tried to use it personally and I haven't found success, but there's a lot that goes into building really good trading systems using machine learning and personally I haven't found success, but I'm sure there's ways around it. There's been a lot of different ideas about using sentiment, using
news articles, kind of trying to rate articles and give it a rating to buy or sell. So I'm sure there's funds out there that I've seen a lot of success, but I personally haven't. So I would do your research elsewhere, but there's definitely a place for it for sure. I think our goal here is just to get something working, and then we can try to optimize that after. Yeah, yeah, the basics, right? A two back test date. I'm understanding that you have to go back to the trader and back test it, but it's not really using this code, right? It would be using it. Exactly. Yeah, so I've mimicked the code in an indicator to the same as yours. And that way when we can back test an indicator, we can see the results, and then once we optimize it and get the different parameters, we can actually change your code to mimic that. So yeah, they're not the same. Ninja traders in C-sharp, unfortunately, they don't support Python. So I'm going to hop back to Ninja trader, and we're actually going to run a back test with these current if statements. This current strategy that Tina has. Essentially, this is her strategy right here.
And we're going to see if 30 and 70 are good. So I'm going to hop back here. So once again, this is pretty much the same code, but it's separate right now. So in this example here, I've done Apple stock on 60-minute bars. Okay, so every kind of hour, it's the strategy runs and we have the RSI. So it'll buy when it's 30. You can see this buy here, right? And then the sell. So actually, I got to uncheck this. There we go. There we go. Okay, so this is a back test. This is going historically on where it's buying and selling. We can see it's selling when the RSI is above 70. Right? You can see it's holding this position and it's buying when it's below 30. And let me change to one share. So we're going to kind of accurate results. There we go. So this is once again mimicked from what we coded in Python there.
And if it's a green dot, it's kind of a profitable trade. We bought what they say by low sell high. It's the way to do it. And if it's red, it's not profitable. So I think we'll just do Apple stock tina just to make things simple. And once you wanted to trade something specifically, just to, you know, so we don't confuse the viewers. But let's look at the results here. So this back test was actually all of 2020 and 2021. So it was actually January 1st until today, March 9th. So trading one share of Apple, it actually made $7.80 in profit. So that's that's pretty good. It's actually profitable. Let's look at the chart here. So you can see it kind of the whip saw is up and down. But overall it made money for sure. So that's that's a good sign to see. I actually see a little bit. Sure. I don't know if I can.
Yeah, I don't know if I can zoom in. Let me try and make this bigger. Still too small or are we good? Yeah, or everybody else would you guys think? I think a lot of someone that chat if you can see. Yeah. That's really nice though. It's a hot one. You just just I'm sold. I'm sold to take get that for a coat. Okay, yeah, I'm watching the stream right now. It looks pretty good. So yeah, here's the results that initially. So if we use 30 and 70 to buy and sell, this is what the back test looks like. So it ended with $7.80 in profit. And these are all the trades that made. Obviously, there was times where it lost money and times that it made money.
So that's great. We have kind of a good start. The next step that we can do is we could optimize it. So we could try different values, change the RSI or change the bar size to see which one is the best. And we could spend a lot of time doing this. So I'll kind of keep it short. But what I'm thinking, Tina, is we could try optimizing the 30 and 70 to see which ones were the best to buy and sell. And then we can actually optimize the bar size as well. So we can try 30 minutes, 60 minute, 15 minute. We can try all these different values. And it's going to give us the best one. So I think that's kind of the best plan. Do we need to explicitly declare it in the trade horizon that there's probably a way of testing variables? Yes, we do. So right now, I can what's called optimize the bar size. So I know this is kind of small. I apologize, I can't zoom in on this part. But we're going to do a walk forward optimization.
Okay, so sorry, I'll go back. An optimization is when you try every single range of values, and then it will give you the best result. And the best result is usually the highest profit, right? The problem with doing that, though, is we could optimize for all of 2020, for example, and 2021 and then start running with those. But the problem is you get what's called overfitting, right? So when you overfit data, you optimize on too much and you have no out of sample data. And I'm sure Tina, you've kind of done this with your channel or explained it a little bit. But what we want to do is we want to optimize for maybe six months, maybe a year, and then try those optimized parameters out of sample. So historically, but not for that time frame. So I'll kind of explain what's going on here. So we're going to do a walk forward optimization. And what I'm going to do is optimize for say, let's do something decent, like the last two years. So we'll do January 2019.
And yeah, I want to go to today. So we're going to optimize for two years. And then we're going to test those optimized values for all of 2021 out of sample. So meaning that once 2021 starts, we don't optimize. We use the same ones previously. And this allows us to see the potential strength in our in our strategy, right? Just so I can I understand this part. Well, we're optimizing it. What are we like what parameters are we optimizing on? Is it just a single parameter of our value? Good question. Yes. So we're going to be optimizing on the RSI values of 30 and 70 and the bar size. So there's three parameters, the 30 RSI, the entry RSI, the exit RSI, and then the bar size. Okay. So three parameters. Save anybody else. Try 30 and 67.
We might. Kudu, I didn't really understand a walk forward. Yeah, I can explain it again. So walk forward is built on top of optimization. But basically walk forward. You optimize error actually. Let me pull up an image here. I help. I think it would help you guys understand better. Yeah, here we go. Okay. Okay. So here's an example of what kind of walk forward is. So basically you have your training set, right? So it says one year here, right? And this is what the data you use that you optimize with.
Right. So you try all the RSI values. You try the bar size values. And maybe it says, all right, the best RSI is 33 and the best RSI exit is 77. So it'll find that. And then for 0.5 years, so for half a year, it will use those same values that 33 and 77 out of sample, right? And then give you the results here. And those results are kind of out of sample, meaning they haven't been optimized after the previous historic day. And we get it's more realistic. Because in real life, you have a strategy, you optimize it and then you try it to run it live, right? And when you're running it live, it's out of sample because you're not optimizing when the market's open, right? You're just kind of, you have your values and you set it. So in this example, you can see that it looks like they optimize every year and they try half a year out of sample, right? You have the dates here at the bottom. Let me know if that answers your question. So I'm just going to reiterate what you said.
Also, just to go for it, I understand. So you're in this case, we're starting off like in 2015, our day is somewhere in 2018. So we're taking that one year and we're going to optimize it there. And then we're going to test that on behalf of your after that. And that's what the out sample is. And then after that, or and then we do in sample, against you, like re-optimize it in the next period of time then. And then you do it again. Exactly. Yeah. So I have some strategies that they optimize every seven days. So the last week it will optimize and then I'll run it for a week. And then once the next week hits, it uses the previous week and so on and so forth. So in your example, it won't be that close. But you can set those parameters on how often you want to optimize and from what time period you want to. I'll answer about you. And I think you mentioned sort of reasoning for doing this is because it's more realistic. Because as you're actually going forward with it, you can't be like, let's wait a year before we optimize it again. So we're actually trying it out so that when we actually move forward,
it's the same as what we were doing previously. Exactly. It's way more realistic because when you run it live, it's all out of sample. So you need some type of testing previously before you do that. So you kind of have a trajectory of where you're going. Right? Are these a strategy kind of beating your goals and stuff like that? Got to. And the optimization that's being used is it just like common or it's like you're just going to try every single one from the first day. Yeah, it's it's there's there's two methods. But the default one is it tries every value. There's also a genetic one. But that one would just say, you know, try a batch and then take the best performance out of that patch. But the one we're using is every single value and then just giving us the best one. So everybody is anybody else having any questions? Um, um, 60 stuff. Is it using volume indicator? Uh, we're not using volume indicator here. So we can use it in future.
So right now is just our side and the, um, it was, it was our side bar size and who bar, what is it, bar length? Um, the RSI entry, RSI exit and the bar size. Got it. I'm saying, sorry, that's big. Okay, so I am going to, I think that's that. So now let's actually run the optimization here. Um, bear with me for one second. I have to make the RSI values be able to change. Alright, I am going to just answer some more questions. Um, key to, okay, awesome. Makes sense. Albert, I'm learning so much. Yay, I'm really glad. I am too. Um, BW, would there be any regression or prediction of, uh, be using authorizing RSI? So, uh, like jakelessing earlier is that, uh, right now it's just pretty much like you just
try every single combination to optimize it or the genetic method where you use one, you just pick one of a pool and then you just keep going until you find the best one. So we're not really using the like model for optimizing. Um, oh, sorry, actually, I think I may have understood your question. Oh, no, never mind. Yeah, so we're not using like a model for it right now. Um, I don't know if you actually can, I'm sure that you probably can code an optimizer. If you felt like it. Yeah, you're probably good. Um, there's some people like to build their own custom stuff, right? So they have more control of how it works. Once again, I'm using the indicator platform, which is closed source. So whatever they have, I kind of have to use. I find that it's best enough, but yeah, there's, you could try, you could build your own optimizer. One popular library that's open source in Python is called Backtrater. And that's a platform I use quite a bit as well. When clients want proprietary software.
So you could look into that and you can definitely, you know, you can see all their optimizer, their code and you can change it to how you want it. Um, Q, do you want a question? Doesn't this to finally lead to a birthfitting? Since it keeps optimizing after every year. I think that's what you walk forward is for, right? So you're trying to not fit with all the data that you have, but because you're doing it in chunks of time. So it's you're not really taking really past historical data to try to get it. Although you are still taking historical data, that's for sure. Exactly. Yeah. The walk forward, you are still optimizing, but you're trying it out of sample as well, based on, so this parameter here, I don't know if you guys can see, I know it's small, but it says test period in days. So whatever this length is, that's the out of sample. So, um, we are optimizing for 720 days, which is two years, right? And then we're going to test for, I guess, probably all of 2021, which would be, I don't know, six months, for example. So all of this here, the stuff that I'm highlighting here, where my mouse is, that's all going to be out of sample.
So it doesn't do overfitting. Cool. Anyway, I'll have questions. Random, I mean, don't know how I'm going to say it. I guess bar size and volume is related. Yeah, I think because bar size is technically, like, I guess, I'm going to call them like the volatility, right? Like the difference between the highest and the lowest and volatility is falling. So I guess it is related. Yeah. It can be. Ali, what library do you use to get the candle sticks? So this is an indicator. This is a separate closed source platform. So it's kind of, you know, their platform. If we're talking about Tina's bot, it doesn't draw candle sticks. Right now, if you want to use a library that does, I would recommend looking at Backtrater to do that. That's an open source free Python library to do that. But this, this is a separate platform what you're seeing right now. This Ninja Trader, it's a separate closed source platform.
And we're using this to backtest because it's fast, it's quick. And for us to build a back testing solution for Tina, would take quite a bit of time. So trying to keep it short here. I think we're good to move on. All right. So let's run this optimization and then we'll plug in the values for Tina's bot. So on the right here, Oh, sorry. Is it actually possible to move your screen more? Because I realized your picture is. Oh, yeah. Yeah, my face. Yeah. Yeah, I could, I guess I could just do this. See how that looks. I'm just waiting for the streamed update. But yeah, there we go. I think people should be able to see now. And I'm definitely going to subscribe to this guy. Yeah, everybody goes to subscribe to Jake right now.
Thank you. Appreciate it. His link is in the descriptions. I will also put it in as pretty much as well. Yeah, definitely. Okay. So now now my face isn't blocking. I think we're good. Yep. So here's how we're going to optimize. So we have our parameters here. We have our RSI exit or RSI entry. And then we're actually going to optimize the bar size as well. I need to check this box to do that. Optimized data series. Okay. So we have a minimum value and a maximum value and then an increment. Okay. So it's going to take the minimum value. Try that and then use the incrementer to try the next value. And the one that gives us the most profit, essentially, that's what it's going to return. So for the entry, let's try, let's do say 20 to 50. And we'll increment by two. And then for the exit, let's try say, 50 to, I don't know, 80, and increment by two.
And then for the bar size, let's try, let's try one minute to 60 minute and maybe increase by 15. Okay. So it's going to try one 15 30. Well, actually, it's going to do 16 because it's starting at one. So I'm going to do the minimum to 15. So try 15 30 45 60. Okay. It's going to optimize for 720 days. So two years and then try for 180. So all of 2019, all of 2020, it's going to optimize. And then 2021 is all out of sample. Okay. So let's give it a run. It's going to be 2000 iterations. Are those parameters the ones that you usually use? So the RSI entry and exit? And I mean like the walk forward, like the time periods. Yeah. So there's no, I use all different values.
But yeah, mostly for walk forward, my general rule is at least two years in sample and then two years out of sample. Or sometimes I'll optimize every 30 days. But the actual back test has to be at least two years for me to be somewhat happy with it. That way you're getting different market cycles, potential crashes, potential big news items, and big kind of price changes factored in that way. You're you don't have what's called like fake alpha or a strategy. You think is good, but you don't have enough data that if you actually ran the back test for a year longer, it would have failed. But yeah, generally two years is my go to. All right, so let's see the results guys we ran it, it finished. Oh, it didn't make any trades. Okay, so that's very interesting. So it picked. There is a dip. Yeah.
Give me one second. It could have been because. Give me one second. I think it's a it's not a bug, but it's a setting I didn't enable. Sorry, guys, I think it should work now. I'm going to rerun it. Thanks, Jamie, I appreciate it. Okay, we got some results now. Okay, so I will make this a window so you can see a little bit. All right, so it ran out of sample. For all of 2021. Well, it looks like it started December 21st. Sorry, if you guys can't see, I can't zoom in on this platform, I apologize. But um, yeah, I think it's okay. Okay, so what it chose was a 62 exit and a 24 entry.
And it chose 45 as the bar size. Okay, it made, let's see the percentage gain. It made 11% year to date. So January, well, technically December 21st, 2020 to today, it made 11% return on Apple. Out of sample, this is all out of sample. So this is great. It's great news, right? Looks like it only made four trades. Ask a question. Do you mind going back to where? Oh, this, the summary. This summary over there. So total net profit is $14.33 gross profit. I'm afraid. Does this mean to this? It's not being talked into a commission and stuff, right? No, it is not. This is no commission. TD Ameritrade is commission free. But um, one setting that we should put is what's called slippage. And so yeah, it's not including commissions. Um, because I, why I didn't set it, but I think TD Ameritrade's commission free, right?
So it wouldn't affect you either way. So when it's, uh, taking the, uh, okay, I see. Thanks for bearing with me. What's slippage? Yeah, so slippage. I should explain that. So the goal with creating strategies is you want to beat them down. Beat them as much as possible. And if they still survive, then you, you're, you're very confident that it's going to do well. So slippage. Anytime you submit an order in the market, you never get filled at the best price. There's always someone ahead of you. There's always someone that's trading more quantity sizing or has a, you know, preferred, uh, fill. So you need to take an account that every time you submit an order, there's a percentage chance or there's a percentage deviation in, in you getting filled at a worse price. For example, you submit an order for Apple stock at $100. The chances of you getting filled at $100 is very low. You'll probably get, especially if it's a market order, you're probably going to get filled at $100 and $4. So $4 higher than what you thought you'd get filled that.
So that difference between $100 and $4 and $100. So that's a $4 slippage, okay? So what I like to do with, generally with stocks, it depends. But generally with the stocks, we're trading, Tina, that, you know, that was the, the, the, the liquid companies. Generally, there's like a 3 to 4 cents slippage. So down here in Inditrator, we can actually say, all right, what's the slippage? So I'm going to put three here. And what you're going to see, Tina, is the results are going to get a little bit worse, because now it's taken to account that every time you submit an order, it may not be the best fill, okay? So I'm going to rerun it and you're going to see, um, the $14 is probably going to be down to $13. But it gives you a better, it takes into account for that slippage. So that way we get more realistic results from the back test. So that kind of answered your question. Sorry, kind of went on a tangent. Yeah, that makes sense. Yeah. Yeah. So now it only did $14.9 instead of, I think it was $33.
So there was a $24.00 slippage, which is good though. That's good. Even after slippage, it's still profitable, which is great. That's fantastic. That gives you confidence that the strategy is potentially strong. We also didn't, there may be a amount of money right here. It's just trading $1.00 a size thing. That point, right? It's trading one share at a time. So I'm going to the trades menu here. So it's trading one share at a time, meaning if we, you know, averaged it out, so it's trading on average $123 per trade. So it only made four trades. And so in total, you'd be trading with $400 or $500. Okay. Questions. Kee-Doo, this bot doesn't do short sales, right? No short sales. No, only long trades.
Shorting is too risky. I think you actually did a video about that. How you don't do short trading anymore? Yeah, I still do. But I trade futures, not stocks. So there are different asset class and have different rules. But shorting stocks is generally not recommended, because your borrowing shares from the broker, and you got to pay interest if you hold overnight. So just to short it. So it's against you. So yeah, I don't recommend it. Cool. Anyways, so yeah, I'm really excited. Tina, I think this is a really good result. I mean, out of sample, it made 11% for six months. I say we plug in these values and then start kind of testing and tracking your bot. What do you think? Yeah, sounds good to me. Should we just, when you say test that, you know, we just put it into the PD1,
and then because we can't try it there, right? So I'll just have to turn on Monday. On Monday, yeah. So we'll turn on Monday and then we'll kind of, I'll shoot you a message over Discord and just see how it's going. Just to make sure it's working properly and stuff like that. But yeah, I think that's the plan. So I'm going to minimize this. Go back to Tina's bot here. And make sure the values are correct. So we got 62 exit. So let's plug that in. And what was the entry? The entry was 24. And the bar size was, I think it was 45 minute, yeah, 45 minute. It tells you in this little parentheses here. So use 45. So our bar size, I'll just hard code it to say 45. I'll comment this out.
Instead of 45. Okay. So we got 45. We got 24 and 62. I guess I'll change the comments too. Wow, that was fast. There you go. I expected it to be a lot longer for some reason. Yeah, it's pretty quick. I've streamlined things a lot. So I wanted to make sure we did the stream. I was like, all right, everything's set up and good to go. But yeah, I think there's going to be a couple days of testing. And then we'll decide how long we want to track it for. Maybe it's a week, maybe it's a month, whatever you feel most comfortable with. And then yeah, we'll kind of show the results to the people. That'd be great. I feel like it's everyone. I think it's deceptively easy the way that Jake offers. Because I was looking through some of the things and stuff. And just trying to understand. And I wanted to try to build something so much of that. And it's not as simple as it seems here.
So I think you kind of optimized it. I mean, it has the blank strategy and stuff. And put that in. I wonder if you, if we're going to do some other sort of indicator, what's another sort of strategy? How flexible do you think this code is? Yeah, so if we, this code is really messy, I'll be honest. It's not the need is. I could definitely spend some more time making it neat. But if we wanted to make another strategy, what, like, this code is definitely pretty flexible. I mean, we are, we've abstracted the part where we get data. And we get the open high-low close prices. So if we wanted to make another strategy, what I would do is say you didn't want to keep the RSI. And you wanted to do say MACD or an SMA strategy. Obviously, instead of these if statements and line 25 here, you would make it say you wanted to do MACD. You would say, you know, self.macti is equal to TA, which has all the indicators that you need,
everything in that library. And you would put say MACD in here and put in the required parameters as well as the period. And then you could, you know, use that MACD to make a strategy. So I'd say it's pretty flexible. Honestly, this is the only code you need to change. 124 to 138, everything I've highlighted here, you only have to change this code. Everything else is kind of the same is abstracted. So I'd say it's really flexible. Yeah, yeah. Yeah, it does indicate it. It's kind of changing around. Have you also looked into a price action trading? Because then we need to start, I guess, like tracking the values, really throwing lines and things like that. Yeah, absolutely. I have I have some trading system. Actually, one of my most successful trading systems recently is a grid trading system. And it literally just draws lines on the chart. And if it breaks above those lines, it will buy. If it breaks below, it will actually short. So I've done stuff for price action. I have strategies that buy on certain weekdays and they sell a week later.
So yeah, we could do that as well. We could do price action. We could do honestly, we could do anything you want. So I've seen success in all kind of basically in all forms. And it's just essentially layering those strategies together to diversify as much as possible and trading different assets as well. So you can find success anywhere honestly, as long as you just put in the work. And you do the back testing. You do out of sample. You include commissions. You include slippage. And then from there, you run it live. And sometimes it's profitable. Sometimes it's not just a matter of turning in a hot and air off essentially. Yeah, yeah, for sure. Hey, I am so excited. Thank you so much. I just just walked through with me. And in all of us, I'm sure everybody is well. You've probably learned so much from watching that. And if we try to figure ourselves, I don't know how long Jake had took you to figure this all yourself. I feel like it would take me a really long time. Yeah, it took me a while. So I wanted to speed things up for you. So we weren't kind of like spending a ton of time,
you know, setting up all the libraries and stuff like that. And that way people watching can get enough information where they learn enough and they can have the tools they need to start. But also, you know, that they're not sitting here for six hours straight what we build this thing. So I want to meet in the middle. I really want to just, you know, take that strategy. Like take your back. That's what I want to try out some other ones as well. I really, I would really like to try out some of the price action ones. I think it should actually work okay, because we have all the bars. So you just need to, okay, is this TA module good enough so that it does that for you too? I don't know about price action. So the way we did the bars, you're right, we could draw a line at the high or at the low. And then if it breaks below that, say buy, for example, TA has, I don't think it has price action in it. It just has the normal calculated indicators like RSI, SMA, MACD, that sort of thing.
I don't think it has price action. So price action we'd have to, once again, like all the code we have to change would be here. But we wouldn't, I don't think we could use a TA. We'd have to kind of build that customally where we draw the lines and we say, hey, break a little or whatever maybe. God, sure. Should we, should we listen to Kidu, back to his balance in GME just for meme sake? Where's that old one? GME for just for meme sake. Sure. Oh, why not? Let's try GameStop here. So the thing with GameStop though, here's my take. It's recent, right? So the move has already happened, like the volatility, the craziness. So, I'll run it and we'll see what it is. But because it's so recent, the chances of it happening again are extremely low, right? So we're optimizing the last two years and the last two years, GameStop has what
kind of was kind of plummeting in price because I mean, who goes to GameStop to buy games anymore, right? But let's see what the results show. So GameStop. Here's the results. The results are in $89 in profit, which is a 107% gain, which makes sense. They made three trades. Yeah, did pretty well. But once again, recently it happened, right? This is just back testing. Yes, this is out of sample, which is good. But the chances of this pattern recurring are extremely slim. But there you go, kid. There's your results. 107% profit. I think this is also just what you can, this is an example of when you can do this, and then you can get everything great. You actually do it. And you start experimenting with your real money, then not so great. Exactly, yep, exactly.
Oh, I was also curious. Like when we're, like, say we're doing this only for one one stock, right? If you want different multiple stocks, would you just build multiple ones and let them all run individually? Where is a more like a portfolio? Yeah, so what generally what I do is, so if we look at NinjaTrader, what you can do is have multiple, they call it instruments, but it's multiple symbols for one strategy. And then it's still the same strategy, but every symbol kind of has its own instance. Per se. And it would be all in my account. So I have some strategies that just trade that trade four different symbols. And with NinjaTrader, it kind of groups them together under that strategy. Now, if we did something with Python, say in your example, you're bought from scratch. With TD Ameritrade, we can stream multiple symbols at the same time. So what we would do, if we wanted to do that, you know, in this line here, line 94, we can actually comma separate the symbols if we wanted to.
So we could say stream four symbols at the same time, say all the fang stocks, right? And that way, the on-bar update would actually run individually for each symbol, and it would trade all five at the same time. Which, you know, from my diversification standpoint, is better to do that. But yeah, that's what we would do. And it would just, you know, be one share for each. So at the most, you'd have save of the fang, you'd have five stocks in your portfolio at the same time. Just trading one share each. Gotcha. I can also have logic interacting. So like if this one's in position, then, you know, you want to be able to try this and do that. Yeah, yeah, we could build some cool stuff saying, you know, if, you know, for it in a position of, I don't know, an oil stock, exomobile, you know, don't buy this or buy this kind of thing. So yeah, you could do that where you could, you know, use, they call it pear trading, but we're used one pair to influence another pair. So yeah, definitely possible. Okay. Well, I think we've covered most of everything. How will we? I think so.
I, that was a lot quicker than I thought. Like, yeah, I'm glad we were able to go out at a good pace. Yeah, so we, what did we do? We explained the TD bot. We, we coded the initial entry and exit with buying at 30, selling at 70. And then we backtested it. The results were pretty good, but then we did an optimization to get the results even better. Then I updated the code to reflect those results. And all that's left is to run it and kind of see how it does. Yep, yep. That was, um, it sounds like a lot that we actually went through. Is there anything? So okay, what do you guys want to do that? Do we want to use the remaining time and make something else? Maybe look at an indicator or any suggestions? Jake, I don't know, you're down. Yeah, I'm, I got like probably, I'm available for definitely another hour. So if they want to, uh, for down to do something else, I'm cool with that. We can look at an indicator. We can look at a new strategy.
Let us know in the chat there because that was, that was faster than I thought. Hey, yeah, subscribe to Jake's channel. Hey, Jake, getting getting some, some subs here. I know. I appreciate it guys. Thank you so much. Um, I, I hope I can provide value to you guys and kind of give you a head start with this, this, this algo trading. So that's, that's great. Um, do you have a good real-time screener to recommend? Uh, personally, I, I do not, I don't use any. What's a real-time screen? It's a way of, uh, say filtering stock. So you can do like a, say you wanted to filter stocks based on a parameter, say, uh, RSI, you want all stocks that have a current RSI of 30, it would actually filter those and, and show those results, um, in like a user interface and then you could, you know, use those stocks to influence your trades. I see, I see. Oh, I usually just go look at trading view, but recently I just, the tea, I was playing around with
the TD API looking at price history and then I just like took them and then screamed at myself. Oh, that's awesome. But it's not real time though. So I think, yeah, I haven't, I don't know. There's actually a way of doing it. Uh, I guess you can just code it like with the price history, just have like the streaming data in and then just filter yourself. Exactly. Yeah, like in, in that on bar update, we could have our own, um, where we have like an if statement that is the filter, right? Um, but I think TD that they do limit you, like you can only, I think get 100 symbols or 500 symbols at a time, like in real time, um, which kind of sucks because in the thinkorswim platform, you can get as many as you want, but they, you know, they, when you access the API, they kind of limit you because obviously they're a business and, you know, they can't have people, uh, getting gigabytes of data from them without paying right? God, yeah, yeah. They do have like the movers though, like on the TD API, you can get like the certain percentage movers. Um, or else, otherwise, because the, uh, okay, this is like kind of a new question, like an issue that I've been facing when I'm like just consistently trying to learn
how to trade is that I eventually run out of symbols that I know to trade. So I go and try to find tickers to look at. Um, and I used to do that for like screeners from trading view and also send this. Um, but it's like not the best I feel like because it's, it's very limited. It's like I just, you just specifies or are assigned like whatever and I just screen it and you just like, and then I just go to TD and I look at every single one and see what kind of this to trade. I was wondering if you have a solution for that. Yeah, it's not really efficient. So the thing is like, um, with Sc reat with scanning for stocks, right? You know, how does the scan stocks correlate with profits that you make, right? So in all the strategies I build, I trade the same stuff every time I trade the S&P, the NASDAQ, um, the oil, gold, that stuff. It's, it's always the same. So on all my back tests are the same symbols. I haven't found a way to, you know, take the scan symbols that you get for a day or the screen symbols and, and kind of correlate some type of net return with them with a strategy. It's, it's very difficult.
But generally what most people do is, um, they kind of have, they, they, they screen a stocks, but then they have sectors, right? Every company has a sector. So, um, when you get the screen stocks and you divide them by sector, so you get oil, oil stocks, your bank stocks, your tech stocks, right? After you get the scanner and then you use those to influence your trades and that way you have some type of initial diversification. So if you'd entered those three trades, at least there are different sectors. So one doesn't do too well. Hopefully the other ones are uncoilated and kind of reducing your risk. And they're hopefully winning more than the losers kind of thing. So that's where I would start. But I agree it's, it's very overwhelming getting all those screen results and then, and then trying to, uh, to trade them. It's actually very time consuming. That's why I was getting tempted by 4X actually because there's like a much more limited number of pairs. Yeah. Yeah. So I was actually thinking about doing that. Yeah. Much easier. And I think they trade a 24 hour or six days a week. So it trade quite a bit.
So you can, it, they're much more easier to run trading systems for because they trade more often and there's less kind of session closes. So it's much more a smoother process. And I trade futures which are kind of in the similar realm where they trade a longer time frame. There's less, there's less session closes. So they're better to run trading systems on because I can run them overnight and not have to worry about not being trades or stuff like that. So just 4X is a little bit riskier because it's, it's leverage. So the higher potential returns but also higher risk and with stocks, it's lower risk compared to 4X and stuff like features. It's a good start. Yeah, the hedge funds are in 4X. They're going that space and developer is so. It can be crazy. Yeah. Well, how's it for futures? Sorry. Futures, yeah, as well. Futures are leveraged as well. So basically you're putting up a small amount of money and your broker is kind of matching the rest. So you can make more than what you put in but also you could lose more and lose more than what
you put in. You could actually get them what's called a margin call where your broker is like, hey, sell your position and we're slapping a fee on you. But yeah, with the funds that they're trading everything, they're trading, they have some funds that just trade stocks. I know someone that, you know, they just, they'd go long on stocks. I have, I know some funds that trade 4X are futures. It's whatever they have some type of, you know, vision and that vision can be multiple assets or it could just be one whatever they feel. They think they can get the most kind of return on. But yeah, 4X definitely is, I think they're the highest liquid asset traded every day. So it's what most people are doing. Yeah. We have any suggestions in the chat. Yeah. Let's see what we're saying. Wow. With this work on trading view. Trading view. Yeah, good question. So trading view is a little bit of a, what I call a mixed bag.
You can build trading systems to automatically buy and sell for you with trading view with like indicators. So say in trading view, you can like draw on a chart saying, hey, buy a side blow sturdy. You can do that without coding. And then you could actually use what's called a web hook, right? And a web hook is a command that's sent over the web, usually to a URL, right, to a website. And that, in that web hook, you can customize what it says. So if that buy signal draws on the chart in trading view, you can send a web hook. And then from there, you could do something with what Tina's doing, where you have the TD Ameritrade kind of API run on the back end and submit a buy order. Now, if you want to back test it, or you can also do that in trading view with their whole, their Pinescript editor, I think it's called, but you can't submit trades through their Pinescript through their proprietary coding language. So if you want to submit trades, you have to use web hook to do that and then have kind of a custom back end on your end. All in all, it is possible to do that. It's just that you can't do it exactly in the trading
view platform. You kind of have to have your own web server on the back end handling the trades. Cool. How? Sorry, I feel like I'm just lagging a little bit. My entire thing is, are there a new comments? The last one, yeah, they're coming in. What about sentiment indicators? That's the last one I see. Let me just read that. Go ahead and answer. What about sentiment indicators? So personally, I haven't, I've delved into it a little bit. I've tried sentiment analysis with with Twitter posts and with articles as well with the news articles from like CMBC and stuff like that. But I haven't, I've only built the fundamentals where it works and it gives it a rating of, you know, one or zero. But I haven't used that for any of my real-time strategies. So, Paul, to answer your question, I haven't done enough research to see if they're successful or not.
I'm sure there's people out there that have sentiment indicators that do pretty well. Someone did have a suggestion, I think, for try volume AMA 50 sharpies. Should we do that? Volume AMA? Yeah, let's do it. I'm done. Let's do that. Should I do it this time? Yeah, I gotta get you to do it. So, I guess I should send you the new code then, right? Oh, yeah, yeah. I have, I actually alter Gerber to a little bit too. Because I thought I was going to be like typing it. But, I know, be too, actually, I'm sorry, I feel like, I jacked you and I know. No, no, not at all. Please don't apologize. Like, I thank you so much, because I was so nervous because I didn't know what was happening and I haven't coded it before. And I was like, oh my god, would it like, I just like, how do you want to see? But I feel a little better now because I watched you do it. And it's okay, we're all learning here.
So, let me send you the new file on, let me send it on your discord. Yeah, you can send it to me on discord. I just hide all my, I just hid like all my config stuff, but I guess we're not going to eat it really. So, yeah, I should have done a config file that was amateur mistake on mine. Okay, so let's send you this file here. Well, you do that. I'm going to answer Gary's question. Are women afraid to stomp on bugs and squish them flat? You know, you know, I think so. At least this woman isn't. Oh my god, that's hilarious. Okay. That was the safe out. Yeah. All right, I just sent it to you. And Kro also wants to know more about Ninja Trader. Yeah, I'm down here. I can't know more about Ninja Trader 2 after this. Yeah, sure. So, I'm not, by the way, I'm not sponsored by Ninja Trader or anything. I just,
I use them just to disclaimer out there. I'm not a, I'm not a pro VIP affiliate. So, Ninja Trader, they are two things. They are a brokerage. So, you can only for American residents, but you can trade futures or forex through them, just like any other brokerage, like TD Ameritrade or Interactive Brokers. And then number two, they also sell, they also make software to be able to automate strategies. And they allow you to back test, they allow you to optimize to run strategies live, both in real time or a paper trading account. They allow you to pull up charts, submit orders. So, it's an all in one that their software is catered to people that want to automate trading systems. And you can actually use their platform for free until you want to go live. Once you want to go live, there is a payment required. It's kind of close source from there, but they have a lot, they provide a lot of value with their platform. There is some limitations, of course, as well. They're only in C-sharp. So, they use the .NET framework. So, you have to use
C-sharp. And so, that's one of the limitations. There's also a couple others, but overall, it's a very powerful platform. And if you're looking to get into automated trading and algo trading and quant trading, definitely check out an Indutrator, they're a great start. I think I will be after this, because I am pretty interested in trying this out more. Although, I guess we could technically use the free platform if you want to do like the forward testing, in fact, this is not very... Yep, yep. We could... It's just a pain in the butt a little bit. I think if you just, because then you're like, do that, and you put it here, and then you color it. You got to like make it in two places, right? And then make sure they mimic each other. Let me share my... Awesome. Thank you. Glad I could explain very well. Crow. I'm assuming I think that's how I say You guys see the strap. The strap. Yep. I can see it.
I just scrolled back, but I wonder what it is that we're making. What is it that we're making? I think it's volume EMA. EMA is a 15. Just EMA, just EMA. Okay. Okay. Okay. Try a volume in EMA 50 strategy. And EMA. I assume that TA has all of these. TA has EMA volume. We might have to get from the bar. So if you scroll down Tina to I think it's near the bottom. Oh, we don't save the volume. We need to save it. We have these bars here. Right. So like the worst bar. I think it's up a little bit.
We can just have another variable, right? With this. Yeah, so we have self-doubt volume, right? Which is good. We initialize it, but we don't set it to what TD Ameritrade's setting to us. So we have to do two things. So number one, let's set the volume to what TD Ameritrade is sending us. So if you go back to OnBar update, near the bottom where it says update bar. This is big enough. I think you're good. I can see it. Pretty good. OnBar update. Here we go. Yeah. And then down a little bit more. So you see where it says where we append a new bar? I think it's line 142. Yeah, so if you did self.currentbar.volume.
Oh, so we only have to close price right now. Is that correct? Yeah. So we need a new line that we save the volume as well. So I'd make a new line after that. Yep. Perfect. And then set.volume is equal to I'll double check that. I'm assuming it's volume in all caps, but I'll double check the API. So we'll double check that it's volume in all caps. So we're checking that it's volume in all caps. Yep, it's volume in all caps.
So now one more thing though that we have to do. The problem is we're not so with volume volume is the amount of trades it's making per time frame, right? So we actually want to increase the volume every time we get a new bar. So what we have to do, I think we have to create a separate local variable. Or sorry, we have to increase it. So if you go back to the bottom where you wrote that code. So after print new bar and we append a current bar, we want to increase the volume by the bar volume. So line 143 where you set volume is equal to bar volume. That bar volume needs to be us and like an added volume. So I think we need to plus equal that. Can we just do that because we're just adding it to the photo volume. Yeah, I think we can. I think you're right. If we do plus equal.
Anybody on the chat? We incorrect. Let me see. So the self-ta current bar is close and then volume. We're just attending that volume. Yeah. I think we should be fine with that. Yeah. Check the chat. Anybody can we do something wrong? Be good. Yeah, I think we're good. Any free rest API to fetch real-time data besides Yahoo. Yeah, Paul, check out a alpha vantage. I'll type it in the chat. Isn't TD also having? It is, but you have to have a fun or I guess it is, yeah. You don't have to operate for just the price data. You need to create a TD account, but you don't have to fund it. So technically, TD is free as well. So you can use TD as well. Now there's an asterisk there. I think you need to be American to do that.
If you're Canadian using TD, you have to fund an account before you can use their API. You know what's fun fact, everyone. TD stands for Toronto domain. It does. Nice. What is this discrimination against your own people? I know. I love saying that too. I'll always correct someone. TD is a Toronto Dominion. I was like, oh, I didn't know that. I was like, yeah. Seriously, this is ridiculous. Come on, TD. Get your shit to come. Yeah, come together. I'm Canadian, so that's why I have so much pride in it. Me too. Funny. That's why we say it, right? Because we got to let people know we got to say, hey, it's Toronto Dominion. We can do line, keep a simple code readability. I think this is pretty readable if we're just adding like that. Instead of creating a separate variable, I think this is okay.
Okay. Yeah. It's like it's adding to the volume. Yeah. Okay. I'm going to do it your style. Yeah. So what? Yeah, whatever you want to do. So I'm just thinking here, Tina, that line, you see where we build real time bar 149? Yes. I think it has to be down there because that's outside the if statement. So that if statement, remember, it only runs every 45 minutes right now. But we want to increase the volume, right? And then once that 45 minute mark hits, that's what we said it to. So yeah, yeah, paste it down there. So wait, this is like if self-accommod open is equal to zero. Correct. Is equal to block. Sorry, just trying to understand. Sure. I'll try and explain it a little bit. So we're saying if it's equal to zero,
we want to set the open price because there's a new bar object created. And we create a new bar object every time the minute closes. So if it's 45, once that 45 minute mark hits, we create a new bar object. So technically open is set to zero, highs, set to zero, and stuff like that because we've created a new blank object. So with the volume, we don't need to check that because we always want to append to it. But something like the open price, we only want to set once, right? Because the open price is, okay, what did the bar open at? Never set it again until the next bar. So I think that's where we want the code, right? We add the volume. And then we're good because it'll append the volume as we get new data. And then once the minute closes, it'll be that total sum of the volume. And then we just create a new bar object, meaning the volume gets set back to zero. Okay, so I think in that case, we can just the stuff over here. We can just comment this part out and make it into the, yeah, me. Yeah.
What was it again? Followed right? Volume. Yeah. So I just comment. So we need to actually one two, I mean fifty are a close. So did I make a you many very likely, two? Not sure which function it is. Yeah, TA dot, it might be momentum, try, try dot momentum. I don't think it's in momentum. It's probably in, I'll check for you. It would be like, it would say exponential moving average because that's like the full name.
So it would be T A dot. That's going to tell me. Oh, cool. They have pattern recognition too. Really? Yeah. Yeah, me. Oh, it's an, it's an overlap. So try typing T A dot overlap. We didn't. Oh, you put it all in T. I'm not sure. My fault.
No, it doesn't work. It should be out of completing. It's called the last study. No, the module is called overlap. I just don't know why it's not. It's T A dot. Yeah. Because we import it all. Yeah. We can just try it. We can try it. Yeah. And then we run out of Monday. We'll see. It is overlap. So I actually try it. You could try running the Python file and see if it, um,
they can find overlap just to confirm. Okay. So I actually have a new view before. How do I? Have I run it? Top right. See that I think the green play button. It's like my shares. There's I can't. Try that. Yeah. No reason. No reason. I think that's because the market's closed. But I'm assuming it worked because it would have said, oh, cannot find overlap from T A. So I think we're good. Okay. So something amazing. Over. Dot. EMA.
I think it might be. All I'm just playing out the documents here. If I can find it. I think it's a good. Good. And it. And it. Pie. Now this is true. I put it in. Right. We are. We're in the trenches here. This is what it really looks like. Like no idea what it is. Look up everything. So when people ask me. I think it's like, like, I think it's like, I think it's really good. I think it's really good. You know, I never know how to code emotions, like, you know, stuff. But like, you know, this is really what it's like. So. Oh, there we go. No, it's not overlap. I'm a dummy.
I was looking at the wrong library the whole time. I was looking at T.A. Dash lib, not T.A. I was looking at it. I was looking at it. Was you. Respect. I'm coming on the chat. I was looking at it. Always out from you. I was just looking it up. But I just copied it here today. Turned out you're a indicator. So yeah. I have to be it. It once appendus. fill in a true. Um, I think he used the same one self-thought closer. The close price, yeah. It's already in the appendix. Put in the put in the print, too. So that way when we test it tomorrow, it will make sure prints. Yeah.
I'll check the chat while you're doing that. I'm just going to go back to the chat. Feeling actual coding vibes right now. Five minutes searching, one minute typing. How's it going, David? Hi, I'm new here. Can you tell me what you were doing? Uh, Mohammed, we're building a trading bot. So to automatically trade in the stock market for us. Where do you find the documentation for the API data? Um, for I'm assuming, Crow, you're, you're referring to TD Ameritrade. I will link it in the chat. I'm not sure.
I want to I'm ready here is for the strategy. I think he like basically price is greater than the way for me. I'm going to buy sure like that. Any input from the chat. Yeah, if you guys, yeah, if there's, if you have any suggestions for the strategy, type it in the chat. I'm assuming you're actually not in the position, you try to buy it again, it would just throw it or it would just buy another one. Um, technically, it would buy another one if they're, so if it submits a buy order, we immediately, uh, you know, change the Boolean to true. So I think it would be impossible for it to buy again, unless. I guess if you restarted the application while you're in a position, but because we're setting a Boolean, I think it would be impossible, right with that, that uncheck statement.
That's scary. What do you forgot? Yeah, so what I'd recommend what we could do is check your current positions to see if you're in that stock already. And if the symbol is the same of what you submitted, uh, don't submit a buy order. Yeah, he's a better way of just making sure that you don't forget to check. Yeah. Let's just go through this for now though. I think you guys are all extra pairs of eyes. Make sure I don't plug my account. Okay, so any objections in the chat, I have any chats. Um, Vio Nub is saying if 50 moving average is greater than 200 by. Okay, we can do that. That's the golden cross. Well, this is not even I wrote 14. I mean, you can do 50. Yeah, 50. Yeah. Uh, we can do that. What do you think?
Yeah, we could do two EMAs. We get up to variables of 50 in a 200. Yeah. Okay, so we can use variable up here. EMA. Oh, wait, I didn't, I needed to initiate the slides. Right. Because this is. Wait. You initiated it. I'm not making it. I'm just making it. Yeah, so what the, um, what the, the TA dot trend and EMA indicator. That take. So I think that depends the list in the constructor. So that does it for you because, um, we have a panda series with a close array online 127. Of all the previous close prices. And then we pass that in. And then we pass that in into the EMA indicators constructor.
And that way it will append the values. Uh, I see. Because that close array is getting bigger each time because a new. Uh, close prices being added to it. So really use a recalculate all of it. I see that we just recalculate it every time. Exactly. Okay. So if price is greater than half price, if EMA 50 is greater than half price, if you're going to get a higher rate of, if you're going to get a higher rate of, um, EMA 50 is greater than. 200, and we're not in position. We are not in position. Then we have. So. So. So. There's. Oh. It's a list. So we have to do. We have to check. We need to do like a cross check, right? So we check the. Not the latest index, but the one before it. If it's so if two indexes back it's below 200 and then the last one is now greater than 200
Does that make sense? Right, can you say that again? So we have two EMAs there lists right? Yeah, so you want to check that I Yeah, I guess we I guess We just check so what are returns here is a list with the last value right? Could we just check the last value? Yeah, yeah, you're right. Um Trying to do a big brain moment, but it just not needed See that's a poem we came and checked because You know, we we don't actually know until we run it if we miss exactly. Yeah, so tomorrow is gonna be testing day I just call you just for moral support Oh, I'll be you're all beer So in greater I Didn't know that minus ones the last one I was using Len Length oh this yeah
Yeah, I'm not a python pro yet You know, I actually know Java better than Python. It's my 30 30 secret don't hold on. Oh, yeah, I'll keep it safe You and a hunter or so people watching So So I'm actually fine like the digitator because it's in just a sharp It's actually I think C sharp is quite similar to A few Java from when I was being a last time. So I was actually like pretty comfortable with that Yeah, they go hand in hand And non-position see what I did there. I forgot that part busted Busted not in position yet. So it's that line you guys My blood pressure is running like going higher Okay, then we want to submit a buy order so I think I can just do what you have here um And then making position in true
All right And then should we so what should we want to be thought should we just solve when it's The other way around Yeah, we could so when it crosses below so when E may 50 is less than E may 200 Kiddie says Tina you should be ashamed for being a Java pro Hey, at least I'm not a JavaScript Hey, whoa there whoa there whoa there. I love JavaScript really you love JavaScript. Oh my god. I eat JavaScript I've used no JS before I have I have I I'm okay my probably JavaScript but there's just like too many brackets. I really dislike that You can no longer be friends. I'm sorry Java school You threw me under the bus there I didn't you do web development. I didn't know you did any web style yeah Well, I built some of my some like my clients work they wanted on the web so we uh
I've been using Python mainly I'll be honest um But in a previous life I did a lot of web development and no JS was my go-to And then some of the websites I have it's a no JS so I did not know that I have really offended Jake Team JavaScript You should watch my video um where I'm like I learned JavaScript in three hours that's why I take JavaScript Hi, I'm definitely gonna watch it after this in comment Be like yeah now now you like JavaScript don't you Um, yeah, so sell market and then the if statement I think it needs and in position Houch JavaScript's a Titan you can't disrespect it that's right Navine That's I'm greatly offended the people JavaScript is a new Java facts Stop! No, okay farewell friends goodbye goodbye we're leaving now
Oh, man You know what I'm gonna stay I'm gonna stay something very controversial here all right you guys ready I would rather sit there and manipulate pointers in C than do JavaScript What And I can't take the seat There's a difference between Java and JavaScript emoji Yes, there is a difference yeah Okay So is that is that good? My extra personalized Okay, so if self Can you scroll up a bit so the first ones in there? Is greater than and then if it's less than equal to any in position Cell market self-symbol Smit a cell order so yeah Cell order yeah um yeah looks good to me
EMA 50 TA trend Now the dot EMA indicator is weird Because when I did the RSI all I to do is TA. Momentum. RSI Um But I guess maybe there's like an alias of how It works EMA indicator because yeah, I see it Okay Whatever it is Yeah, so line 131 31 it just weird that it it auto completed until to EMA indicator instead of just dot EMA Oh But it says it's yeah, okay, I guess it's fine. Maybe there's two ways of writing it you can either write Like what I did I just the lowercase RSI and it worked, but I guess EMA indicator also works or like maybe there's two ways of running the constructor So I guess we're fine other than that. I think we're good Yeah, I'm looking at the documentation for EMA indicator and that's what it says
All right, because I just caught I actually it wasn't auto completed. I copy paste it directly from the documentation Okay, that's how yeah, I trust you then if you're doing that Uh, don't trust me Let's see you know, oh, okay, you know what it is Uh, it's a good so it's EMA indicator It actually calls that so this is an object Okay, so I think what I actually want is EMA like what I want is Yeah, actually nice catch Although I don't think I would have lost my memory in this case. I think it would have just not worked No, yeah, I would have just not uh This is stop there What it is let me just double chat Um, maybe you can Double chat with me I think it's p a dot trend Rid So it closed window and fill and a
Yeah, so that was the constructor first you can actually So wait wait, so you that's interesting so you make a oh, hey, I see so this is a function and it calls that directly So that's an actually an object Um, an EMA indicator object Correct. Yeah, and then what's you calling the function it returns a panda series? Yeah So panda data series I think yeah Um, wait actually is that what we want if we're doing a data series it's not a bit straight so Can we still index it like this I think you're right I'll just do what you do Let me just do what you're doing here. That's what yeah try let's try just dot eMA and then tomorrow when we test it We'll see if it prints dot me sorry Oh you just like you need just leave it and then Yeah, so leave it but line 131 31
T.A. trend just do dot eMA Oh, no, no, sorry. I wasn't talking about that part. I was talking about like this part you know how Uh, because whatever returns is that it's a panda series, right? Correct So I don't know if you can index it with negative one if you're doing a series I know you can do that list. I don't know if you can do that. Is there anyone know what does anyone try that out on their terminal I guess I can write Python pros. We need you right now. Yeah, I need you to arrest you don't don't remember I can't blame my command off and just try it out And for pandas Well, I can't even try it out Apparently, I'm not cautious my computer Because oh, no, I mean like can someone just try out See if you can index a panda series with a negative one
Tino one JavaScript's hero Ha How is this related to JavaScript? Yeah I don't know Do you have any recommendation about trailing stop loss implementation? Um, I would say Paul tried out see you know backtests that see if it if trailing stops give you better results Sometimes it works. Sometimes they don't just depends So we're trying to see if we can index a panda data series Negative one Because we're like I said, I can just copy what you did For now, yeah, I think Because I yeah, I tried opening up a terminal to do it, but that just crashes my computer I guess I'm trying to do a live stream and code at the same time Yeah, let me just just to be safe. We can always change that later Okay, let me just
One of your Cool, okay, um, and we wanted to do ball as well, right? What what about ball we wanted to do? Yeah, so this strategy is random strategies So random Oh, here we go here here's to what he says so I think we're doing that cross over where the 50 is above the 200 and He's saying store the last seven bars volume in an array If the last bar volume is relatively bigger And the 50 EMAs is below open a bi position It what All right random I need you to explain the strategy in one message I think what he's saying is
um The volume has to be like x percent bigger Then maybe the average and that EMA needs to be above So So I think we'll have a variable so we're storing the volume right? So we'll have a variable saying minimum volume for example and the volume needs to be above that minimum volume In addition to this EMA thing for it to buy so we have kind of two layered if statements but Random is that is that cool with you? I don't know if he's even here. It's been a while back This is random strategy essentially he's Yeah, we're doing yours try to hear and I don't think he so I hope I hope he didn't just leave Yeah Okay, so why aren't you wasn't even aware? And then it's like you know on Mondays like random what
Um okay, so I'm gonna write that down so my understanding so we take that volume so seven day volume so past seven day volume Uh, and get the minimum right so we get the minimum that and If today's volume is greater than minimum volume I think it's just the seven bars so the last seven If if it's greater than the minimum But wait the minimum from one um ever I guess ever yeah um so we yeah we could do We could either get the lowest value of the the past seven bars or we could just have a separate variable that says okay This is the minimum volume it needs to be I don't even do that. I just have an update or we have like gets the um Yeah, yeah, we're already already saving the volume right And yes, so volume we should why don't we just get like uh
I'll just make a minimum in here sure Do I need to actually Uh Yeah, I think so I think that's the easiest way And she's took that to No No, what's uh is it what's there's like a max there's a way of being like max number um or what it is This is due to the coding coding skills there Learning from the best Please again Not financial advice we don't know what we're doing Don't do what we're doing We're we're just teaching How to code I don't even know how to do that yeah, and that's a little if you have this stage Okay, so if um and not in position Yep In Python, I don't think you can even do that I think yes
Uh, oh I'm learning something new from you every day Tina I don't even know that's true I don't remember I'm pretty sure you can't just split it by line. I think you have to do that Okay, so 70 volume getting minimum um Do we store we do store volume right what was it called? Yeah, it's in our current bar object Okay, so self-doll volume um Okay, so we want to get if self-doll volume is greater No less no greater greater that um Min vol self-doll yeah um Then we can do that and then What was selling do we care? Um, yeah selling just leave it because we wanted to sell like relatively Not quickly, but you know the volume might not match up when we're going to sell um
So but uh going back to line 140 I don't think it's self-doll volume. I believe it's um is in itself dot current bar Uh, 40 Yeah, I think it's self-doll current bar dot volume unless we I don't think we have a volume variable for the bot class. Yeah Okay, and then we just need to um get So we have to be selling them in fall Mm-hmm Um, we should be getting that doing that when we actually get the bottom right Yeah, I think so Yeah, let's do that So if oh, by the way, I thought you don't need to have parentheses What's that you don't need to have parentheses Oh, okay, when you do the if statements
I gotta start writing these down No, it's all good the words. It's just like you don't have to If um sign up for tina's class here in python. No, don't. I don't know what I'm doing What do you mainly go? What's your main language? Java, right? No, no, so It's like a complex SQL and Python sometimes are because I know that I do data science I don't really work with like like classes and my object oriented stuff as much anymore So it's more just like write script get it to work and I just do whatever is easiest Which is usually a combo of SQL and Python, but I use like it's like pad doesn't stop so it's actually very different from based Although this is fun, you know, I missed doing this Um, so bar If self-doc current Oh, no, we're actually append me. So actually we want is if bar volume
I think yes, yeah, bar volume is less than Now, Vien says parentheses help in debug true maybe I guess if you have a breakpoint, maybe if you don't have it I don't know, maybe it doesn't show the values, okay, so if bar volume is less than the min volume set it Uh, what was the thing about seven days? Oh, we only want it for seven days. Oh Or seven bars. I don't think we want to do days. So I guess we have to reset it every If the if the current bars divisible by seven if it's index is divisible by seven we need to reset min volume Uh I mean If the current bars
You see where you append it. I think line line 172 where you append it Oh, yeah, it's divisible up by seven. We have to reset min vol back to nine like the big number that you had Wait, sorry, self the bars Isn't it? Isn't this like continuously appending though? Yeah, exactly. Oh, I see we made oh Yeah, every bar close it depends a new bar to the ourselves bars So Wait, sorry, you're saying like so if it's greater if it's divisible by seven. Oh Because yeah, every then every seventh bar Because it right now it's going to be the lowest volume of all time Right, so eventually it would never trade But we don't okay, so if you're resetting it Yeah We have to take like we don't want to just go back to the human right because then we're only wanted to be like a moving average
Yeah, that would be smoother um Um Isn't there a function in Python that we could say Isn't there like a min function that we could say min min self dot bars and then seven which would get the minimum of every seven bars Yes, I believe so Or maybe you know Because our our self dot bars isn't a yeah, isn't there min yeah, and then So you're saying we should do min self dot bars Yeah, and then is there parameter that we can say seven So it's I'll check it out Sorry, I'm waiting on you for this Man returns the lowest value or the item with the lowest value in a iterable We can do something Oh, here we go Oh, here we go yeah
Just checking Yeah, you can put in a list in there and it will So right now it would get the the smallest value in the whole list If we did min dot self bars Yeah, so can't we um you know how you did your minus one can you do like minus seven which would be the last seven bars So self dot bars and then um Square braces and then can't you do like minus seven or is it colon yeah Uh, this is a list right yeah I think This is If I'm trying to remember Python indexing was I think this is yeah, it looks right to me. Yeah, there's semi colon with the minus seven yeah
So let us know in the chat guys is that correct The linear you guys we literally can't test it until the market opens so we're kind of like This is probably crack who knows I think it's right Okay, so we get the minimum of those seven and We can just do Just send me involved to it I can actually replace that right So yeah, actually um, so we're setting the minimum volume here and This is more correct to me This is a little bit too really. Oh, yeah Seven minutes. Okay, we're far volume is less than self-involve Okay, so we're setting in here and then we're going to set it to a minimum of those seven Yeah, so I don't think we need lines 185 and six we don't need because we're already setting it to the last seven Yeah, yeah, that's I think that's
Yeah, because then we're just doing like self-involve just getting the Yeah, I think this is yeah Okay, cool Wait, self-help bars. What was bars again? Bars is our list of bars So we actually want the bar volume, right? Oh, yeah, correct. Yeah Wait, but no you need to do dot volume because it's It's not a um Is that dictionary? I don't know well so bars the list is it? It's bars of this yeah bars is a list self dot bars is a list. Okay, and we want the volume We Because that's bar Yeah, it's from TD Ameritrade like the real-time data and then bars is like historically the list of bars I see actually so self thought so from that list we want Those bars and then we want to get only the volume so yeah
This is how it works. I don't remember. Oh, no, I don't think so I think it's so that that quote volume is Can't be used in self dot bars because um You know how we say above on line 183 self dot current bar dot volume, right? And then we append that current bar object to our bars, which is 172 So I think We need to get the last seven bars, but the volume of those Last time yeah I don't remember that you could do some I don't remember this this actually like I'm gonna need it. I still I won't remember how to do that Yeah, I don't know yeah I'm gonna I'm gonna try it on my end. I'm just gonna make a simplest here and uh Like throwing some objects Oh
Did I use a semicolon no, I use the colon use a Yeah, I use the colon Um Yeah, if you guys want to help as well, please um do help help us like try out these different things as well. We are literally doing it on the fly Uh negative seven included negative one I think the negative seven to negative one negative one goes all the way to the end. So it's like The past seven ones although it might be negative six actually Hmm Let me see It goes all the way to there. No, it is it is it is it's negative seven. Yeah, because it's excluding negative once So it goes all the way to zero. Yeah, so it is negative seven to negative one
Feel no just say no and all your coding talk has helped motivate me and finding solution to your problem with half of the password Thank you big brains I am really glad that we were able to motivate you Awesome that makes me feel so good. I'm gonna sleep. I'm gonna sleep so well tonight. Yeah, say it soon Okay Sebi my internet disappointing me again. Oh, oh no Eat some pantanes. You'll you'll be fine. Oh, and Jake just contacts Sebi loves panties. His favorite food pancakes Plantines like oh plantains the Not the banana that somewhat banana. I love those. I love plantains big bananas. Yeah Yeah, Sebi's favorite is steamed plantains right Sebi? I've had them I had plantain chips like fried plantain. It's really good Yeah, I love that right So how how do we do this? I'm trying um So Min volume is equal to minimum
I'm just building a simple example in my end to try to Yeah, take your time to know race. Yeah, we can't do so we can't write self.bars.volume-1 because volume is a Is a part of the current bar object, but not the list So So if I hit run, yeah, it doesn't work So I mean you do a while learn something but get them iterate through and get the last step So that's what we're gonna have to do so Yeah Yeah, because
Right now it's yeah, we could do a for loop As well just a little bit messier I guess Jake, please take everything Tina says is pure sarcasm Um, I've learned that Not a troll you guys and I know you're talking about Can you just do fire volume um Just say like if bar volume is less than self-dominable We can probably use like list comprehension for this so don't don't judge me guys I'm just gonna get it to work first um self-domin Well, it's people to bar volume Can you do that?
Let's see uh you need to say um Bar period volume because it's a it's a current bar object I know I know you're seeing oh sorry um I know you're seeing bar volume in a As a dictionary, but that's only for um stream to data Oh, yes, it needs to be bar lowercase volume. Yeah There you go and then same with the if statement as well line 189 I think that looks good. Yeah, cool. All right And I think that should be good, right? Right? Yep I think we're finally good and we use self-domin volume right above in the entry subject curve ball. Yep. Yes, and not in position
Awesome, okay cool. My hands is cracked It looks good to me. Yep, uh as a good start. So I'm interested to see if this one will do better than the other one I Guess it will be If we were to put into uh ninja trader because I guess we have to like rewrite everything right Yeah, I could put it in um Wouldn't take me that long. I can do that right now You guys down to to see Let's try it out Yeah, our tradition isn't bad at all when we're struggling. We're at 82 people watching out I was expecting like Damn these people. What are you doing? That's not bad. Yeah, yeah, thanks for bearing with us It should be calling Tina and Jake learned to code Yeah, first time coding come join us All right, so we have an e-mail Does it distract you if I'm just gonna answer people's Comments while you're doing absolutely go go for it go for it. We're good. Cool
um Polo I think they should have a design plan for code I agree we should we really should have However, we had we did not have the foresight. We did not We're all about genuine interactions here and uh sometimes you can't plan for everything you just gotta Hold on Yeah, yeah, that's I think that's we can always what we can always promise like whatever you see here It is certainly not scripted This is um as as truthful as it gets Sebi Jake please security Tina says you're sorry. No, no, no, Sebi No, no, Sebi. It's it's fine. I'm not a troll really. I'm actually a very um a genuine person. Do you not do not think so? I think I am Drew use list comprehension to build up those involvements after you think of a list and then find a middle mile of that Yes, I can certainly do that list competition lander function You know what I will do that. How about um
Let's leave it like this first. I just want to see back who works and then if it works then I'll make him to list comprehension and make the code look less ugly Sound good Uh That being says the girl first year of a JavaScript wait list comprehension lambda function says to see to girl for a See a redolus grip why why why is that weird? I don't get it isn't Do you are are there list comprehension and lambda functions? Aren't they like see based off So it's not why Doesn't that mean that I should be Wanting to use it because I like see over JavaScript. I think you JavaScript doesn't do lambda functions today I don't know Um, Sebi I don't like with JavaScript well, so uh there there you go. Sebi's on my team Okay Kiddo penises are really mean and min and max when she's emerging as pd. Not really mean that is true. I totally forgot that
Well, you know what we just reinvented the wheel here and just reinvented our own rolling min function Okay, we will I promise we'll clean up this girl After we actually get it to work. I just let's like not touch it for now and just get it to workers and then we'll we'll fix it up Uh That's true. I totally forgot about that I'll get on my popcorn ready It's not bearing I'm learning. It's very interesting. I'm really glad. I really got that you're learning that you're learning from this Navine most people like stonk most people like stonk's when I'm not sure I understand that comment um Most people like stonks when make money and don't like stonks when lose money usually I think yes Sebi meanwhile, why is my cousin wishing me mother's day? Sebi, you're everybody's mother. Oh my god. What?
Everybody's I don't even understand Wait does that have another input implication? I just literally just randomly said that I don't know what else is supposed to mean Tina, I'm gonna be honest with you. That was the funniest thing I ever heard in my life Wow That's so flattered holy crap. This needs to be part of my stand-up comedy show one day Yeah, get on um What's that comedy central All right, I'm almost done here Cool, but I take it time. It's cool. I am literally just trolling everyone now, so it's all good. You are Um Farah, the key to stream is certainly very is very very valuable. I'm glad And I'm having so much fun to Jacob earth's earth and Bach rather than coding how to trade another day could we look at data collection and analysis from our feed data
You know, I am really down for that. I don't know if Jacob if you have time or Are interested in that but I would be very interested in looking at data collection analysis because Well thing is I've been reading some some trading books and investing books and I think I'm just like a rather skeptical person Because they're like if this happens all the time you know when they just say that But I'm just like I don't know if I believe you because you didn't actually show me evidence So I like to take like data and actually like look at it myself Because I don't trust nobody No, and I want to reiterate that point that you just said I don't want to trust nobody that's that's how you should view everything especially with not only trading but like Any opinion you get online because I find now a lot there's a lot of like People will say something and it's just like you believe them right away and that's a skill in its own of like not trusting anyone And seeing it for yourself and actually seeing the data and trying to visualize it yourself. I think it's really important. So I like that, but yeah, I would say
I guess when we're looking at market data Are they referring to like actual the price data that we're getting from TD Ameritrade? Yeah, I think so I think it's looking at just looking at data analysis and just kind of verifying some of the hypothesis that we have by looking at it So instead of like just building like because right now we're building a bottom-up back testing it And that's like kind of one step before then like you if we're trying to find a strategy for example That could be a useful thing to do Absolutely, I actually I've been working on something cool. I think you guys would like this, but How I gent how I code new strategies for myself I actually have a tool I call it my AI strategy tool But it actually mines data so it mines bar data and then we'll present strategies based on the results So the the best results like basically gives me the best strategy for the mind's data that I found and it will try every indicator It will try different patterns and it's something I use commercially with my strategies and with my clients and Definitely I'd be open to do that. I guess we're we I'm almost done back testing give me a second here and then we can look into that
Yeah, that's that's really cool. So you just sorry like just understand I slightly So you just have when you're testing you struggle because you have like a collection of them and then you iterate through them and try them out Is that is that what you said? So yeah, what what it does is like it loops through so you know in the TA lib that you saw right it loops to every single indicator It tries each one it tries just buying on Mondays it tries you know different weekdays different months and then So I can say all right, give me the best strategies for 2019 It'll mine all that data try every strategy and then give me the best one and it says okay This is the best one and and that's then I from there. I would try it out of sample So yeah, it's really cool. It it mines data It chooses a strategy for me and it saves me a lot of time instead of Handcoding a strategy by scratch each time I can use this tool that I built even though I spent hundreds of hours on it It's kind of like paying in dividends now because now I can just use the two of mine strategies So it's a what a lot of funds do right they they They get their kind of quantitators to use these the software to generate strategies for them And it's something I'm trying to replicate so it's really cool and really powerful
Oh, that's really interesting and do you do like just try every single combination then at this point every combination Yeah, I run it overnight sometimes it takes like 10 hours based on how much data I'm trying to get So it tries everything everything every single combination and sometimes they take five to 10 hours depending on how much data I'm trying to mine um and how many different parameters I'm trying to do obviously If I only iterate or only increased by one each time it takes a long time but um You know, it's it's very powerful So I guess that is kind of what you know something with data science what you would do right you kind of you look at previous data and you try and generate hypotheses and and thesis is from from the data that you mind rate Yeah, yeah, so like what you're saying is a heuristic approach which is usually like the first approach to To figuring out like it's to be like building out a model and a different parameters I think there's definitely like you because With ml you can do some ways in which you can like kind of figure out what are the best combinations of things When you don't have to do it like completely heuristically
But with that being said it's not like let me just throw into this ml algorithm and it's just going to tell me how it's best Like it doesn't really work like that it would it would still Like as your problem space gets larger and larger I think the solution will have to start becoming an ml solution because I'm assuming you're also iterating with each indicator Are you also very like changing the number of days and things like that because if you are then that becomes like a huge Combination grade yeah, the combinations can be massive. I I have an option where I can say hey I need two combinations of indicators where you know I want you to try all these indicators and then try all these and they have to work in kind of parallel and There's so many options right if you have an rsi and ema there's so many values you could try Um, and then on top of that, they're still like okay What if you we only traded in a mondays or what if we only traded in februaries every year? What would it do? Um, so you can look into like I was thinking maybe you're looking to a What about like the other way around like you have the strategy that works for one stock and then you use a model to determine other stocks
There's similar to that stock Yeah, that's a really good idea. Holy crap um And finding the correlations to that's something I want to get into as well because I generate strategies and Sometimes I want multiple, but I want them to be uncorrelated so my risk is reduced um, so Hmm, that's right. I might be an interesting way because then it's kind of like a I guess you can call like a look a like model Like you're trying to find like things that look like that one and you can just run a correlation Between them Yeah, yeah, a cori I was watching a youtube video yesterday on covariance and correlation just learning more about it Anyways, I digress I have the back test done. Do you want to see it? Yes. Yes. Yes. Yes. I do So it's It's it's pretty good not gonna lie once again. This is only an apple stock. So you know Could be overfitted, but I think so far it's a great start. Oh, it's two one share So we have our two EMAs here. They're both yellow which isn't recommended, but um
What's yours? Sorry. Oh, you mean the colors is literally yellow. Yeah, I know both the same. Yeah um So we'll buy if one of them is greater than the other the 50 is greater than the other and the minimum volume It's greater than the last seven bars of minimum volume. So This isn't a great great example because it buys almost immediately, but I want to find an example where it doesn't buy right away and it kind of waits a bit um So it's still buying right away there I I want to make sure the minimum volume is working as we intended I don't think it's not because I don't think it is because it's you can see it's buying as soon as it crosses over So Bye So I might have to fix that up But even without the minimum volume it does really well anyways, so let's look at the return. So trading one share of apple for This is
Three years since 2019 Did 200% so that's that's pretty solid can't complain about that Um So we could do a walk forward analysis as well um, which actually I'd like to do Yeah, that's pretty impressive. It was very good. Yeah nice strategy Yeah, so I'm just going to do a walk forward on the bar size because um I I had an editing code the um EMA values as parameters yet. So let's do bar size. Let's try the same ones 15 to 60 and we'll increase by 15 minute Yep on Apple stock we're going to try for two years Summer and 20 days and then our test period will be 180 So that way you get some out of sample Let's run it And see what we get. I'm excited doing that. I'm gonna go to the bathroom really quick go for it
Go for it. I'll handle things from here right now um Data analysis on trading go So Wow, it wasn't profitable out of sample Interesting It lost 2.7% Interesting See that's not good. It wasn't even profitable. I mean we could try more parameters We could say um Let's say let's try um say a minimum of 15 we could increase to 200 Let's try that
The return percentage was negative 2.7% after the walk forward optimization I Thought it would do better. What do we do weird it was red it wasn't profitable Which was weird sorry I didn't have my earphone. Can you say that? Okay. It's so good. Uh, it's bad. It's not profitable Negative 3% Uh after you did the walk forward after the walk forward. Yeah, so it's so the initial back test that showed you Tina was just 45 minutes Like no optimization just trading on 45 minutes and it did really well But after the walk forward it's not profitable Um with that being said. I mean apple uh, I mean it's only six months worth of data, but yeah not Not too profitable now. I want to um let me fix this volume thing You see how it's buying as soon as it crosses over It should be buying also when the minimum when it's greater than the minimum volume and I don't think that's working right now
So I think that's a bug on my end So give me one second. I'm gonna try and uh fix it here and why it's not working Because maybe that's why it's not profitable could be other reasons as well Uh Minimum The volume is greater than the last seven bars You Okay, let's see if that
Let's see if that works Okay Yes, still no dice interesting Is it doing the correct thing now It is yep So now it's has to be greater than the minimum volume of the last seven bars So you can see this bias signal here see how even though across above here It's a lot to wait a bit because that minimum volume wasn't hitting It's interesting Huh, that's pretty interesting so if you walk forward actually made it worse It made it worse Yep Yeah, so if I put this back to just a back test and we did 45 minute
Actually, no, I'm curious. Let's try 45 minute, but the same length So for 2021 we'll try 45 minute it run Is it profitable? No, yeah, it was still wasn't profitable at all Even with 45 minutes so how many times did it buy it? It bought Three times First trade So yeah, I only had one losing trade, but it was negative 3.5 percent so it was so much that it You know, cause it to not be profitable. So that's very interesting Here's to see like what the volume interaction there might be that our volumes are Not like for the losing one Try are you saying like try changing the period instead of seven? Yeah, I'm just curious what the volume interaction was and I was also thinking we might just If we can there must be some logic that we can do to sell before the
What is it called the report Porter yeah, what is client just literally forgot it's called the EMA No, no, like the Erning's report because I feel like the huge rock that happened Yeah, you're right Um, well look at like look at this buy here like I bought here and it was up for a long time But it never sold because the EMAs didn't Crossed down until here. It was still a profitable trade, but it missed out on a lot of money Right, and I think you're right. That's when the earnings report happened recently If we go back to this trade Yeah, this is the losing one. Yep This one look it missed out on a lot of profit Because the EMAs Didn't cross down here. So here's what we're gonna do. We're gonna do the right thing We're gonna we're gonna make the EMAs parameters that we can optimize on
Because once again like what look we found in the RSI one right the The 30 and 70 weren't the best so maybe the five the 15 200 aren't the best So I'll make the EMAs parameters again, and let's do another walk forward optimization is see if we can uh Get some some decent returns So just give me one second here So Okay, so we got our 5200 You
Yeah, you know using a smaller EMA range Yeah, I think after looking at uh optimizing those parameters. I think that might be the thing we're Not having a 50 day because the issue with having my circular long periods I don't even miss out on a lot of the The class always I think Yep, I think that's the issue. So I'm gonna go back to walk forward. So now I have an EMA long and an EMA short variable I'll bring this down. I know my face is in the way um So for the EMA short let's try from 20 to 50 And we'll say increased by two and then for the EMA long Um, let's do 100 to 200 and increased by two And then our third parameter will of course be the uh the bar size as well So I'll try 15 to 60 minute increased by 15
Uh, should update. Okay, and then we have two years of Optimization and then six months out of sample Let's do that Okay, 720 180 awesome. Let's say run and see what we get Ideally, we want to be able to catch all of the swings because where else Actually, yeah, where else the problem with the crossover just like that is like it doesn't take into account where it is a cost of Great, that would correct. Yeah It was holding too long Interesting. It's still Still not profitable Negative 4.2 percent 4.12 percent Um, so it chose 126 and 22 on 60 minute So it got a good trade there that one was green Yeah, it's just not not doing too hot on apple
We could try a different symbol as well um we could introduce more parameters But I don't think so apple. I don't know if it's been performing pretty well. Maybe that's why it could be that in general, but uh Yeah, still not profitable results um let's try I don't know pick a stock. Tina. What do you think? Jimmy um Let's pick snap try snap chat. Let's see what we get Okay Okay, cuz yeah, sometimes like one a takeer or a symbol won't do well, right? Because Even though if the strategy is optimized if you know that company's not performing and it's just going down and value You're not gonna great get good returns um, you know in most cases I feel like this kind of set of My hypothesis is that it should be where you don't have like huge
Like it should be like a pretty calm stock because then the crossover has happened, right? Yeah, it's not because of like huge fluctuations from from like one time period Exactly. Yeah, snapchat did worse Okay, what's a really calm stock? um One that's been doing really well right now is ex-on-mobile the And uh, let's see other one The bank company not Wells Fargo Goldman Sachs has been killing it recently too. So if I do XOM which is ex-on-mobile Uh, they're in a way of company They are killing it right now. So I know I know it would do well And it doesn't move that often Yeah, tech has hit it like recently tech has been hit a lot I think a lot of investors have been selling their positions because You know last year the gains were so big because of what happened right to come back Now it's kind of overinflated and people are selling their positions Yeah
And there was also like a That little Blip like the big With my little blip upwards Uh, I think a few months ago. So I think it's just kind of like reverting That's Exactly. Yep. Yeah. So I feel like tech moves as an industry more closely than others I don't know that's just like me watching tech. It just seems like one of the tech companies has something everybody else just Yeah, tech is the most volatile for sure. So Um, when the upswings are they're great and when the downswings, you know, they're pretty hard compared to Stuff like banks and oil and stuff like that. So yeah Examobile exoam did really well 34% return Yeah with your strategy Kedu and of being Tesla Amazon and NFNVST We can try those two sure. I'll try those. Yeah Tesla Be a good hypothesis like things that I don't are are more stable throughout
This could be a good This is this strategy is good for kind of buying and holding for you know number of days or weeks on stocks that are less volatile and it'd be cool to do like a I don't know how you would like visualize that but to find the volatility of a company and then compare that with this strategy's return performance Right and see if there's a correlation between Okay, if there's a lower volatility this strategy makes more profit right based on results based on like trade performance That'd be cool to see Yeah, you can just get you can just find a correlation between the two variables And then just see what the correlation is there I think that's should be pretty easy to do Mm-hmm. Yeah, so Tesla did good did return 10% year-to-date Which is really good um the other one was Amazon Amazon You Any other suggestions? Yeah, let us know in the chat. Stocks you want to try oops
After we get the quote to run like we can also just like post the the TV Ameritrade line. We can just Open source people can play around with it too Oh Yeah, but all Ninja Trader though. I think it is Hard Because the Ninja Trader is just you know you can actually do this Mm-hmm Center deviation on the price smaller center deviation is a brilliant strategy Uh, I think we in that case we could just do volunteer bands right if we're doing their deviation base was it Mm-hmm I think was born to it was born to your bands and kept our channels. I think it's born to your bands. We want to do standard deviation Yeah, no Yeah, there's multiple ways you could do it um Yeah, Bollinger brands are are one indicator that shows a deviation in price um Okay, so yeah, Amazon was negative 3% That was for I think
Naveenia and then nvst Yeah Just so what exactly is happening when you run the different software will really make that no race no race Just closely around now. We we made another strategy, which was suggested by random Who I think I've left but it's this strategy Where we're looking at crossovers between ema like two different ema's And they're also looking at volume so we only buy if the volume is greater than the minimum of the seven days prior to that So um, we're just trying out different stocks to see like what is a good Stock to run this strategy with and our current working hypothesis is that probably stocks are less volatile Um, are better for this strategy because the crossovers would be happening at like times in which you know Like you don't have a huge drops that will make the crossover just randomly happen like that and we're just trying out different Sox at the bar suggestion I hope that way Uh, so nvst did 21% hey good pick via nube. Yeah, good pick
Uh, crisp is crisp crisper CRSP is it crispy? Uh, let's see The center Uh, yeah, I don't know either Yeah, crisper therapeutics. Oh crisper I'm pretty done. I feel like I'm just partial to crisper in general Although it's been a bit down Yeah, it has Let's see how it does so far the best performer I think was I think it was Exxon mobile xlm. Yeah Thanks picks Kiddo I have to go it's 1127 pm and have classes tomorrow. Face stream as always. Hey, thanks so much for joining and thanks for the uh for the Input as well for testing different stocks. Hope it was useful. I think Jake you and I probably where we'll be heading out as well Right in just the three more minutes. Yeah, probably soon. Yep. Yeah, so crisper note not good negative 30%
um All right, let's try cciv and then we'll try alibaba and I think we'll Stop there because I think people are just gonna keep saying hey try Yeah Mucha suki I'm late It's okay Okay, feel free to rewind I will be releasing the code as well So be kiddo goodnight in sweet dreams cap so many cat awards I Used really like cats. Wait Just oh cats really do you have cats? I have two You have you want to be called Oliver one's Oliver. He's an orange I don't know if he's a tabby, but he's an orange cat and he's everyone's Bob Oliver and Bob yep Interesting. I'm really interesting name your your cats have people names Yeah, I'm every pet I have I've had it's always a person name So I want to get a dog next, but I need some I need some more space before I get a tux. So it's gonna hold off um
CCIV was did incredible 200 percent I think it's workhorse They do like I want to say electric vehicles for logistics companies like FedEx or something like that But I could be wrong Yes, never mind. I was way off No, I was just a CCIV that was uh, Muhammad I want to actually see the trend of CCIV. I wonder if like it's just if it's consistent. Yes, CCIV has been Pretty consistent for like the past The amongst them is Indigreeing consistent All right, and I think the last one was Alibaba. Let's try that Which is a more I would say a more stable company for sure Don't come on. We'll just be posted as recording. Yes. Yes. They will be yes, and um I'm Probably so I'm not gonna say I would do it immediately But I will probably go um and cut out pieces of it and post the parts where it's not Jake and I
Thinking about how this work so people don't have the struggle for that Yeah, we can't highlight that that wouldn't get I wanted to do too well on YouTube Yeah, oh also Jake I think um I'll send you to recording over it as well. So you can do What you like with it, too. Yes. That'd be amazing. Thank you. Yeah I'm gonna start doing this more often the streaming. It's way better. Yeah, it's so much fun I really love it and you know if you're ever down to like just do like marking us or anything else Um, I would I would love to and hopefully it won't just be you carrying next time I'm gonna play around with it. It's been more myself Yeah, it was good. I want to do more content around this and I think uh I think we're I don't know we kind of have two skills that kind of come together um But yeah, I know you you carried the end of it. I mean you wrote that whole you mean anything um True, I just don't know how this works. That's okay Yeah Bobo was not profitable. It was rather Oh, has Bob been I guess like this Bobo cow has a text off. I really don't know
Yeah, it is they they're like It's similar to Amazon, right Um Well, they I've never used their website though, but uh I know they they're like e-commerce The high-pobuses seems to be that you need to Be trending up stable because all the text off of you tried so far. This is like terrible switching bias, but like That's what it seems like right now Yeah, so yeah, the best performer I think was cciv technically percentage wise and um XOM XMobile Tesla and then nvst and then the rest roll red so I would do personally. I would probably do it more stable stock the cciv is more volatile So I would I would do like Tesla or XOM mobile with this strategy just because they're more stable more stable stocks or they're moving less so um Basically you want you do want the highest profits possible
But there's also risk right anytime there's higher profits. There's higher risk. So you have to kind of balance out Okay, what's what's the amount maximum amount? I'm willing to lose versus my profits and kind of get that risk to return ratio So if we look at cciv for example Stick a look at it here If it will pull up there we go So you see this max drawdown parameter. It's minus 6% That means at the worst possible scenario you were down 6% of whatever you put in right So if you bought one share at whatever $28 a share you'd be down 6% from the back test if we looked at Tesla right Tesla only had a max drawdown of 1.9% so a lot lower right you were You made less return wise, but your risk was also less and if we look at XOM mobile Even a lower max drawdown at negative 1% negative 1.11 so you know, you always find that generally the higher returns You get sometimes there's a associated higher risk with that so
Personally, I would do XOM mobile because it's the lowest lowest risk stock for this case use case sorry Not financial advice Yeah, but it looks like something to analyze. Yeah, I think we can also just I mean, I'm like a stop-lost right like maybe like 1 a tr Yep, we could do a tr we could just do a percentage or like Even a dollar amount say like hey, I didn't want to lose more than five dollars, right? We could code that as well Cool, cool. I think we're good for today. Yeah, I think so yeah Yeah People I think most people in on India India time are also going about so Perfect time to attend Yeah, we don't want to keep you guys up all night. Yeah. Yeah. Thanks very much for joining This was so much fun and thank you again Jay like this was I learned so much Yeah, I had a lot of fun with this you know, this was we gotta do more of these clubs This is a lot of fun and I think just interacting with your fan base was great too
And I was surprised by how many people kind of like we're really interested in this whole trading thing So that's that's good to see I thought I was boring everyone or making everyone bored Yeah, I was just thank you everyone that joined as well like I was I didn't well I was actually expecting that many people because on this channel We don't really do this kind of stuff that much on my channel We usually just talk about like coding stuff or data science not like trading specific But I loved how much interest there was as well So thank you everyone for joining and hey caught this I caught this on camera I like let's let's do the other ways together. I would love to apply some of like the different Like different hypothesis things and maybe who combines some data science into there as well In the future. Yeah, let's do that. I'd love to do a separate video about that And see if we can use that to improve it somehow or just get some more knowledge about it Sounds good and everybody make sure if you haven't already go check out digs channel It's on the pin comment. It's also the description. He builds really cool trading box And he's also super open about like you know what how his trading box are
So I think there's just so much valuable knowledge in that and yeah, like it's just That's actually how I got into it myself. I just started watching Jake's video It was an awesome girl. This is and then I started like you know like this this makes a lot of sense and then I got introduced to Jake from from Kenji and that's how that's how I'll start it Yes, thank you, Tina. I appreciate it. And thanks to Ken for introducing us Yeah, thank you All right, thanks again. Thank you everyone. Thanks Jake. I will see you next time. Yep. Talk soon. Talk soon
More episodes
More from Tina Huang

🐙 Lunch & Learn: Let’s Talk About OpenAI Sora (the most powerful text to video...
Tina Huang

Best ChatGPT Prompts to Learn Coding (the ULTIMATE method!) | Tina Huang
Tina Huang

How To Unlock Your Hidden Potential (pareto principle 🧠) | Tina Huang
Tina Huang

🐙 Lunch & Learn: Let's make some AI Music | Tina Huang
Tina Huang