How I Built A Technical Analyst AI Agent in n8n With No Code

Dr. Violet Howard builds a no-code AI agent in n8n that analyzes stock charts. You send a stock ticker via Telegram, the agent fetches a candlestick chart from Chart-Image API, runs it through OpenAI for initial analysis, then refines it with Claude 3.5 before sending the detailed breakdown back to you.
Chapters
Okay, we have our AI agent right here ready to go, waiting for an event in Telegram. So we're going to send off this text that asks it to analyze Apple. It's going to send that stock ticker to this tool that we created in N8N called GitChart. This tool basically takes the ticker, it gets us a chart with technical indicators on it, and then it creates a brief analysis, and then it sends that back to the agent to use Anthropic 3.5 to actually make that analysis a little more in-depth. And so right now it's creating that. We saw that we already got the chart back. In our Telegram right here, and then the analysis is also going to be sent to us in Telegram right here. We just got that back. As you can see, it's pretty in-depth. It basically breaks down candlestick analysis, current trend. The chart shows a downward trend highlighted by recent consecutive red candlesticks. Goes into a little more detail about the patterns. Doesn't appear to be any strong reverse reversal candlestick patterns like a hammer or doji currently visible. Then it breaks down the MACD, talks about the signal line, talks about the histogram, And then it goes into volume and finally support and resistance levels. Key support is seen around the $220 area where previous price consolidations have occurred, and then the recent high resistance near $260 is a significant resistance level, as you can see up here. Um, so that's super cool. And then finally, it gives us some key takeaways and interpretation. Um, we've got a bearish trend. Apple is currently in a short-term bearish trend. The consecutive red candlesticks and lack of reversal patterns suggest that this downward momentum might continue in the near term. We've got MACD confirmation. The MACD indicator confirms the bearish sentiment. We've got volume, key price levels, no immediate reversal signals, price action. And then finally it goes into, it's important to note that this analysis provides a snapshot of current market conditions but shouldn't be considered as financial advice. This isn't really a financial advisor, it's more of just giving a brief financial analysis as well as a technical analysis on whatever stock you enter in there. So I know I went over that feedback— or sorry, the analysis— really, really quick. We got the picture back, we got our analysis, but this was kind of just a quick demo before we really break into how you can build this out in your own N8N. Before we get into the breakdown of this build, I wanted to say that you're able to download this workflow for free if you'd like to. All you have to do is join my FreeSchool community. The link is down in the description. Once you get in there, you'll go to YouTube Resources, you'll click on the post associated with this video, and then you'll see you'll be able to download the workflow right here. Back in N8N, you'll, you'll click on these three dots and click import from file, and then this will pop up on your screen and you'll have it ready to go. If you're looking to take your skills with N8N a little farther and you'd like a more hands-on approach, feel free to check out my paid community. The link for that's also down in the description. As you can see, we've got a great community of other people who are also dedicated towards learning more about N8N. We've got a great classroom section as well as a calendar with 5 live calls per week. So I'd love to see you guys in these calls. And finally, if you're looking for AI consulting services or you want me and my team to help you guys deliver a certain project, then please book in a call using my website. The link for that's also down in the description. But anyways, let's get into the breakdown of this build. Okay, so as far as the actual agent itself, super, super simple build. We've only got one tool, which is the one that we created called Get Chart, where we'll break that down after we talk about this initial agent. But what's going on in here is we're communicating it with this agent through Telegram. So if I click into this trigger, you can see that it's going to be on message received. And all you need to get out of here is the Telegram chat ID, because when you're able to link that ID to your window buffer memory, you can see we use that right here. As well as when we're actually sending information back, both here and in the other workflow when we're sending that photo back into our Telegram. You need to reference that chat ID so that the node knows what, you know, where to send this actual information. So that's all we're doing as far as communication. We're using Anthropic 3.5 Claude for this case because I think that it does a lot better job actually creating like detailed analysis, content creation, the way that it formats and word stuff, I think that it's a lot better. So that's why we're using it here. And then finally, we just have the tool called GitChart. And as far as the actual prompting goes, within GitChart, we told it to call this tool to get an analysis of a requested stock. The URL that is output from this tool must be returned in a markdown format. And this is just because if you want to, if you want to chat with this thing in N8N, you need that markdown format for it to actually come through as an image rather than just the URL of the file that we're looking at. But in this case, we're just doing Telegram so we can put the URL in. But just keep in mind, based on how you want the photo to be sent from N8N to something else, based on that medium, you're going to have to play around with the way the URL comes through. So then as far as prompting within the agent to actually get it to use GitChart, very high level. We pretty much told it what its role was, understanding financial topics, and it has the ability to get technical analysis using the GitChart function. We gave it some context, some instructions. The tool. It only has one tool called Git Chart. Um, and as you can see, I gave it a few examples and some standing operating procedures, but it's pretty simple in this case because it's, um, you know, pretty much only using that one tool. But if you want to take a deeper look at that prompt, then feel free to download this template. Like I said, it's in my free school community. But now let's look at that Git and analyze chart workflow. Like I said, this is where the magic really happens. Um, one quick tip I wanted to point out is let's say you're building a workflow that's going to be called by an agent. What you can do is you don't have to call it every time to test it. You could actually pin your data in here. So for the example, we sent through Apple, and so I could come in here and I could just set the query to be Apple. That way, if I wanted to test this workflow, I could just hit test workflow and not have to go into the actual agent and chat with it. So that might just save you some time down the road. But let's go into the execution we just ran, and then we will break it down in more detail. But let's go over just a high-level approach of what's going on in this workflow real quick. So we come in through here and we get the query of Apple. And I know this is the data that was pinned, but this is live data coming through. And so this is just because we prompted the agent to say, when you're sending information to the Git Chart tool, you're only going to be sending over the ticker. And so it's able to understand what that means rather than sending over a whole query that says, can you analyze Apple? It just sent over Apple. From there, we wanted to set the actual ticker. This was just more to keep things visually appealing and organized in my mind as far as like visually seeing what each step is doing. But all we're doing is we're taking the JSON query that's coming in and just setting it to an output field called ticker. So from there, we are doing 2 HTTP requests. The first one is going to be a POST request to an API called Chart Image, and it's gonna be free. I'll show you guys how to set it up, but we're going to be sending off that POST request based on the type of chart we want and sort of like the, the ticker that's being put in. So if we click into here, we can see, you know, we've got a POST request, we've got this endpoint, we've had to set up our credentials and the content type, of course. And then we actually send over the, the body parameters of this JSON within our POST request. You can see we've got stuff like the theme, the interval, the actual symbol. And so this is the only thing that's changing every time we're sending this request is the symbol. You can see that we're putting in the exchange, which is NASDAQ colon JSON ticker. And so in this case, the JSON ticker was Apple. And so that's just going to change every time, but then everything else is going to stay consistent, as you can see. And once again, I'll show you guys how you can set this up without having to know pretty much anything about like JSON or coding, anything like that. It's going to be really simple. Finally, we're just getting this response as JSON because we want this URL. This is what we're looking for here. If we kept this response to be a file format, it's going to come back as binary. And once again, I'll show you guys all this, but if it comes back as binary, then we can't actually reference this URL. So we want to get, first of all, the URL in JSON, and then we can take that JSON into this next HTTP, which is going to be a GET. We're downloading the URL, and then you can see we're getting the chart back right here. And then now that we have it in binaries, you can see up here in this top right We're able to feed the binary into this OpenAI Analyze an Image node. Pretty much I told it its role, um, financial analyst specializing in technical analysis of stock charts. Your role is to analyze financial charts provided to you, offering comprehensive insights and technical aspects, candlestick patterns, MACD, volume, sentiment. I go into a little more detail here. Once again, I mean, I use GPT-4 to help me write this prompt, but all it's going to do is look at the image, generate kind of a brief technical analysis that it's going to send over. Um, and then when the agent actually gets it, the agent makes a better one using Anthropic. But then in here, all we're doing is we're grabbing that URL once again, sending it to our Telegram with that chat ID that I mentioned earlier. And then finally, the response. Um, so this is the actual response that we get from this tool. And as you can see, this is a bit shorter than the analysis we got here in Telegram, which was, um, as you can see, a lot more long, a lot more in-depth. And so this is what the agent gets, and it takes this to make a more in-depth analysis. But at a high level, that's what's going on here. So now let's talk about how do we actually set up these POST requests— or sorry, the one POST request and the one GET request— because really that's the most difficult part of this workflow. And still, even that is not too difficult. So you're going to go to chartimage.com, and this is what it will look like. Like I said, you can get a free API key and then you're gonna click on API Documentation. So from here, it's gonna look maybe a little confusing and overwhelming, but we're gonna break it down. It's really not too difficult. What we're gonna do is click on Base API Endpoint. And so from here, we understand that this is the endpoint we need to access, and then we can change the parameters off the end based on the type of chart, all that kind of stuff. But just remember, it's gonna be https://api.chart-image.com. Hopefully it helped that I read that out loud. Rather than just letting you guys read it. But anyways, um, so you can see there's different ways we need to authenticate. We need to see in this request that we have access to get to this service to create a chart for us. So there's authorization bearer, or there's going to be x-api-key. Um, and so the way that I'm going to show you guys how we can do this, it's going to be a lot easier than trying to read through these docs and understand what you need to set up where, because that can be very confusing. So we're going to click on TradingView Snapshot V2, and in here we can see it's similar things. This is going to be the endpoint after that base URL that we need to access. And this is just showing if you want to kind of do it manually, different parameters you can put in your header or your body. But on the right, let's just look at this because it's more, a little more natural. We've got different types of charts that we can do. So as you can see, these candlesticks, here's the MACD, the example that I just did in the demo. But let's say we wanted to do this chart. All we would do is we'd have to see the request example so we could copy this right here because it's a curl. and then we can go back into this workflow. Let's say we're creating an HTTP request, import curl, paste the curl command in there, and then we just want to get rid of this top line that it's just an extra comment. But then we can import it, and you'll see it changed to POST. It created this URL endpoint automatically. It set up our headers, so all we'd have to do here was enter in our API key, and then it already sets up the JSON body and everything like that. So let me import my API key real quick. Okay, so there's my API key. We'll hit test step, and then we should get a binary file back because that's just by default how this one was set up. So as you can see, we got this file and we get this Bitcoin chart in here because, um, we use the curl, so it's just kind of the default request. So now let's say we want to change things up. Um, I'm going to go and do this, the example of the one that I did, um, in the actual demo of this video. So we're going to copy this one which relates to this chart. We're going to go back into here and import curl once again, paste that in there, get rid of this top line and then import it. And so as you can see, a few things have changed. Once again, we need to put in the API key. So let me put that in there. And then now we have— this is the place where we can see the actual parameters. I don't know why this isn't loading up, but now we can see the actual parameters of what's going on in this request. And this is where we want to change the actual ticker that's going to dynamically come in. Right now it's set for Microsoft. We've got other parameters, of course, so we're going to leave it as is for now. And now you can see that we have— if we were to test this, it would come back once again as binary. So let me show you, we'll hit test step. It's going to come back as binary, and we don't want this because we need to access that URL. So this isn't good. What we want to do is change this to JSON. But one thing that we're going to have to set up in the headers is that the content type is JSON, because I think by default the content type is sort of an image, a binary image. So if we hit test step, we would see that this may come back with an error. Okay, so response body is not valid JSON. Change response format to text. So I think you would think that it's talking about this, but what I believe is that we need to set up the header to actually say that, hey, this is going to come through as application/json. So we're going to grab another header right here, which is content-type, paste that in there, and then we're going to grab application/json rather than coming through as an image like a PNG or a JPEG. So we're going to paste that in there and then hit test step once again. Now I really— I hope this should work. Okay, maybe we need to change it to text. Let's try that. Oops. Um, no, see, if we do this, I think it's going to come back as, um, binary still perhaps. Let's see. Okay, yeah, so we didn't get— we got this, this gibberish back. Okay, so I figured out what it was. Um, what we need to do is we need to save the chart to storage because then we're able to actually access that URL. So at the end of our endpoint, we just want to add -storage right up here, or not -storage, /storage. And then we'll change this back to JSON because that's the way we want it to come back. Now that we've set up application/json, we should be able to get this URL back. There we go. So this is the URL we're looking for. And now from here, what we would do is add another HTTP request. It's going to be a GET, and all we have to do is drag in the URL right here, and that's all we have to configure. Now it's going to get this URL and it will be able to bring us this binary image that we can now view. And then from there, we would just feed that into the OpenAI Analyze Image node. So in here, we would just have to make sure that we're saying it's going to be a binary file because that's the way that it's leaving this node, right? If we clicked on table or, you know, JSON or schema, we're not going to see the file. We're just seeing URL, but in binary, we can actually access and view this binary image. So that's what we were doing here. It's called data, so make sure you name it data analyzing image. I chose 4.0 just because we're analyzing an image, so I wanted to go with the most powerful model. And then I just turned off simplify and I set the detail to auto. And then from there it's pretty simple. It's just going to read in the file, look at it, scan it, make an analysis, and then push it off. And if you want to look at this prompt, of course It's going to be put in the workflow you can download for free. And then all we have to do is send the chart, which we're accessing the, um, the URL that we got from the Git Chart URL node. So this node that downloads the original file URL— or sorry, that gets us that file URL— we're just putting that back in here. And then finally, we are sending the response over to the agent. So we're calling a field response. We're setting it to the name response, and then we're sending in the actual output from the technical analysis OpenAI node. So whatever this node outputs is what's going to be sent to the agent. So if we go to, um, back to an execution, we'll look at the most recent one. Oh no, we'll look at this one because these were little tests. But we can see that, um, in here we have different things come through, but what we want is choices.content, and this is the actual analysis that it came up with. So in the response, we're referencing item.json.choices.message.content, and you can see this is the response we get. And this should align with the response that we got from the actual, the tool in the agent section. So the agent sees that response and then it uses its brain to, you know, format the response even better. So we click into the agent, we can click on logs, and we'll see exactly what happens. So first it updates the window buffer memory. Then it uses its model to read through the prompt, understand what it needs to do. As you can see, kind of a long prompt. And then it says, certainly I'll analyze the latest chart for Apple Inc. And then it takes the ticker of Apple for you. Let me generate that chart and provide you with a comprehensive analysis. And the input for the next node, which is get chart, is going to be just Apple, just the ticker. So you can see the query that was sent over to this tool was just Apple, and then it got the response from the end of the, the workflow, which was this, which we had just looked at. And then it sends that response back to the Anthropic chat model, reads through its system prompt again, and here is where it created the, the larger, um, more in-depth analysis right here. So this is what we ended up getting in our Telegram because we referenced the actual message in Telegram to be json.output, which is the output from the AI agent. As you can see, if we go to schema we got the output right here from the agent, and that's what we dragged in right here. Okay, so I know I went through that one pretty fast, but like I said, you're able to download the workflow for free. So hopefully you can get in there and play around with it and see, um, you know, how everything is working. If you enjoyed this one and it helps you out in some way, you learned something new, please give it a like. Definitely helps me out a lot, and I always really appreciate it. But thanks for making it to the end of this video. I will see you guys in the next one.










