GPT: KAMA Scalping Strategy in Python Makes 795%
About this lesson
In this video, I’ll introduce you to the KAMA Indicator and demonstrate how to implement it as a scalping strategy using Python within the Jesse framework. #ScalpingStrategy #Kama #Trading #scalping #opensource #Backtesting #Python #Bitcoin Performance metrics on other timeframes and symbols: https://jesse.trade/strategies/kama-trendfollowing Join our FREE Discord community: https://jesse.trade/discord Apex signup URL for fee discounts: https://jesse.trade/apex Explore our strategy listings: https://jesse.trade/strategies
Full Transcript
hey guys Sol today I'm going to act as a Trader who has a good strategy but maybe he's not necessarily a good programmer so I'm going to ask our GPT to write the code for me now of course I'll be there guiding it if it makes any mistakes but I'll do my best not to touch The Code by myself now the main indicator that I'm using in this strategy has become my most favorite indicator so far it be super Trend moving averages or anything else that I used before all right let me show you why the main indicator of this strategy is called kofman adaptive moving average don't let the name scare you it's actually very simple to use so basically when the line is red we're in a downtrend when it's green we are in an uptrend in other words when the current price is below the moving average we're in a downtrend when it's above we're in upt all right this is important because that's how we're going to write the code but the really cool thing about this is that it actually reacts to the price very quickly to compare let's add the super Trend which used to be my favorite indicator for Trend following notice that in this uptrend the super Trend started getting green in here while the cman moving average actually gave us the signal here so that's like eight or 10 candles before that it's also the same in here so the super Trend it started getting red in here but the kman moving average or comma in short it started giving us that signal here right in here I'm look at this the comma started getting green here but the super Trend gave us the signal here you see the difference is really huge all right so I simply asked GPT to write a trend following strategy using the comma indicator to determine the trend Direction risk 3% per trade which is what I usually do set the suplus and take profit at 2.5 times of the current ATR which again is something that I do in many strategies this is the code that it gave me so first let's copy the name and go to Jesse and create a new strategy with the same name and then I'm going to copy the whole thing and open my IDE and I'm going to paste the whole thing and I'm also going to zoom so it would be easier for you guys to see so let's go through it one by one so first it Define a new property for the comma indicator and the syntax is perfectly correct then it defined the ATR now it's simply saying ta. ATR then this is passing the current candles again perfectly fine for the shoot long which is our entry rule it is saying return true if the the current price is above the comma line this is exactly what I said that when the current price is above this line we are in uptrend and vice versa for short positions so that's exactly what it is doing here and once the entry rules are met we're going to use the go long method to open the long position and the go short for the short position and it's saying that the inter price is the current price which would be a market order and that's exactly what I wanted the sub plusus is the current price minus 2.5 * h which again is what I specified for it and for the quantity it's using the risk to quantity utility function of JC which first you will pass the available margin or your capital and then the percentage risk and that's three which is what I asked in my prompt then the entry price the suplus which it calculated here and then passing the current fee of the exchange for trading and finally it is submitting the buy order and to do that is first is passing the quantity and then the entry price right so then it's doing the opposite for short positions and now we need to submit the stop loss and take profit at some point right and it's doing that right after we open a position so using the unopen position event we're saying if it's a long position I want the Stop Plus to be the quantity of my current position and the price is going to be the current price minus 2.5 * the current ATR and we're doing the opposite for a take profit now this is exactly what I asked in my prompt and it wrote it perfectly fine and it's doing the opposite for short positions it also defined the update position method which is used sometimes for for example saying if it's a long position and the current price is below the comma line in other words when it's the opposite of our inter rule I want to liquidate the position now I tried this and it didn't work fine with this strategy so I don't want it to be here right and it's not what I asked in the prompt all right so let's go to Jesse to the back testing section and choose our strategy and as for time frame I will begin with 15 minutes the symbol is BTC UCT the duration I'm beginning since 2022 up until just a few days ago and I've also selected the fast mode and The Benchmark right so we should be able to start the first practice while this is going I'm going to add another one and pick the 30 minutes time frame and then another one for the 1 hour and another one for 4 hours all right so let's take a look at The Benchmark page this is for the 15 minutes which is absolutely horrible but that is basically because we're taking just too many trades and we probably paying just too much trading fees I look at it here we're paying 12,000 fees while the starting Capital was just 10,000 so obviously we need some filters now this is for 30 minutes it looks better because we're taking less trades this is for hourly and 4 hours all right so at this point I went back to GPT and I said remove the object position part which is what I didn't want to do because I didn't ask you to do that and I also add the adx filter so that I don't want the strategy to take any trades if the adx is below 50 now I always use the adx filter when I want to avoid taking a trade when the market is ranging which is what we always want to do with Trend following strategies so this is the code that it gave me let's go back paste it in now firstly it removed what I asked it to remove but it did add the shoot cancel entry method which we don't really need in this strategy because we are using a market order here to enter the position so there isn't any entry to cancel or not right so we can just remove this now it also added the adx property using the ta. adx and then it just passed the candles using the default parameters which is exactly what I wanted and then in my entry rule it added this one it's saying and self. adx is above 50 and it's doing the same thing for short positions so this is perfect let's go back to Jesse and run another back test so while this is going I wanted to quickly remind you guys that we have a Discord Community with more than 3,000 quants such as you and I we hang out there share ideas and help each other out and I would love to see you guys there all right so the result looks significantly better this is for 1550 minutes this is for 30 minutes this is hourly and this is for 4 hours so you can see we're actually profitable at this point right especially with the 4 hours now the main reason that we got profitable at this point is that instead of trading thousands we are trading just 573 trades so we're not paying as much in trading fees anymore although it's still by the way we're paying 7,000 in trading fees imagine if this was added to our ending balance we would have been sitting on a really nice profit so at this point I went back to GPT and I asked it to do something that I always do so basically whenever I have an indicator that I really like it usually works really well if I use the same indicator as it is but also on a bigger time frame all right so let me show it to you here so this is the comma indicator that we are using now I just added another one now because it doesn't have the option to set time frame in it because it's a community built indicator what we can do instead is to just increase the length from 14 to let's say 250 but in Jesse we can specify the time frame and that's what we're going to do so check this out so this means we now have two integrals not just one so for example in here this comma line went green but this one was still red so because of that we did not take the trade now maybe this isn't really a good example of it but in here for instance here it became red but we're not taking a short position because the below one or the slow one the one with the bigger time frame is green so because they are not saying the same thing we're not going to take any trades and as a result it wouldn't have been a false breakout here all right so I simply ask GPT this is good but firstly remove the shoot cancel inry method because we don't need it and I need you to Define another property for the direction of the trend again using the comma indicator except this time use the bigger time frame candle use the 4 hours as a bigger time frame but if the current trading time frame is 4 hours itself then use the 6 hours now this is the code that it gave me all right so first it defined a new property called the long-term candles so instead of passing the candles like this for this case we're going to pass the long-term candles and in it it said that the big time frame equals 4 hours but if the current time frame is 4 hours then the bigger time frame is 6 hours and then it's using the get candles built in method of Jesse which will give us the candles for whichever exchange we tell it to whichever symbol and time frame and it is passing this variable as a time frame all right and then it defined another one called long-term comma which is just using that and then it defined another property called Trend Direction which is using that to determine the trend but the weird thing is that it is not using this or anything else inside our actual iny rule so it's flood so I went back to it and I just said this is good but we're not using the value of the trend Direction in your ined rules also in it go ahead and just put the part where we checked the direction of the trend using the self comma also in it so that our shoot long and shoot short would be cleaner so this is the correction that it gave me and now if you check it again that property doesn't exist but instead inside our shoot long and shoot short it is using this line to check for the direction of the trend with the longterm comma now let's go back to Jesse and rerun the entire back test now remember these numbers so the sharp here is 0.6 1.2 right so the results are slightly improved not too much but they are especially with the 30 minutes I like this Equity curve better right so now I want to add another indicator which is very similar to adx except it kind of works the opposite so with the adx we want the volatility to be high to take a trade so that's why we say take the trade if the adx is above 50 but with the chop index index it's actually the opposite we want want the choppiness or the randomness of the market to be low and the way it works is that we Define some kind of threshold usually at number 50 and we want the choppiness to be below that so here for instance you see it was in a ranging Market which means it was random the choppiness was high and you can see it in here the number is actually above our threshold but here which we had some kind of trend the value for the chop index is actually low the same goes for here actually so we were just beginning to see some structure but then again we went into range so the value is is clearly seeing that no the market is just randomly working so that's why I really like this indicator for trending strategies so I went back to Jesse and I said add another filter for our in rules I want to take only positions when the choppiness index is below 50 and this is what it gave me right so it defined a new property called Chop and in it it said ta. chop and then pass the current candles all right so it also reformatted our inter rules and I really like it this way because you can clearly see we have four in rules for the strategy in the end of it it said the self the chop is below 50 it also did the same thing for short positions all right so let's go back to Jesse now remember these numbers sharp is 0.9 1.1 0.7 so let's reexecute everything one more time right so check this out the sharp ratio of all the time frames is now improved so with the 15 minutes now we have a sharp of one with 30 minutes we have 1.3 so let's take a look at the equity curve so it looks slightly better this is for 30 minutes and this is for hourly and this is for 4 hours all right so this is really cool but now I want to show you another technique that I use with this sub of strategy so you see sometimes there is a trend for example in here but because there was such a huge jump in the price like out of nowhere we don't really want to take the position here because there's a good chance that there will be a pullback now how can we know about this one way is to use the Ballinger bands indicator and if you take a look while this was the case the width of the Ballinger bands so the difference between this line and this line is actually really low but during here when the price had a huge surge the difference is really huge right you can see the same thing here for instance so we don't really want to take a trade here because now the difference between the upper and lower band of the Ballinger bands is really huge that means that the price is just moving too much and it has already went up too much and if you take the trade here there's a good chance there's going to be a pullback and we're going to end with a loss now how can we measure this well there's a really easy way and that is to use another indicator called the Binger band WID now with this one what we get is actually just what I describ which is the difference between these two lines and for instance in here which you can see it's really tight the value for this is almost one but in here the value goes up to near nine right so it's really huge and in this line that I said you know we don't want to take the trade the value is almost at seven so now I asked GPT to add another filter using the Ballinger band with value and I said I want to take a trade only if the value of it multiplied by 100 is below 7 now why did they ask it to be multiplied by 100 that's because in the calculation that the trading view is using that's what they're doing they are multiplying it by 100 otherwise this value would have been 0.07 instead of just 7 which is just really easier on the eyes because I want it to be the same as trading view I just asked it to multiply it by 100 all right so let's copy this go back paste it here and now we have a new property called BB width and in it is using ta. Ballinger bands and it's actually calculating the value of the BB width that I wanted instead of using the builtin indicator that Jessi has for this indicator so I went back and I simply asked that this seems fine but I need you to use the built-in volunteer bands with indicator of Jessi it gave me this one which is indeed using the Ballinger bands with built-in indicator of Jessi and in the in rule it's saying that the value of it multiplied by 100 must be below seven and it's using the same thing for a short position all right so there's one more filter that I wanted to add you see sometimes we take a trade and it actually goes really well we close the position but we're kind of done with that Trend especially because this is a scouting strategy we want to get in and out very quickly so we don't want to write the trend for for for example for as long as possible but sometimes our in rules are still true so that means even though the strategy closes one trade it immediately takes another one so I wanted to implement some kind of tool off mechanism so I went back to GPT and I said lastly add another inry rule I need the strategy to remember the last index that it took a trade and when a trade is over I don't want to take another trade until at least another 10 candles has been passed so let's copy this all right so first it Define a new variable because we're going to need to hold the value of that index it's called last trade index and then in our entry rule it said if the current index minus the last trate index is bigger or equal to 10 which is exactly what I wanted it also did the same thing for our Sho short method but where is it updating this because we need to specifically update this it's doing that inside the go long and go short method so once we are opening the position it is updating this value using the current index now this line is perfectly correct but there is one mistake at this point we are just opening the position but I wanted to wait 10 candles after we close the position all right so this ISS to change so I went back and I told it that you are updating the last index inside the go long and go short methods but that's for when we are opening the position I need you to update it inside the on close position method instead and it gave me this one so now it added another method called on close position which is a real event method inside Jesse and in it is saying that I want to set the current index inside the last word index variable which is exactly what you wanted and it removed that other one all right perfect so let's go back to Jesse and run another back test so remember these numbers the sharp is one 1.3 1.1 and 1.1 all right check this out the sharp is upgraded to 1.9 on the 15 minutes time frame and the Cal R is 3.7 which is amazing and the max thron for almost all of them is below 10% that's just awesome with the 30 minutes it's 1.3 which is still awesome so let's take a look at the equity curve this looks fantastic and this is on the 30 minutes now you may think that this is a straight line but it's not actually it is still going up and because the max thron is really low we can simply add to our position size so that this would look better now this is with the hourly and this is with the 4 hours now the hourly and the four 4 hours I think should be retired at this point but these two look really well but the max Ron is still really low so that means we can easily add to size of our position so if I go back and in here for instance I can just add to this quantity by number such as let's say three and rerun the two of them all right so now with the max throw down of minus 24% we're making nearly 800% profit all right so this is the equity curve now obviously this looks still really good and this is with with the 30 minutes now you see my point it wasn't really a straight line it is still going up but we weren't really seeing it because there wasn't enough volatility in the daily balance but now that we added to the position sides it's much more but still these Max R numbers I think it's really safe to just increase them because my risk cap allows me to take up onus 30% Max R down and if we do that we're going to make even more penal numbers in here you can access the source code of this strategy on our website if you haven't checked out this page yet now is the time to do so there are tons of other strategies in here and you can very quickly see the results of each strategy on various periods and symbols and time frames now this was a new type of video that I just did where the idea of the strategy was from me but the implementation was done by the AI while me being the teacher and guiding it now if you like this format please let me know and if you didn't if you want me to go back to the previous format where I take the idea let's say from the AI but I called it from a scratch myself again please let me know now we're going to have a giveaway a random person who likes this video posts a comment and subscribes to the channel is going to receive 1 million bnk token all right let's pick the winner for my previous video and the winner is amazing results well done thank you so much for your comments please reach out to me so that I can send you your buk tokens thanks for watching and I'll see you in the next one [Music]
Original Description
In this video, I’ll introduce you to the KAMA Indicator and demonstrate how to implement it as a scalping strategy using Python within the Jesse framework.
#ScalpingStrategy #Kama #Trading #scalping #opensource #Backtesting #Python #Bitcoin
Performance metrics on other timeframes and symbols:
https://jesse.trade/strategies/kama-trendfollowing
Join our FREE Discord community:
https://jesse.trade/discord
Apex signup URL for fee discounts:
https://jesse.trade/apex
Explore our strategy listings:
https://jesse.trade/strategies
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Related Reads
📰
📰
📰
📰
Top AI Papers on Hugging Face - 2026-07-15
Dev.to AI
Integrating Open-Weight LLMs as Drop-In API Replacements: A Practical Guide
Dev.to AI
How I Built a Multi-Page AI Website Generator for Nigerian SMBs — Architecture, LLM Prompting, and Lessons Learned
Dev.to · Innocent Oyebode
The Token Tax: Why You Are Paying for How AI “Thinks,” Not What It Writes
Medium · AI
🎓
Tutor Explanation
DeepCamp AI