Code a custom NinjaTrader 8 indicator using ChatGPT (part 1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] well hello there today we're going to do something a little bit different uh just like the title on the screen we're going to write a custom ninja Trader 8 indicator using chat GPT with the latest language model that just came out gpt4 the other day so let's get to it we won't be any we won't be doing any trading today I already finished most of my trading this morning um this is actually not ninjatrader this is Quant Tower in this first part of this video we'll just use chat GPT to generate the ninjatrader code what our indicator will do well let me step back I have not written in an nt8 indicator before I've looked at some of the code you know to help somebody debug a problem or make small minor changes but nothing from scratch and so what we're that's what we're going to do today I did attempt to create one the a couple nights ago I think I succeeded but it took me about two and a half hours to kind of you know figure out how to get it all going now with chat GPT if I was truly an experience I'm sure there would have been some ramp up time with the developer environment whether it's Visual Studio or the ninja script Trader but you know some of the things I was trying to do I still had to dig through some apis and the Google and stack Overflow and such we'll see if chat GPT can help expedite some of that so I'm logged into my chat GPT Plus account I'm going to choose chat gpt4 and if you haven't logged in or don't have chat GPT plus there is a limit on how many messages you can consume or have chat GPT generate for you I don't quite know that metric you know it's every four hours and there's no way to find it that I know of so now what I'm doing you know I subscribed a couple days ago is just using it as often as I can throughout the day and taking breaks in between so let's go ahead and just start with the prompts here I'm going to increase the font a smidge and just to see can't hide the right window here [Music] well hopefully that'll be big enough we'll see let's say I want to start a or I want to code a custom we'll just start with that see what it says [Music] Okay C sharp it's going to give you a step by step [Music] okay that sounds right [Music] wow it tells you where it's even located [Music] this is the I think this first stage because we asked such a simple question is just walking through giving you an overview of the layout of the code which looks you know for my limited experience looks right foreign [Music] you can use Visual Studio [Music] oh just gonna go ahead and give us a SMA indicator [Music] foreign you get most of this for free you know when you create a new indicator via a ninjatrader but sometimes you know that what they give you comes so fast that it is helpful to get a little walk through here [Music] it does some error checking there with the current bar being less than the period count foreign [Music] plots it because it didn't set it to Value the value array or the values array one of the two let me screw up add line add plot okay [Music] cool alrighty well let's see if we can um you know go beyond the basics here and say I want to let's see [Music] [Music] foreign [Music] [Music] [Music] [Music] let's see Kendall coloring [Music] wa foreign [Music] [Music] the first moving average will use the difference between the current price and the previous prices its input the second moving average will use the absolute value of the different of that difference okay that looks right [Music] so it looks like again from my experimentation chat GPT is great at helping you get started not necessarily modifying code afterwards just because once you've made your customizations unless you communicate that to chat GPT as it generates additional code you'll have to manage between what you've changed and what it's generating it's doable it's just that you spend a lot of time just talking to it versus typing code that that you can do quickly right like if you need to change a variable name or comment something out or this and that when I was doing this by hand I couldn't find a Wilder's moving average in the list of indicators and I'm not sure where it's getting its WMA right now but it looks like we're getting the input of the first one to be the close minus the previous close versus so there's there's a slight difference there on [Music] we'll stop in a little bit oh it's also doing line color or candle coloring for me it inferred based on the name of the indicator that it did this conditional coloring here where if one is greater than the other change that this is not the exact logic that I want but uh at least it tells me well that's candle outline not the actual bar color [Music] providing now the properties that I can customize with that [Music] [Music] [Music] cool so this is the line that I was pointing out earlier I actually know this line right here there's a slight difference between these two one is just calling close versus close you know with the offset of zero or the current bar now I don't know again I don't have much experience in ninjatrader but this you know the time series data for the close value is actually called closed then this is right you know the close what if you don't pass in an index it just assumes the current bars close okay that's cool I mean that I don't know where the wama um I don't know if that's a valid class that is being referenced I know like I said I had to customize my own but because I couldn't find it on the list of pre or indicators that I could use but that's okay go on um I also [Music] [Music] [Music] thank you [Music] foreign so while it's generating this and slowly typing it out it's not going to replace the job of a programmer but it definitely is a good tool to help and experience developer get started on a new project where it's you know generating custom stuff with names and certain values so that you don't have to you know if you're copy and pasting from an existing indicator in this case there's a chance you will screw up by forgetting to replace a certain name or value somewhere whereas here it's you know you're it's basically a giant input form while you're communicating with it you can tell it's a like the is overlay portion you can say I I don't want to print it on the main chart I want to print it or display it on a subplot I believe it can you know detect that and set these parameters to false for you so it's uh it's creating a new period parameter for us it forgot to plot the uh the waas but that's okay that's fairly easy to do but that is something to be aware of that it um I could I could probably make a request to say I don't want to plot the EMA [Music] like okay it's using the built-in update functions so this is a little different than the previous code generated I don't think it I could be wrong I'll have to scroll up once it finishes generating this I know that if I were to scroll up now it may stop generating what it's currently doing so I'm going to wait till it finishes so we're about you know 12 13 minutes in and we've got um a good framework you know for our indicator I don't know if it'll compile yet that'll be in the next video I'll copy the the contents of this all right looks like it got stuck and I see this quite often is if it's a lot of lines of code you may have the type continue for it to finish printing out and then it's not in the right display um box so you're just getting it as plain text basically you'll just have to know when you copy and paste that's cool right the last thing I'm going to do here [Music] after it finishes this for this video is I'm gonna have it not plot the EMA I mean I could do it by hand but this is just an example on state change I don't want to plot the enemy [Music] yeah I don't know why the code generation is going line by line I don't know if it's a server thing it was a little bit faster when I was doing something else last night with react in helping me generate I'm learning react as well and I was just you know asking it to to help me Implement a new library to make API calls and it was much faster I don't know if it's because the the train model or the react portion of its knowledge is easier to connect versus something like this I don't know I don't quite know how machine learning and these language models work which reminds me of a phrase that chat GPT and other generative AI they um they know enough to be dangerous it doesn't mean what they they share with you and generate for you is correct you as the end user will have to be mindful to evaluate each you know line of code each default value is correct and it may not have done everything in the most idiomatic or preferred way but I'm fairly certain that it will work with some tweaking and debugging all right looks like it removed our ad plot from the on-state change where it set the defaults and now on bar update it's gonna hopefully use a different bar coloring oh it's just doing the candle outline there's another method called to to paint the bar itself [Music] I'll see if I could uh just prompt it on that on the bar update [Music] good [Music] looks like I got nope it didn't get stuck on the same section of code as it did last time so once it's this completes what I would do is go to ninjatrader and you know go to the code editor portion and click new indicator and give it the same name as what I have named this so that I can copy this code into it right away and if there's any naming changes I do in my code I'd come back to this conversation and chat GPT and said hey I want to name my indicator this now that way it'll know in its conversation history what the new name is so if you ask it to do anything else you can do that with the class name itself or the variable names or any private methods you may have just so that you stay consistent between the conversation and what you have in your code of course if you are no longer in need of referencing the conversation you can go ahead and you know do whatever you want in your own code I'm just going to ask one more thing in the on bar update method how do I paint the bar [Music] because I know this is like as if I was to you know take the code run it and all that it'll just paint the outline but I want to Bar itself I know it's a different method or at least I think I know [Music] candle color instead of candle outline okay so the so if if you haven't used chat gpt4 to generate code you can you know if you were more specific with your prompts like in this case I said on the onbar update method I want to do this instead it'll just go straight to that and if you want if it starts um just you know ellipsing things and say oh there's previous code here I'm just going to print a new prompt you can always say print me the whole onbar update method and it'll do that so now between the two you know examples that it's provided with candle outline and candle color I have enough information to add my own if logic here to do that the last thing I'll do is um all right [Music] [Music] [Music] awesome [Music] oh I hope he doesn't print the whole thing no it is okay I don't know if it's doing this just to slow down although I can stop generating any time just load and slow me down so I don't have to type more prompts in you know I'm gonna go ahead and end the video here as the first part of this series um it won't be a long series but who knows in the next one what I'll do is I'll take the code that's been generated here I'll go into ninjatrader and I'll copy and paste most of what I have and assimilate the two and we'll see what we get all right thanks again for watching like And subscribe and stay tuned for part number two
Info
Channel: Latter-day Trader - Codes
Views: 344
Rating: undefined out of 5
Keywords: chatgpt, ninjatrader8, ninja trader 8, nt8, ai, day trading, futures, c#, indicators, custom indicator, apex
Id: 8Qd-1J4lrY8
Channel Id: undefined
Length: 23min 58sec (1438 seconds)
Published: Fri Mar 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.