i coded a trading bot live.. (293%+ roi) — Transcript
Full transcript
- 0:00don't know about you but the only reason
- 0:02i usually lose a trade is because of
- 0:04myself and it's because i didn't close
- 0:06out when i hit my target or i was in a
- 0:10losing trade and i didn't take my stop
- 0:12loss or something that has to do with
- 0:15myself so
- 0:16a couple years back i set out on a goal
- 0:18to just automate my trading and it's the
- 0:20absolute best strategy of ever best
- 0:23thing i've ever done in my life because
- 0:25now i can code algorithms and you can
- 0:28too i promise you if you haven't started
- 0:30coding yet if you're trading hey you
- 0:32know you can increase your profits by 10
- 0:3520 30 100
- 0:37just by
- 0:38coding them out and saying hey computer
- 0:41you do this for me because instead of
- 0:43you panicking when it goes down the
- 0:45computer might buy or based off of
- 0:47whatever rules you put in there maybe it
- 0:50sells
- 0:51maybe it takes a stop you know it takes
- 0:53a stop out or you know it takes profit
- 0:55at this point or whatever
- 0:57the thing is is computers can execute
- 1:00without the emotion and the only
- 1:02downside of humans
- 1:05is we we have emotion and you have to
- 1:07use the bathroom you have to eat what if
- 1:10you're in a trade and you need to exit
- 1:11but you got to go you got to go to the
- 1:13bathroom or you got to eat lunch or you
- 1:15have a family
- 1:16thing going on right so there's so many
- 1:18reasons i don't need to sit here and
- 1:20convince you to learn how to code i
- 1:21think if you're on this video you're
- 1:24everlasting learner and you're never
- 1:26gonna stop until you get there so this
- 1:28is just one of the best ways i've been
- 1:29able to pull alpha out of the market is
- 1:32learn how to code and code your
- 1:34algorithms to trade for you 24 7
- 1:38365 because you are literally
- 1:41unstoppable there's not many people out
- 1:44here that are going to spend their time
- 1:46searching through youtube for new
- 1:47strategies or algorithms but you're
- 1:50doing that so
- 1:51if you can
- 1:53take the best of you which is you know
- 1:55your persistence and you put it into
- 1:57code to trade for you
- 1:59it removes the only downside of me and
- 2:02you which is hey we're humans we gotta
- 2:04sleep we gotta eat we gotta go to the
- 2:06bathroom we have emotions we think it's
- 2:08gonna go higher or lower you know we
- 2:10think right computers don't think they
- 2:12just do
- 2:13so in this video what i'm gonna do is
- 2:16you know i'm a regular dude
- 2:18i i'm not a mathematician i didn't go to
- 2:21harvard i didn't get an engineering
- 2:23degree none of that stuff i think that's
- 2:25all
- 2:26you know mystical stuff that they want
- 2:28you to believe
- 2:29just so they can say hey you can't be an
- 2:31algo trader because you don't know how
- 2:33to or you didn't go to harvard or you
- 2:35don't you're not a mathematician yada
- 2:37yada well guess what i'm always trying
- 2:39to 24 7 365 every single day i make a
- 2:42new algo and i'm going to share it here
- 2:44with you on this channel and i'm just
- 2:46going to write an algo here just to show
- 2:48you that like you don't have to be an
- 2:50expert to do this you don't have to be a
- 2:52crazy coder you don't have to you know
- 2:54spend years and years of your life to
- 2:56figure this out
- 2:57but you're diligent enough you're
- 2:59already persistent enough that you're
- 3:01gonna find a way to pull alpha out of
- 3:03this market and in my opinion you know
- 3:06i'm a decade plus entrepreneur
- 3:08in my opinion
- 3:10this is the best way
- 3:12to pull alpha out of the market and the
- 3:15market is the best business if you
- 3:17figure it out so let's just go ahead and
- 3:19start coding you know um i really
- 3:22appreciate you being here it's super
- 3:24cool because you are unstoppable you
- 3:26will figure this out and let's just go
- 3:28ahead and start coding this out i'm
- 3:30going to build a strategy today that is
- 3:32it'll look at the overall trend past
- 3:35maybe fifty hundred two hundred days
- 3:37we'll get into that later
- 3:41and then we'll decide which way the
- 3:42trend is going you know from my
- 3:44eyeballing this looks like we're hitting
- 3:47long-term support kind of
- 3:50um we're obviously in a downturn
- 3:53but it might bounce here
- 3:55you know i i can see that right but
- 3:59i'm thinking and i don't really want to
- 4:02think i want to program a computer to
- 4:04just do it all for me because it's just
- 4:05so much better it's just such a better
- 4:07lifestyle i don't have to sit here and
- 4:09look at these charts all day um but yeah
- 4:12this is the daily chart so my strategy
- 4:14here i'm trying to build is it's not too
- 4:16hard uh it's gonna look at the
- 4:20last 100 days or so
- 4:24actually it'll probably be about 20 days
- 4:26so i'll build an sma a simple moving
- 4:29average and it will tell me which way is
- 4:31the trend
- 4:32and if the trend is
- 4:34you know bullish
- 4:36we're going to look for longing
- 4:37opportunities but if it's bearish we're
- 4:39going to look for shorting opportunities
- 4:41now this is a bitcoin chart i will will
- 4:44go ahead and pull up let's see
- 4:47pull up my femix account here because
- 4:51i actually don't want to trade bitcoin i
- 4:54would actually rather trade one of these
- 4:57altcoins
- 4:58based off of bitcoin
- 5:00so it's a little weird i know but
- 5:05it tends to work and the reason i do
- 5:07that is just the all coins are a little
- 5:09more volatile so
- 5:12you know they typically follow bitcoin
- 5:14so i might even go ahead and see what
- 5:17the trend is
- 5:18with bitcoin
- 5:19and then also the altcoin they're gonna
- 5:22be similar but i'm going to look at the
- 5:24trend and then i'm going to place my
- 5:26buys i'm going to build like a
- 5:31i'm going to build a 20 sma again
- 5:34but
- 5:35i'm going to have it on the 15 minute so
- 5:37the first sma is going to be a daily sma
- 5:41for the last
- 5:42i think 20 days maybe 15 20 days we'll
- 5:45figure it out when i get there test it
- 5:47out and then the second sma is going to
- 5:49be a 15 minute sma
- 5:52for 20 periods or so and the reason i'm
- 5:56going to put this sma in is
- 5:59because
- 6:01this one is going to determine where
- 6:03i'm going to buy
- 6:04it so one determines which way we're
- 6:07buying if we're opening as a short or a
- 6:10long
- 6:12that's the daily one and then the second
- 6:15parameter i'm looking at is the 15
- 6:18minute
- 6:19sma
- 6:20and that's where we'll place our bids
- 6:22i'll probably i'll probably place two
- 6:24eyes and they're gonna be above and
- 6:26below that sma so pretty simple strategy
- 6:29i'm not gonna use a stop loss i'm gonna
- 6:32use a kind of just
- 6:35a stop loss in the sense of
- 6:39size so i'm just not gonna
- 6:41i'm not gonna make my positions too much
- 6:44i will use some leverage
- 6:45let's go ahead and see what i have here
- 6:48so i only have 100 bucks in my account
- 6:50and that's probably good because you
- 6:52know this is a new strategy but once
- 6:54this strategy proves itself
- 6:58we can go ahead and level this up to
- 7:01probably a thousand two thousand um i
- 7:04like to diversify i have tons and tons
- 7:06of strategies so
- 7:07i try to keep keep it in the low
- 7:09thousands and then you can scale with
- 7:11other strategies but that being said
- 7:13let's just dive into it
- 7:15i've got this great cup of coffee here
- 7:17so i'm sorry if you hear me slurping a
- 7:18little bit
- 7:22it's my favorite coffee and i'm gonna
- 7:23need it because we're building an algo
- 7:25here
- 7:26we're building it from scratch
- 7:28i think i went over everything
- 7:31you know the strategy look at the trend
- 7:33from the sma
- 7:35we're going to do the 20 day sma
- 7:39and then we're going to place our buys
- 7:41or shorts
- 7:42our buys or cells
- 7:45to enter
- 7:46along the 15-minute sma so we need to
- 7:48create two smas that'll be one of the
- 7:50first things we need to do i'm going to
- 7:52use ccxt which is a library
- 7:55in python and i'm just going to get
- 7:57started because i think this is
- 7:59this is going to be good um a lot of
- 8:02people are scared right now like this is
- 8:03a
- 8:04downtrend i personally think
- 8:07i'm not going to think i'm not going to
- 8:08make any opinions you know from from my
- 8:11eye it looks like it's gonna
- 8:13it's gonna bounce but that being said
- 8:17if it doesn't bounce this is where
- 8:18humans go wrong like if it goes down
- 8:20here and it starts falling if i keep
- 8:22thinking it's gonna bounce i would keep
- 8:23longing it but
- 8:25i just want my code to do it for me
- 8:27because i at the end of the day if i
- 8:30program this strategy or whatever
- 8:32strategy i do run
- 8:35then the code runs it and
- 8:38it is what it is you take out the
- 8:40emotion for example like i'm sure you've
- 8:42been in a strategy in a trade before
- 8:44where it's like you're in a a winning
- 8:46trade and you just need to close it out
- 8:49and if you closed it you would have won
- 8:50you could have walked away enjoyed your
- 8:51day
- 8:53but what happened is you have a motion
- 8:55and you think hey
- 8:56this might go a little higher or i might
- 8:57make a little more
- 8:59and then it turns around on you and you
- 9:01lose it so that type of stuff happens
- 9:02all the time and i just want to avoid
- 9:04that that's why i'm an algo trader and i
- 9:06i just code all my algorithms
- 9:09in order to trade for me so let's just
- 9:10dive into this this might take a bit so
- 9:12please do stick around this is gonna i'm
- 9:14gonna show you a lot and like i said i'm
- 9:16just a normal normal dude and i want to
- 9:19show you that this is not like rocket
- 9:21science so let's make all our imports
- 9:23here let's import ccxt which is the
- 9:26library i'll be using
- 9:28let's import numpy
- 9:30let's import my don't share config
- 9:34as ds this is pretty much a
- 9:36configuration file with my keys in it
- 9:38let's go ahead and import
- 9:43um date time for sure let's import date
- 9:47and i'm doing this live so
- 9:49i don't see many people do this on
- 9:51youtube but
- 9:53if you appreciate it
- 9:55this transparency just go ahead and
- 9:58smash that like button
- 10:00okay so i imported all of these things
- 10:03it looks like i need to go ahead and tip
- 10:06install some of these
- 10:09pip install
- 10:11date
- 10:12see if that works
- 10:13nope
- 10:15pip install date time
- 10:18and you're gonna see like everything
- 10:21you can see like i'm gonna run into
- 10:22errors and stuff and
- 10:24let's go ahead i'll have to google stuff
- 10:26along the way of course
- 10:30let's go ahead and i'll handle that
- 10:32later if i need it
- 10:34i'm just going to mark them out for now
- 10:37import date
- 10:40let's go ahead and keep it moving
- 10:46import
- 10:47time
- 10:49and schedule okay now we need to connect
- 10:52to
- 10:53our uh
- 10:57our brokerages so how are we going to do
- 10:59that
- 11:02i'm going to type in phoenix equals
- 11:05ccxt
- 11:07cc xt
- 11:09dot vmix
- 11:12and then get some curly brackets and
- 11:14let's do enable
- 11:17rate limit
- 11:19and that will be true okay
- 11:22and then api key
- 11:26let's go ahead and you know here yours
- 11:29might look like that
- 11:30but
- 11:31i'm actually calling it in from this
- 11:33file that i call ds
- 11:35and let's
- 11:37find the key here
- 11:39and then the secret
- 11:42so ccxc is pretty cool because it
- 11:44connects to all exchanges all crypto
- 11:46exchanges pretty much is
- 11:48pretty much so coinbase finance
- 11:51v max
- 11:52ftx
- 11:54all that so let's go ahead and
- 11:57i'm gonna
- 11:58mark
- 12:00what was going on here from daytime
- 12:03i always do that
- 12:06okay so i'm gonna go ahead and just make
- 12:08sure that we're connected so i'm gonna
- 12:10print out femix.fetch
- 12:14balance
- 12:16and let's run this let's see if it is
- 12:19connected i do have a balance of like a
- 12:21hundred bucks or something and that's
- 12:22plenty plenty plenty for this algorithm
- 12:25because i can lever up you know i can
- 12:28lever up 20 times
- 12:29um maybe won't do that much but we are
- 12:32connected okay so the symbol i'm going
- 12:34to use for now equals let's just let's
- 12:38build it with btc because that will be
- 12:40easier
- 12:43okay
- 12:45and
- 12:48let's put position size
- 12:50position size
- 12:51let's just do one for now i will change
- 12:54that later params i this is
- 12:57if you've seen my other videos i show a
- 12:59lot of like step by steps
- 13:02and
- 13:03this is a parameter that i use
- 13:06for all of my algo trading within femix
- 13:09because what it does is it makes it so i
- 13:12i only do limit orders it's a post only
- 13:15order so
- 13:16i'm super handy to have all of that now
- 13:19we want to go ahead and figure out the
- 13:21indicators right so first step
- 13:24uh find daily
- 13:27sma
- 13:29i think i'm gonna do 20 let's do daily
- 13:31sma 20
- 13:33and then i want to find
- 13:36daily
- 13:39sms or not daily 15 minute 15 minute
- 13:44sma
- 13:4520. okay so i need to make sure i get
- 13:48both of these smas in here
- 13:51and then
- 13:52i also need to get the bid and ask get
- 13:55bid
- 13:56and ask because it's just a it's a
- 13:58better
- 13:59it's more accurate pricing from what
- 14:02i've seen
- 14:03um let's see what else should we get
- 14:05here let's start there and then we'll
- 14:08we'll just build this over time like i
- 14:09said i'm building this whole thing in
- 14:11front of you because i want to show you
- 14:13that like i'm
- 14:14you don't have to be a mad genius to be
- 14:16an elbow trader you just have to
- 14:18be like
- 14:20persistent like it took a few months to
- 14:22learn how to code sure
- 14:25sure it was kind of boring at times but
- 14:27if
- 14:30you can double your profits because you
- 14:32get rid of your emotion it's so worth it
- 14:33oh my goodness so worth it you spend so
- 14:35much time looking at the screen anyways
- 14:38um okay so
- 14:41i don't like making decisions so that's
- 14:42why i'm coding this so let's just jump
- 14:44back into it let's go ahead and find the
- 14:46sma
- 14:48um
- 14:49let's call this daily
- 14:51sma
- 14:52okay
- 14:58and then what we want to do
- 15:00is we want to say
- 15:03let's say df
- 15:09i'm going to do dfd so i'm going to make
- 15:10a pandas data frame
- 15:13and by the way if you have any questions
- 15:15along the way about any of this
- 15:18let me know let me know in the section
- 15:20below
- 15:22super easy for me to answer them for you
- 15:27i actually like to say something like
- 15:29print
- 15:31starting
- 15:36indies so indicators
- 15:39and
- 15:45just thinking here and i apologize i'm
- 15:47gonna there's gonna be some pauses
- 15:49throughout this right because i'm i
- 15:51literally have to think this through
- 15:53and this is the process of coding an
- 15:56algorithm so i'm just getting things set
- 15:58up i'm good everything's imported we're
- 16:01looking good got a data frame here
- 16:06and i need to pull in data obviously is
- 16:10one of the first things i need to do
- 16:12so
- 16:15let's go ahead and
- 16:21let's get the bars
- 16:22bars equal
- 16:27femix
- 16:28we got to get our data i think that's a
- 16:30good place to start and this is why i
- 16:32love coding it's because like
- 16:36algos because you're just like
- 16:38sitting here
- 16:40trying to figure things out and it's
- 16:41like a puzzle right so
- 16:43let's say time frame equals
- 16:47time frame
- 16:49i haven't set that variable i need to
- 16:50set that
- 16:51and then limit of bars this is how many
- 16:54bars we want equals num of bars
- 16:58okay i need to set both of these so this
- 17:00will be the time frame
- 17:05so
- 17:09equals one day
- 17:11sorry it's one day
- 17:13okay and number of bars
- 17:16give us as many as you can
- 17:19no actually i don't need that many i
- 17:20just need a hundred okay
- 17:22let's do a hundred
- 17:24okay
- 17:25so starting indies i made a data frame i
- 17:28don't know if i'm gonna use it i should
- 17:29use it though
- 17:31and now
- 17:35i should bring this data frame down here
- 17:36because i want to put these bars here
- 17:40and just to kind of show my work let's
- 17:42go ahead and
- 17:44just not even show my work i just want
- 17:47to see if this works let's print bars
- 17:50see if this works i should have
- 17:53now
- 17:54the um
- 17:57i should have the open high low and
- 17:59close open high low and close
- 18:02and the volume for the last 100 days
- 18:05on the daily so remember we're building
- 18:07the daily sma right here so
- 18:12starting indies okay perfect
- 18:16um
- 18:19okay
- 18:20so
- 18:21looks like it's on a list
- 18:24this would be the date time stamp this
- 18:26would be the open this is the high
- 18:30low
- 18:31close volume perfect okay so i have all
- 18:35the data now i need to change this data
- 18:37up because it looked like it was in a
- 18:38list
- 18:40let's go ahead and
- 18:43pause that out
- 18:45and then let's go ahead and make this
- 18:46data frame just
- 18:48have our
- 18:49data be a little nicer columns equal
- 18:54um
- 18:55timestamp
- 18:57okay
- 18:58let's do open
- 19:02hi
- 19:05low
- 19:06and i gotta remember to uh
- 19:10remember that i'm using lower cases
- 19:12sometimes some data sources will use
- 19:16upper case
- 19:17some will use lowercase and i'm a
- 19:20lowercase guy
- 19:21it's just easier to remember for me but
- 19:24okay so now i have this data frame and
- 19:26let's print this out
- 19:28see what this looks like see if we have
- 19:29a better
- 19:31better looking set of data now
- 19:39beautiful beautiful beautiful beautiful
- 19:41okay so now we have the time stamp to
- 19:42open the high the low the clothes and
- 19:44volume i don't know what date this is
- 19:47though so i need to change that okay so
- 19:49how do you change that let's see here
- 19:53let's call this df let's tap into it tap
- 19:56tap in the timestamp
- 19:59and then let's change it by doing pd.2
- 20:02datetime
- 20:04and then df
- 20:06um
- 20:08we would tap in the timestamp again
- 20:11and then oh we would just change the
- 20:13unit unit
- 20:16is we would say it's okay so essentially
- 20:19what we're doing with this line is
- 20:20saying hey the date times in
- 20:22milliseconds timestamp
- 20:24let's uh change it to date time
- 20:26so this should look better now
- 20:28let's go ahead and move this print here
- 20:32to uh here
- 20:36let's see what this looks like now
- 20:39beautiful beautiful beautiful okay so i
- 20:41have until 1 22. today is 5'7 up nope
- 20:45today's 5 8 so this is yesterday's data
- 20:48up to yesterday's data um will that work
- 20:53let me think
- 20:55i think that's fine
- 20:58do i need today's data on the daily
- 21:02let's check this out i want to see what
- 21:04it's going to look like with the 15
- 21:05minute because i do need
- 21:07i do need the last 15 minutes for the
- 21:10next one
- 21:11okay this works 7 15 17 15 i think right
- 21:15now is
- 21:1817 30ish
- 21:20okay this works this works this works
- 21:21okay so i was just checking to see
- 21:24if
- 21:25the if we had the right
- 21:28data coming in from phoenix i know
- 21:29phoenix is sometimes playing with their
- 21:31data to be to be honest
- 21:33um i love the exchange though it's it's
- 21:35nice um let's see okay what do we do now
- 21:38we have the data frame we have the
- 21:40information we need
- 21:43okay there's some things that i really
- 21:45enjoy using
- 21:49but i want to figure out how should we
- 21:51do this
- 21:52like i want to get the low the high
- 21:54and all that good information
- 21:56but since it's in the function i need to
- 21:58think this through okay so we have the
- 22:00daily we don't have the daily sma yet
- 22:02though so let's just get the daily sma
- 22:06daily
- 22:07sma
- 22:09and i'm gonna put this data frame again
- 22:11here
- 22:16and
- 22:17i have my copy
- 22:22and let's find the sma
- 22:25so i think we need to do something with
- 22:27like rolling closes yeah that's right so
- 22:29daily sma
- 22:31and we're going to do a 20 20 day
- 22:35why did i pick 20 today i don't know to
- 22:38be honest you could use the
- 22:4015 day the 10 day whatever you want but
- 22:43that's the thing with i'll go trading
- 22:45it's a bunch of parameters and you got
- 22:46to test things out i could backtest this
- 22:49and i probably will
- 22:51maybe i'll make another video back
- 22:52testing this strategy as well usually i
- 22:55like to backtest before i run live but
- 22:57at the same time
- 23:00i sometimes just run live you know i'm
- 23:02not using a crazy amount of money 100
- 23:04bucks i'm not going to die i'm not going
- 23:06to die if i lose 100 bucks so
- 23:09let's go ahead and say
- 23:12dfd
- 23:13let's add to the data frame the sma
- 23:17sma
- 23:2020. uh and we have to call it daily so
- 23:26estimate 20 day okay that makes sense
- 23:28right sma 20 day so i'm adding to the to
- 23:31the data frame and i'm going to say df
- 23:37um dfd
- 23:39i need to tap in the dfd and then i need
- 23:41to find the close
- 23:44and then i need to make the average
- 23:46of the close so roll in
- 23:51and then i think it's 20
- 23:53dot mean
- 23:55that means and then we should be good so
- 23:58now we should have a column here that
- 24:00has the 20 day sma
- 24:03and i think this is a really good
- 24:04example of like
- 24:08one line of code to find the 20 sma
- 24:11before i started coding like this seemed
- 24:13like something hard right
- 24:15it's one line
- 24:17it's crazy
- 24:18let's see if it works though
- 24:26okay so these have nones nan's
- 24:30because there wasn't 20 days of data
- 24:33before
- 24:34i might need to get rid of these
- 24:36and that's fine because
- 24:41yeah that's fine because
- 24:43this data goes back far enough and i'm
- 24:45only going to look at the 20-day sma
- 24:48so i'm just going to drop those and i
- 24:51kind of remember how to do that i think
- 24:52it was drop and a
- 24:54pd dot
- 24:56drop
- 24:57n a um
- 25:11let's go with this real quickly i always
- 25:13joke that like
- 25:16coding is just being a professional
- 25:17googler that's all that's all it is
- 25:20jeez louise that couldn't have been
- 25:22easier drop nah drop nah i was right
- 25:25boom
- 25:26let's see what it does now do i have
- 25:29pandas installed
- 25:31that's the question
- 25:34pandas has no attribute
- 25:38called dropna
- 25:40i got pandas
- 25:44[Music]
- 25:46i always do that
- 25:47i put pd
- 25:49but it's actually you have to call the
- 25:51the
- 25:52panda the data frame okay so let's go
- 25:55ahead and print that
- 25:57by the end of this we're going to have
- 25:58an algo working like it's going to work
- 26:02so
- 26:03am i going crazy yeah i am going crazy
- 26:08drop underscore nah who
- 26:11stop it
- 26:13who are you what are you thinking
- 26:18okay
- 26:19sweet
- 26:20it didn't drop now
- 26:40this is cody this is welcome to
- 26:43welcome to the show
- 26:45fishframe.drop 9.
- 27:03hmm
- 27:05maybe i need to put the uh
- 27:15all right whatever this isn't too
- 27:16important i'll get back to that
- 27:18um let's go ahead and so let's run this
- 27:21again make sure that we have the smas in
- 27:23there
- 27:26sorry i'm really into data science as
- 27:28well and machine learning so this type
- 27:31of stuff just kind of annoys me i feel
- 27:33like you know with machine learning you
- 27:35always want to get rid of rid of the
- 27:37nans
- 27:38the nons i really like indian non-2 but
- 27:42that's not the point
- 27:44but there's just no point right now for
- 27:46me to get rid of the n a n so i'm not
- 27:48gonna do that um
- 27:51sorry for getting into that but that's
- 27:52what codeine is you go down freaking
- 27:54rabbit holes
- 27:55so i have the sma 20 i think i want to
- 27:58go ahead and put another sma in there
- 28:00just in case let's do uh
- 28:02let's do a couple more sma
- 28:05no no i'm going down another rabbit hole
- 28:07let's not do that
- 28:10let's go ahead and make the 15 minute
- 28:11sma
- 28:13because remember we're gonna be buying
- 28:18around the 15 minutes i mean so let's
- 28:20just copy this
- 28:22and let's call this uh daily sma let's
- 28:24call this uh
- 28:3015.
- 28:35f-15 sounds good to me
- 28:37starting
- 28:4315 minute sma let's change this to 15
- 28:45minutes
- 28:46and then how many
- 28:48what is
- 28:50how many hours is that
- 29:03okay that's a lot it's a lot of data 15
- 29:06minutes 100 bars 15 minutes should be
- 29:08fine
- 29:12bars that's fine
- 29:15df
- 29:18dff let's do that dff
- 29:22so we're essentially just using the same
- 29:27same code but we're changing things up
- 29:29because remember now we're getting the
- 29:3015 minute sma
- 29:35dff
- 29:36okay does that look good
- 29:38to you it looks okay we're getting the
- 29:40data
- 29:41we're formatting the data
- 29:44we're changing the timestamp
- 29:47and we're creating the 20 sma
- 29:51but
- 29:52it's called 15
- 29:55and it would take dff dot close and find
- 29:58the rolling 20 minutes
- 30:00sorry 20 bars so essentially this is
- 30:02gonna find the last
- 30:05yeah this should be good
- 30:06i'll explain it here in just a second
- 30:09let's do
- 30:12f15 sma
- 30:15and then let's run it see what happens
- 30:21okay so sweet sweet sweet
- 30:23we have the 15 minutes you can see it's
- 30:25every 15 minutes
- 30:27have the data the open the high
- 30:30the low the clothes the volume
- 30:33and then
- 30:34wow it's a big volume spike
- 30:38what happened
- 30:43i need to write that down we got to make
- 30:44some sort of bot based off the volume
- 30:51i've been wanting to make a capitulation
- 30:53bot
- 31:07i like using volume a lot because i
- 31:08think it's a really good indicator you
- 31:10know
- 31:11how many people are buying and selling
- 31:14i feel like that's a really good
- 31:15indicator
- 31:16um okay so we have all this data now
- 31:20we've got the sma 20 15 minute
- 31:23and we've got the other one as well the
- 31:26daily and remember the strategy here
- 31:30is
- 31:33let's go ahead and put this here
- 31:36strategies to buy
- 31:39let's just refresh our memories here
- 31:44strat determine
- 31:47the
- 31:51the trend
- 31:52with
- 31:5420 day
- 31:58sma then based off
- 32:02trend
- 32:05buy
- 32:06or sell
- 32:08to open aka short or long
- 32:12around
- 32:13the
- 32:1515 minute sma
- 32:1920 day
- 32:21so pretty simple strategy
- 32:23but it's pretty awesome that you can
- 32:24automate this right so
- 32:26let's go ahead and clean this up a
- 32:27little bit
- 32:33so
- 32:34we're good to go i'm just thinking a
- 32:36little bit what should the next steps be
- 32:38so we found the 20 sma the daily
- 32:41that's awesome
- 32:43and
- 32:47we found the 15 minute sma
- 32:49which is awesome it's awesome awesome
- 32:53and let's go ahead let's return this df
- 32:58df
- 32:59f i want to combine combine these dfs
- 33:01now do i want to do that
- 33:08yeah i think that would be useful
- 33:10just in case
- 33:14dfd
- 33:16and then we'll call this
- 33:19df
- 33:20d
- 33:21equals that
- 33:23and then df
- 33:25f
- 33:27equals that okay
- 33:29so now we have both the functions
- 33:31and
- 33:35what i want to do is combine these two
- 33:40the reason being
- 33:42is because it'll be nice to work with
- 33:44combine
- 33:45the two data frames
- 33:49okay
- 33:50so let's just make sure everything's
- 33:52working dfd
- 33:54and print
- 33:58comma df
- 34:00f okay let's run this make sure both of
- 34:02the data frames
- 34:04are out here
- 34:11what's up with this though
- 34:15why is that
- 34:17sma 20
- 34:19make
- 34:24i think i should not print them here
- 34:27let's run that back just make sure
- 34:29everything's set up correctly
- 34:38weird thing happened here the sma 20
- 34:41jumped over here
- 34:42and i don't know why
- 34:47hmm
- 34:48is it my screen maybe
- 34:56does it shift it over
- 34:59interesting
- 35:03i think it's just an error with the uh
- 35:06the shift in
- 35:08on the output but
- 35:11oh it's because i did this stupid comma
- 35:13thing yeah that's
- 35:14why okay let's try this again
- 35:28all right now let's run it let's see if
- 35:30this looks nice
- 35:33okay perfect
- 35:35so
- 35:38time stamp
- 35:40i wonder why this time stamp has a
- 35:41minute oh it's because it's the 15
- 35:43minute that's why it's wider okay got it
- 35:45got it got it
- 35:47i actually don't want to combine those i
- 35:48forgot you don't want to combine those
- 35:50because one's on the 15 minute interval
- 35:53and one's on the daily i'm sure you
- 35:54already caught that to be honest
- 35:56but you know i'm making a video as well
- 35:58so
- 35:59i'm kind of multitasking um
- 36:02let's see here next thing we want to do
- 36:06let's look at the strategy
- 36:08we're determining the trend
- 36:11with the 20-day sma
- 36:14so let's determine the trend
- 36:21i think the way to determine the trend
- 36:23is if bid
- 36:26is under
- 36:29the
- 36:3020-day
- 36:31sma
- 36:32then it's
- 36:35equals bearish
- 36:38if
- 36:42bid is over
- 36:45sorry we shouldn't do bid we should do
- 36:48no let's do bid i like bid so that's the
- 36:50reason i like to bring the bid and
- 36:52asking is because it's a more real price
- 36:54it's like what's happening right now
- 36:56you know not 15 minutes ago what's
- 36:58happening right now if bid is bigger
- 37:00than
- 37:0220 day sma
- 37:04then um
- 37:06it goes bullish
- 37:09i think i'll just go ahead and build
- 37:11that into this function here
- 37:19okay
- 37:20i need to build a function here to get
- 37:22the bid and ask def
- 37:25bid
- 37:27our ask bid bid ask ask bid
- 37:34i know that's weird to do ask then bid
- 37:36but
- 37:37for some reason i outputted the ask
- 37:39first
- 37:40when i first got started
- 37:42got started
- 37:44and now i have to stick with it or else
- 37:46i'll forget
- 37:47okay so return to ask in a bit and to
- 37:50get the bin ask it's pretty easy i think
- 37:52we just do femix
- 37:54dot um
- 37:57fetch
- 37:58fetch uh
- 38:00order book
- 38:04and then
- 38:06symbol
- 38:07which is btc
- 38:09and then let's print
- 38:12order book
- 38:16print ob
- 38:19we got to make that variable real quick
- 38:23okay
- 38:24so this should print order book
- 38:27let's mark this out
- 38:30and i just have to figure out what the
- 38:32order back book looks like
- 38:35let's do a pretty print
- 38:38no i'm not gonna do that
- 38:44let's run this real quickly
- 38:49i'm gonna mark all of this stuff out for
- 38:52now
- 38:54i don't want anything else printed
- 38:57just want a bit in the ask and what i'm
- 38:59trying to do
- 39:00i'm getting the order book right here
- 39:02and then i need to tap into this so
- 39:05to tap it this is a dictionary and it
- 39:08looks like the bids are right here
- 39:10so i would type in bids let's keep this
- 39:14up here just so
- 39:15i can see it
- 39:19so these are the the most recent bids
- 39:21three four four seven nine
- 39:24and that's the number i need
- 39:26so where am i up here okay
- 39:29let's say bid
- 39:31equals
- 39:33and that would be order book
- 39:37and then i think i'd said bids right
- 39:39yeah bids
- 39:42and then it would be
- 39:44inside here
- 39:45i think that's zero zero
- 39:47if i remember correctly
- 39:50and then the ass
- 39:55would be ask right here
- 39:59and then
- 40:00change this to ask
- 40:03ask jeeves
- 40:05let's go ahead and do that
- 40:09and
- 40:10let's mark this out let's see if this
- 40:12works it should return like a tuple
- 40:15of my two things
- 40:19ask and bid so ask should be first bid
- 40:21should be second let's see if it works
- 40:30okay there we go so this is the ask this
- 40:33is the bid perfect
- 40:36okay so what i like to do sometimes is
- 40:37just note to self here
- 40:44um zero
- 40:46equals ask and
- 40:50one
- 40:53equals
- 40:55equals bid
- 40:57and then i can put it up here
- 41:00and then i can just get rid of that not
- 41:02get rid of it i didn't get rid of it
- 41:04don't worry don't worry don't worry it's
- 41:06just
- 41:07making this a little more beautiful
- 41:09okay so now we have bid ask and why do
- 41:12we need the bid ask if bid okay so we
- 41:14need to pull in bit
- 41:17bid equals
- 41:19what's it equal
- 41:21ask bid one
- 41:28okay
- 41:30and then so if bid is under
- 41:33let's make a little if statement if
- 41:35bid
- 41:36is under the sma
- 41:41i wonder if you can compare these two
- 41:43um i don't know if you can but we'll see
- 41:47i always trip up right here
- 41:48um
- 41:51if bid is under df
- 41:54sma 20
- 41:56print
- 41:58bearish
- 42:02else
- 42:06print
- 42:08bullish
- 42:10okay i'm just doing this because
- 42:12i don't know if this is gonna work
- 42:14because the bid is
- 42:16this is a panda's data frame
- 42:19it's always a little tricky but
- 42:22we'll figure it out together don't worry
- 42:24don't worry
- 42:27when you're working with pandas it's
- 42:29always kind of
- 42:32different
- 42:34let's go ahead and print
- 42:38i can just run that
- 42:46yep that's right so
- 42:48the truth value of a series is ambiguous
- 43:04okay i know how to do this i just need
- 43:06to think a little bit so i'm thinking if
- 43:08it's worth it to do it this way or if we
- 43:10should just use
- 43:13the
- 43:14clothes the reason i don't really want
- 43:17to use the clothes though is because
- 43:18it's yesterday's clothes
- 43:20and
- 43:21things can change pretty quickly
- 43:24so like for example if there's a huge
- 43:26green bar or something we could pop into
- 43:29a
- 43:30bullish trend
- 43:34so i kind of don't want to do that
- 43:38um
- 43:41just trying to think
- 43:43the error essentially is you can't
- 43:45compare this you can't compare like a
- 43:47number
- 43:49to um
- 43:51a series
- 43:53because this is actually like a data
- 43:54frame full of numbers
- 43:57and there's a pretty easy way to fix
- 43:58that
- 44:00just kind of racking my brain
- 44:21one way i could do it is
- 44:23no i'm not gonna do it that way
- 44:51i've done this so many times
- 44:53that
- 44:54it's funny that i i don't
- 44:58have the answer right here for me
- 45:03okay so
- 45:04i think
- 45:06we're gonna try this
- 45:13okay so
- 45:14df
- 45:16dot
- 45:17d
- 45:18dot low
- 45:20df
- 45:22d
- 45:29and essentially i just need to compare
- 45:31within
- 45:38the bid um let's do 20 day sma okay
- 45:43if that is bigger than the bid
- 45:49then
- 45:54we would do
- 45:57sig which is
- 45:59for signal
- 46:01equals
- 46:04if the sma is bigger than the bid it's
- 46:07bearish
- 46:10so let's do that
- 46:12okay
- 46:18see if this works i don't know if it's
- 46:21gonna work
- 46:27okay perfect it does
- 46:31oh
- 46:33the pandas is always a little tricky to
- 46:34play with um
- 46:37so it says sell sell sell
- 46:40and i just want to make sure that's
- 46:41correct
- 46:43so the bid would be
- 46:45about
- 46:4735
- 46:4934 523
- 46:51and the sma is
- 46:54holy smokes yes also so let's just
- 46:57double check this works by flipping this
- 47:00i always like to double check because
- 47:02this is like a pretty important part of
- 47:04the code right we want this is figuring
- 47:06out the trend so
- 47:08none oh it's because i didn't do
- 47:11anything
- 47:12okay
- 47:23that's why okay so i have to set up two
- 47:24of these actually
- 47:26this is why we double check
- 47:31and then let's do this
- 47:36and let's call this buy
- 47:38so just to make sure this is clear this
- 47:40is like we're tapping into the df sma20
- 47:43if it's if the sma20 is smaller than the
- 47:45current bid this is the bid right now
- 47:48then the signal column is going to say
- 47:50bye
- 47:58sell sells out okay okay
- 48:00and
- 48:03i'm just trying to think how can we
- 48:04double check to make sure this is
- 48:06correct
- 48:07um
- 48:10oh i know how
- 48:13what if we change the bid
- 48:16to
- 48:1860 thousand
- 48:22so
- 48:23now the bid is sixty thousand that
- 48:25should be higher than the sma
- 48:28so it should say buy if this code works
- 48:30correctly this should say
- 48:33or the last few rows
- 48:36okay perfect i think it's working
- 48:38so
- 48:40let me run this one more time and just
- 48:43kind of
- 48:44talk you through it
- 48:45just in case you're
- 48:47you're interested
- 48:49kind of talking to myself at this point
- 48:51but
- 48:52essentially we pull in all the data and
- 48:53then if the current bid here
- 48:57it's actually not on here but we got the
- 48:59bid from the bid and ask the actual bid
- 49:02and ask
- 49:03if that bid is smaller than this sma
- 49:08then we should be selling we should open
- 49:10as a cell
- 49:12we should open as a cell
- 49:16so i'm just going to write some notes
- 49:18here
- 49:20for myself
- 49:26if
- 49:27some a is bigger than
- 49:31bid
- 49:33equals
- 49:35cell
- 49:37if
- 49:38sma is smaller than bid
- 49:42equals buy okay perfect perfect perfect
- 49:45perfect
- 49:47now
- 49:48i think we're really making progress
- 49:49here this is awesome
- 49:51i think we're good on this
- 49:54this function right because
- 49:56we're just trying to find the trend
- 49:59and we do find that trend
- 50:01it's going to tell us by ourselves and
- 50:02this is why i love love love love love
- 50:05algo trading because you don't have to
- 50:07think after you code it it's just like
- 50:09it is what it is computers are going to
- 50:10do it and this way you don't have to
- 50:13like be like oh my god it's going to go
- 50:14higher it's going to go lower
- 50:17oh because we all know how that works
- 50:19out so um
- 50:21all right so i think we're good to go
- 50:23here
- 50:25so let's just mark this out for now we
- 50:27don't need it
- 50:28we might need it later
- 50:31let's go back to our strategy strat is
- 50:33to determine the trend
- 50:35with 20 day sma
- 50:40done
- 50:41buy and sell to open around the 15
- 50:45minute sma
- 50:47let's do
- 50:48um
- 50:50point
- 50:51one no yeah point one percent under
- 50:54and point
- 50:56three percent
- 50:58over
- 50:59why did i pick those numbers well
- 51:03i'm kind of guessing but
- 51:05that being said that is like you know
- 51:07when i hand trade this is kind of like a
- 51:09strategy that i would try to follow i
- 51:12would see okay well we're in a trend
- 51:16let me see what the trend is and then
- 51:18let's buy or sell around the smas you
- 51:20know i think a lot of people follow
- 51:22strategies similar to this so this this
- 51:23could be all right
- 51:25but the cool thing about algo trading is
- 51:27like if you find an all right strategy
- 51:30guess what tomorrow you have another day
- 51:32and you can make that alright strategy
- 51:35better and then the next day guess what
- 51:38as long as you're healthy you wake up
- 51:40you have another day and you make that
- 51:41better and better and better so the the
- 51:44key is to just get the strategies out
- 51:46there right like every single day that's
- 51:48why you see me here
- 51:50my youtube channel is literally me
- 51:52making strategies every day because
- 51:55you know i've got a goal in my mind and
- 51:56i'm going to get there i'm just going to
- 51:57keep swimming until i get there and
- 52:00if i can share this with you
- 52:03that's amazing
- 52:05because you're going to change your
- 52:06trading forever right like it i'm not
- 52:09saying you're going to have
- 52:11i'm not guaranteeing profits or any of
- 52:13that stuff but i am guaranteeing that
- 52:16code can execute your trades for you if
- 52:19you know how to code and then it's on
- 52:22you i'm making the strategy like i'm
- 52:24going to help you as much as possible by
- 52:26creating these strategies
- 52:28on youtube and of course
- 52:30i have boot camps and whatnot that will
- 52:32really accelerate your learning but
- 52:35i'm here to help and i'm here to build
- 52:37you know so
- 52:40let's go ahead and build out the buying
- 52:42part so
- 52:44bye
- 52:49so we have the bin ask we have the smas
- 52:53we would be buying
- 52:58oh let's put a buy price
- 53:01um
- 53:01[Music]
- 53:08we need to figure out if it's a figure
- 53:10out if by or sell to open
- 53:17set
- 53:19buy or sell
- 53:21to open
- 53:23price
- 53:24and df
- 53:25those are the two things we're going to
- 53:26do right now so figure out if it's a buy
- 53:28or sell to open we know that
- 53:30we just have to pull this guy
- 53:33how do you pull it you just pull this
- 53:35over here we're gonna pull this data
- 53:37frame into this data frame we'll get
- 53:39data frames inside of data frames df
- 53:44d equals that okay so we have that data
- 53:46frame
- 53:48and then
- 53:51to get the last we want the last entry
- 53:53of that data frame so dfd
- 53:58d
- 53:58and we want the last entry of the what
- 54:01would i call it
- 54:02the signal
- 54:06sig
- 54:08negative one this should give us the
- 54:10last one
- 54:13let's just see if we can get it
- 54:17print
- 54:32holy moly what am i doing
- 54:35i just want to run this to make sure
- 54:36that we can print it
- 54:40we should go ahead and save really
- 54:41quickly
- 54:42it's always a good practice you know
- 54:58dfd say
- 55:15okay so so
- 55:21let's try this let's call this sig
- 55:27and then let's print
- 55:29save
- 55:30you one
- 55:32see if that works
- 55:39hmm
- 55:44well you know what it's a good thing we
- 55:46got google because
- 55:48i do this all the time
- 55:59okay
- 56:17do you have the highlight
- 56:29okay i could use a location if i wanted
- 56:31to
- 56:37but i kind of want to just pull pull one
- 56:40value out of data frame
- 56:52zero would do
- 56:54zero
- 56:56negative one hey
- 56:59okay i think i got it
- 57:02just use the location and try to get the
- 57:04last one
- 57:06so let me just write this down okay so
- 57:09sig equals
- 57:10df dot d
- 57:12dot i log
- 57:14slash
- 57:17negative one
- 57:19okay and then
- 57:21let's see if this prints it out
- 57:24i hope so
- 57:30hey there it is
- 57:32so okay um
- 57:36i think that should be that should be
- 57:38cool
- 57:39because we're getting the last okay
- 57:42last
- 57:43signal
- 57:46yeah the last signal
- 57:48it prints the last signal okay
- 57:51so we figured out if it's a buy or so
- 57:56and then let's say
- 57:59if sig
- 58:02equals
- 58:06cell print
- 58:10we should be opening
- 58:13as a cell
- 58:17else
- 58:19it's just
- 58:21hopefully
- 58:22the only thing else i can think of we
- 58:25should be
- 58:28opening as a
- 58:31buy
- 58:32okay i want to get rid of some print
- 58:34statements
- 58:37because there's a lot a lot a lot
- 58:40see where else we're having printies at
- 58:43that's a good one i like it
- 58:46this one i don't want
- 58:49no more
- 58:52no more profile bar
- 58:58let's run it see what happens
- 59:04we should be opening it as a cell
- 59:05perfect
- 59:06okay
- 59:07so now it knows
- 59:09it's looking at the data
- 59:12and says to me we should be opening as a
- 59:15cell
- 59:33um
- 59:35i want to make a variable here
- 59:38let's make open
- 59:47as
- 59:48by equals false
- 59:56do i need that though
- 1:00:00where am i doing this i'm doing it
- 1:00:01inside of this 15 minute thing i don't
- 1:00:03know if that's the right decision
- 1:00:05put it in this function
- 1:00:08because what are we trying to do here
- 1:00:10set buy or sell price okay that's what
- 1:00:13we're trying to do
- 1:00:14i don't even know don't know if i need
- 1:00:16all of this but
- 1:00:18so this is a true at least so
- 1:00:19essentially it's going to say it's open
- 1:00:21is by is a false or open is by as a true
- 1:00:26if it's a cell it's gonna be false
- 1:00:28else it's gonna be true
- 1:00:30so
- 1:00:31df
- 1:00:40do i need the open price yes i do
- 1:00:47set buy or sell to open price in df
- 1:00:51oh i can so i can do it here got it so
- 1:00:54i'm just gonna set the data frame df dot
- 1:00:57i think it was what f
- 1:00:59um
- 1:01:02sig
- 1:01:03equals
- 1:01:10bye
- 1:01:11no so
- 1:01:13i don't know if that's gonna work to be
- 1:01:14honest
- 1:01:16but
- 1:01:18no that's not gonna work
- 1:01:21again i'm running into that stupid
- 1:01:23pandas thing
- 1:01:33where you can't compare things when
- 1:01:35pandas okay so i'm just gonna copy this
- 1:01:36over
- 1:01:37and use this as my comparer
- 1:01:40instead of an if statement so
- 1:01:42pandas can't really do this statements
- 1:01:44in some ways because
- 1:01:48it makes sense
- 1:01:49but
- 1:01:51essentially it
- 1:01:52pandas can't do data uh compare
- 1:01:55comparing
- 1:01:58because it's a series of data not just
- 1:02:00like one piece it's like i'm trying to
- 1:02:02compare uh
- 1:02:04one thing two
- 1:02:06multiple things
- 1:02:07so let's just get rid of that
- 1:02:11now i'm gonna keep it for now okay so
- 1:02:12now we want df.location
- 1:02:15if
- 1:02:31we should put sig here
- 1:02:36sig
- 1:02:48yeah
- 1:02:50change this to f
- 1:03:09i have a better way to do this so
- 1:03:11essentially what i'm trying to
- 1:03:14to do is figure out if it should be buy
- 1:03:16or sell to open right so
- 1:03:18df.daily smi
- 1:03:21sma sig equals the last sig
- 1:03:28but i actually don't need to do this
- 1:03:30part so what i'm going to do instead
- 1:03:33is
- 1:03:38we'll make a buy price
- 1:03:42and sell price
- 1:03:45then
- 1:03:47later
- 1:03:48figure
- 1:03:50out
- 1:03:51which i should choose
- 1:03:54so buy price one and sell price two uh
- 1:03:58n2
- 1:04:00so because we want to
- 1:04:02i want to be able to you know i i'm sure
- 1:04:04my entry is not gonna be perfect
- 1:04:06so i wanna put in two so
- 1:04:09let's say d let's make a bunch of data
- 1:04:11frames here
- 1:04:16and i'm going to call this uh buy price
- 1:04:21buy price one
- 1:04:24and
- 1:04:26buy price two
- 1:04:29and
- 1:04:30sell price
- 1:04:32one
- 1:04:35and sell price too
- 1:04:41okay
- 1:04:42so we're good to go here
- 1:04:45essentially i'm making four new columns
- 1:04:47buy prices sell prices
- 1:04:48and what did we say we wanted like 0.3
- 1:04:51or something
- 1:04:530.1
- 1:04:56just copy this over
- 1:05:12and this is what we're going to be doing
- 1:05:13here buy and sell to open around the 15
- 1:05:17minute
- 1:05:18so this would be
- 1:05:31buy price one
- 1:05:36would be the 15 minute sma
- 1:05:55one person point one percent under point
- 1:05:57one percent under
- 1:05:59and
- 1:06:00point three percent over okay
- 1:06:04so what is the sma
- 1:06:06well it's up here
- 1:06:0815-minute sma
- 1:06:16value i believe
- 1:06:24times
- 1:06:261.001
- 1:06:36i gotta mark all this out
- 1:06:46let's print this df
- 1:06:48okay
- 1:06:50see if this works
- 1:07:16okay perfect buy price one
- 1:07:19would be
- 1:07:20the sma
- 1:07:23times
- 1:07:28one point zero zero one it looks about
- 1:07:30right
- 1:07:32okay perfect perfect
- 1:07:36and that's actually not right because we
- 1:07:38want it one percent under
- 1:07:40so it would be .999
- 1:07:42[Music]
- 1:07:46and then let's go ahead and copy this
- 1:07:48over
- 1:07:50and buy price two
- 1:07:54would be over
- 1:07:58bigger than one point zero zero
- 1:08:02three remember i said point three
- 1:08:03percent so move that over point three
- 1:08:05this would be point one under point one
- 1:08:08perfect
- 1:08:12and then
- 1:08:16i think that works right
- 1:08:18do i even need the other two
- 1:08:21let's just print it out and see what
- 1:08:23happens
- 1:08:30sheesh
- 1:08:31it's getting big
- 1:08:36so this would be sma 15
- 1:08:48and
- 1:08:50this will be the buy price one it'd be
- 1:08:52right under the sma 15
- 1:08:56and this would be right over the sma 15.
- 1:09:04but but but but that's why we need four
- 1:09:08columns okay i got it so this would be
- 1:09:12point one percent under the sma
- 1:09:15by one
- 1:09:17and this would be
- 1:09:18point three over the sma but remember
- 1:09:21this
- 1:09:23let's pretend the sma's right here
- 1:09:26point one under will be right here and
- 1:09:29point three over will be right here
- 1:09:31so
- 1:09:32that's good for the buys
- 1:09:35but
- 1:09:42not sure you go for the cells because
- 1:09:43we'll be shorting here at the first one
- 1:09:45and then shorting here at the second one
- 1:09:47since this is selling
- 1:09:48but then if we were going down here and
- 1:09:50the sma were down below
- 1:09:53by
- 1:09:540.1
- 1:09:56and then under 0.3
- 1:09:59okay so that's why so the buy prices
- 1:10:01they're going to be inverse so
- 1:10:03this needs to be 1.001
- 1:10:07and this needs to be
- 1:10:110.997
- 1:10:14and
- 1:10:15essentially
- 1:10:17this
- 1:10:18the sell prices need to be the inverse
- 1:10:20of that because we always want to sell
- 1:10:23higher so what i'm trying to get at here
- 1:10:24is like if the sma was down here
- 1:10:28we'd want a 0.1 above to buy right here
- 1:10:31and then our point three below be under
- 1:10:34it because that's a better bot so it's
- 1:10:35like falling into it boom fill fill but
- 1:10:38if it's up here we want the point one to
- 1:10:40be below so that'd be 0.999
- 1:10:42and then the second buy will be over
- 1:10:440.103
- 1:10:46so
- 1:10:480.999
- 1:10:49and equals
- 1:10:52equals
- 1:10:531.003
- 1:10:57okay cool cool cool i'm glad i got that
- 1:10:59um
- 1:11:01that would have been not terrible
- 1:11:03but it would have been weird
- 1:11:06we would just wouldn't have got as good
- 1:11:07of entries so
- 1:11:09that's the i mean that's the one thing
- 1:11:11about augur trading though is like
- 1:11:12you got to make sure you're you're right
- 1:11:16oh you got to be correct it's fun though
- 1:11:18because it's i'd rather be correct or
- 1:11:20wrong i'd rather be wrong through code
- 1:11:23than like emotionally like looking at
- 1:11:25the chart all day and stuff it's
- 1:11:27terrible
- 1:11:28um
- 1:11:30okay so
- 1:11:31three four okay the let's say the open
- 1:11:34three four okay
- 1:11:36this looks fine to me um
- 1:11:40all right so cool cool we've made some
- 1:11:43progress here let's go ahead and delete
- 1:11:45all this junk
- 1:11:47i don't even know what i did there but
- 1:11:49bye
- 1:11:51okay
- 1:11:53so we have a strategy now
- 1:11:58we need to figure out the exit too
- 1:12:01the entry
- 1:12:05exit
- 1:12:06i'm not gonna build a stop loss like i
- 1:12:08said like i'm just gonna yolo it it's
- 1:12:10100 we'll see what happens
- 1:12:12let me know in the comment section below
- 1:12:14if you're enjoying this you have any
- 1:12:16questions if you want to see the results
- 1:12:18later
- 1:12:19let me know comment below but um
- 1:12:23yeah this is fun
- 1:12:24we're making progress here i think we're
- 1:12:26about done too
- 1:12:27so let's just um
- 1:12:32let's print both our dfs
- 1:12:34just to check in on them see if they're
- 1:12:36still doing all right
- 1:12:38like they've changed
- 1:12:41literally why i code because things
- 1:12:43don't change okay
- 1:12:44there's a lot going on here now
- 1:12:47bp
- 1:12:48this is the one we need
- 1:12:51tells us sell
- 1:12:53boom boom
- 1:12:55and then we would make okay if we're
- 1:12:57selling we would make the first bid
- 1:12:59here at two four two eight and then the
- 1:13:02second bid will be a little bit higher
- 1:13:04so
- 1:13:05buy one
- 1:13:06buy two
- 1:13:09okay let's go ahead and make the buys i
- 1:13:12think
- 1:13:15entry and exit
- 1:13:28okay i think i think we're good to go
- 1:13:29let's go ahead and say def bot
- 1:13:33just call this bot body bop
- 1:13:37okay
- 1:13:39let's bring in all this information that
- 1:13:41we need
- 1:13:42so this one
- 1:13:46the f
- 1:13:47sma oh i already have that actually
- 1:13:51it's all there
- 1:13:53and then bid ask
- 1:13:56bid oops sorry
- 1:13:58ask equals
- 1:14:03ask bid
- 1:14:06one
- 1:14:07zero
- 1:14:09and bid equals
- 1:14:16ask
- 1:14:18bid
- 1:14:19one
- 1:14:22let's just pull all this information in
- 1:14:24here
- 1:14:26to our bot
- 1:14:36okay
- 1:14:38so we get the daily sma
- 1:14:42determines
- 1:14:44long
- 1:14:45short
- 1:14:4615-minute sma
- 1:14:50provides
- 1:14:53prices
- 1:14:58and what did i call them
- 1:15:02dp and sp
- 1:15:14okay so
- 1:15:16didn't ask those are self-explanatory
- 1:15:20let's make our entry
- 1:15:26make the screen a little smaller again
- 1:15:30and to enter this
- 1:15:34how do we want to play this
- 1:15:40of course we already set our params up
- 1:15:45so we're good to go there
- 1:15:48we've got the buy prices we've got the
- 1:15:49long short
- 1:16:17so inside the bar we need to figure out
- 1:16:18first okay
- 1:16:20make
- 1:16:21open order
- 1:16:25long or short
- 1:16:28so to see long or short it'd be d f
- 1:16:32d
- 1:16:34i just did this so i'm just going to
- 1:16:36grab it from up here i'm going to tap
- 1:16:38into that df
- 1:16:40df.lope
- 1:16:43not that one
- 1:16:48the one i did negative one remember
- 1:16:53whoa whoa whoa whoa
- 1:17:08df what was it df
- 1:17:12dot lok i think
- 1:17:17the um
- 1:17:18sig
- 1:17:20negative one
- 1:17:30do you have the i look zero
- 1:17:50i could have sworn i just wrote that
- 1:17:56anyways i must have deleted it in that
- 1:17:59whole
- 1:18:00rage quit that's why you don't rage quit
- 1:18:02that's why you don't just delete things
- 1:18:03but
- 1:18:05say print sick just to make sure
- 1:18:09and then
- 1:18:12from the bot let's run the bot
- 1:18:28bid ask
- 1:18:3092
- 1:18:31made a silly mistake though
- 1:18:46what
- 1:18:47again
- 1:18:51sheesh
- 1:18:52she sheesh
- 1:18:54fool me once for me twice for me thrice
- 1:18:57let's see
- 1:19:04okay so i got the cell perfect
- 1:19:09and we'll call that
- 1:19:12where we where we at
- 1:19:14sig
- 1:19:15um let's go ahead and get rid of that
- 1:19:19let's go ahead
- 1:19:20if sig
- 1:19:24equals
- 1:19:28by
- 1:19:30print
- 1:19:41as a buy okay
- 1:19:45else
- 1:19:52making an opening order
- 1:19:54as a
- 1:19:56cell let's run it one more time let's
- 1:19:58just make sure
- 1:19:59like i said i like to be double triple
- 1:20:01quadruple checking things because this
- 1:20:04is real money on the line
- 1:20:06uh making an opening order as a
- 1:20:09cell
- 1:20:09perfect
- 1:20:13now let's make the orders
- 1:20:21actually i need to get the order prices
- 1:20:34df
- 1:20:39dff
- 1:20:42dot i lock
- 1:20:46negative one
- 1:20:49um price what was that name bp bp1
- 1:20:54bp1
- 1:20:57that's not how i spelt it though
- 1:21:01bp
- 1:21:02one equals
- 1:21:04and then bp2 equals that same thing but
- 1:21:08a little different so i'm going into the
- 1:21:11data frame getting the last one now i'm
- 1:21:14getting buy price two
- 1:21:16now let's do the same thing for sale
- 1:21:18price
- 1:21:29change to s's
- 1:21:32things like this just make me fall in
- 1:21:34love over and over again with coding
- 1:21:37because it just changing letters is so
- 1:21:40much better than looking at charts
- 1:21:43oh gosh
- 1:21:45okay so
- 1:21:49print
- 1:21:50f
- 1:21:52this is
- 1:21:53bp
- 1:21:551
- 1:21:57this is
- 1:21:59bp
- 1:22:002.
- 1:22:02little f literal action here
- 1:22:06bp
- 1:22:082.
- 1:22:10vp
- 1:22:12one
- 1:22:13perfect
- 1:22:21let's change the letters again
- 1:22:29okay perfect perfect
- 1:22:33let's just run it
- 1:22:43okay making an open order of cell this
- 1:22:45is sell price one so
- 1:22:48three four two eight one and three four
- 1:22:51four one eight let's go over to my
- 1:22:53exchange change change
- 1:22:56and see what's going on here
- 1:23:00ah this is such a great example of like
- 1:23:03well i'm an algo trader because i would
- 1:23:05just try to short this right here
- 1:23:07but in reality i don't know
- 1:23:09i don't know
- 1:23:11i think my algo would too but
- 1:23:14i don't know i don't know
- 1:23:16i wouldn't be able to exit but with my
- 1:23:19mind though
- 1:23:20so a current price is three four five
- 1:23:23two eight
- 1:23:25three four five to it
- 1:23:35and
- 1:23:37the sma is three four
- 1:23:41sell price one is three four
- 1:23:43two eight one
- 1:23:46three four
- 1:23:48four one eight
- 1:23:50so we must just be over the 15-minute
- 1:23:52sma right now
- 1:24:00hmm put the sma on here
- 1:24:04um
- 1:24:11whoa whoa whoa whoa whoa whoa
- 1:24:15there's a lot i just want a simple
- 1:24:17estimate
- 1:24:19simple
- 1:24:20moving
- 1:24:23average
- 1:24:25community scripts favorite scripts
- 1:24:29technicals
- 1:24:31indicators
- 1:24:35so what i'm thinking is happening right
- 1:24:36now is just
- 1:24:39this is a smoothened
- 1:24:42moving average
- 1:24:43i think we're just over
- 1:24:46sma
- 1:24:48so
- 1:24:51let's get rid of this one
- 1:24:55and let's make this what did i say what
- 1:24:56were we doing at 20
- 1:24:5820 sma
- 1:25:00style let's make it a little darker
- 1:25:03a little bigger
- 1:25:04oh
- 1:25:06there we go
- 1:25:12okay
- 1:25:13so
- 1:25:16let's change this to 15 minutes
- 1:25:20okay that's that's the thing so this
- 1:25:22looks a little weird because we're over
- 1:25:24the sma
- 1:25:25now the thing that i said at the very
- 1:25:27start though won't let us submit this
- 1:25:29order which is awesome
- 1:25:32because i did post only orders i've got
- 1:25:34another video about that but essentially
- 1:25:36it allows you to say hey if this isn't
- 1:25:38going to work as a limit order just
- 1:25:40cancel it
- 1:25:45speaking of that i'm going to go ahead
- 1:25:47and put a time sleep
- 1:25:52time dot sleep i'm gonna put um
- 1:25:5610 minutes now let's do five minutes
- 1:25:59because
- 1:26:00if the the orders do get submitted and
- 1:26:04canceled because the sma is higher
- 1:26:07well
- 1:26:08i don't want to
- 1:26:14i don't want to um
- 1:26:16i don't want to just keep sending orders
- 1:26:18in okay so we're good to go we're good
- 1:26:20to go we're good to go we're back on
- 1:26:21track so we need to buy if signal equals
- 1:26:24buy
- 1:26:26print making buy order bp1
- 1:26:31i got to figure out the size
- 1:26:37i already put size of one at the very
- 1:26:39top
- 1:26:40but
- 1:26:41let's see how much i can buy
- 1:26:43i'm gonna i have leverage on here let's
- 1:26:4725 x yolo that's crazy
- 1:26:49but
- 1:26:50whatever
- 1:26:53btc usd margin
- 1:26:56okay
- 1:26:58let's say 10
- 1:27:00how much does that cost
- 1:27:0114
- 1:27:03okay let's do 50 then
- 1:27:05yeah 50 contracts will be good
- 1:27:10so let's change our size to 50
- 1:27:13and
- 1:27:17that's position size is 50
- 1:27:19but
- 1:27:21i'm gonna have an open size too
- 1:27:24why
- 1:27:26watch
- 1:27:29equals
- 1:27:31you know it could be more sophisticated
- 1:27:32than that but i'm essentially taking my
- 1:27:35position size which is 50 and making
- 1:27:38open size half of that so i can do two
- 1:27:40orders because i have bio-order one by
- 1:27:42order two so let's make these buy
- 1:27:44orders um i want to make sure to do this
- 1:27:47correctly i don't i'm not going to use a
- 1:27:49stop stop loss like i said but
- 1:27:53i am going to only do limit orders
- 1:27:55that's for sure
- 1:27:57so
- 1:28:00themex
- 1:28:02v mix
- 1:28:04dot
- 1:28:06create
- 1:28:07limit buy order
- 1:28:09and then we need to pass in the symbol
- 1:28:12we need to pass in
- 1:28:17um
- 1:28:18open size
- 1:28:20we need to pass in
- 1:28:22the bid
- 1:28:24so bp one
- 1:28:27and then the params so this is what i
- 1:28:30was talking about so in this example
- 1:28:32right now like how the market currently
- 1:28:35is
- 1:28:36we're above the sma
- 1:28:38but i believe on the daily
- 1:28:41so remember our the way our bot works is
- 1:28:44it sees where we're at
- 1:28:46and if we're under this yellow line
- 1:28:48right here
- 1:28:49we're in a bear trend and we're only
- 1:28:51selling to open
- 1:28:53but then it's coming over here and
- 1:28:55saying hey
- 1:28:56the where are we going to open this at
- 1:28:58well we're going to do this around the
- 1:29:0015 minute
- 1:29:01we're going to do 0.1 under and 0.3 over
- 1:29:04but in this situation we just pop
- 1:29:06through this so it's going to send the
- 1:29:08orders but they're going to get
- 1:29:10cancelled right away because i only
- 1:29:12accept
- 1:29:13limit orders if you go ahead and we look
- 1:29:15at this params here this is what i set
- 1:29:17up at the start params times time and
- 1:29:20force means post only aka if this
- 1:29:22doesn't work as a limit order do not
- 1:29:26accept my order
- 1:29:28pretty much never ever
- 1:29:30ever please ever ever
- 1:29:33never
- 1:29:34let me be a market order
- 1:29:36so we're doing two orders so let's do
- 1:29:38this boom boom boom
- 1:29:42and bp2 will be the second one and then
- 1:29:45we want to do the same thing for
- 1:29:47the cell orders
- 1:29:51now i have to be sure to do this one
- 1:29:53right
- 1:29:54because
- 1:29:55this
- 1:29:56s open size symbol symbol i got to make
- 1:29:59sure to make it sell
- 1:30:01i have done that before whereas like i
- 1:30:03copy like it's sometimes good to copy
- 1:30:05but sometimes bad so this is a sell
- 1:30:07price create order blah blah blah then
- 1:30:09we'd sleep 300 seconds and i believe 300
- 1:30:11seconds is 5 minutes
- 1:30:14i think we're good
- 1:30:19i think we are good to go i'm going to
- 1:30:21pause these sleeps here
- 1:30:23because
- 1:30:26just for example purposes what we're
- 1:30:28testing
- 1:30:31this shouldn't fill any orders because
- 1:30:32they're pretty out there
- 1:30:34what else do we need to do
- 1:30:36you know normally not normally actually
- 1:30:38i don't always use a stop light loss
- 1:30:40because i use my position size as my
- 1:30:42stop-loss and like
- 1:30:44just hey if it
- 1:30:46works it works but if it doesn't it
- 1:30:48doesn't and then just make sure to
- 1:30:50control your push position size that's
- 1:30:51how i control my risk a lot of the time
- 1:30:53uh some some of my strategies though
- 1:30:56definitely definitely definitely
- 1:30:57definitely use a stop loss
- 1:30:59um the one thing i think we're missing
- 1:31:01here
- 1:31:02is
- 1:31:04the exit
- 1:31:06so we got to do that
- 1:31:09um i kind of want to test this out
- 1:31:10though
- 1:31:12let's just run it
- 1:31:13what's the worst that could happen
- 1:31:15i buy a hundred dollars worth
- 1:31:22see if it makes the orders
- 1:31:26okay perfect you can see it made the
- 1:31:27orders but cancel them immediately
- 1:31:30because of the post only that's awesome
- 1:31:32once this drops down it will try to make
- 1:31:34the orders again you know what we'll
- 1:31:36loop that here at the end just so it
- 1:31:38keeps running
- 1:31:39but perfect perfect
- 1:31:48okay
- 1:31:49so i need to make an exit
- 1:31:53death
- 1:31:54exit
- 1:31:59and
- 1:32:01i think what i'm going to do with this
- 1:32:03is
- 1:32:04make an exit based on
- 1:32:07my target
- 1:32:09percentage
- 1:32:11so let's go ahead and make a target
- 1:32:14i'm gonna do uh
- 1:32:1720
- 1:32:20no
- 1:32:22i'm risking a lot here
- 1:32:24because i'm going i'm not having a stop
- 1:32:26loss so i need to think this through i'm
- 1:32:28going to do 30 so it's a little higher
- 1:32:30but since i'm using leverage that's only
- 1:32:32really like a one percent move
- 1:32:35um
- 1:32:37i think i wanted 25
- 1:32:39okay so it'll take me out of the market
- 1:32:4125
- 1:32:44and
- 1:32:45i don't want to just put a i guess i
- 1:32:48could just put a
- 1:32:52take profit
- 1:32:57hmm
- 1:33:00i could just set up a take profit on the
- 1:33:02buy orders
- 1:33:08i actually like this way better so i'm
- 1:33:10gonna set up a function and then in that
- 1:33:12function i'm gonna say hey if we hit my
- 1:33:13target
- 1:33:19if we hit target
- 1:33:25then close
- 1:33:29so
- 1:33:29[Music]
- 1:33:31how do we do this
- 1:33:32we have to tap in now this is going to
- 1:33:34be a little tricky because we have to
- 1:33:35tap into a bunch of dictionaries but i
- 1:33:38think this is the last thing
- 1:33:44yeah i'm pretty sure this is the last
- 1:33:46thing so
- 1:33:48let's see how we're to pull this off
- 1:33:55let me think about this for a second
- 1:34:16so i think i'm gonna make this
- 1:34:19um
- 1:34:22it's pretty much gonna look
- 1:34:25into my current positions
- 1:34:30and
- 1:34:32yeah okay so it's going to look into my
- 1:34:33current positions
- 1:34:36and
- 1:34:39it will run every time the bot runs
- 1:34:43right so
- 1:34:49i think that makes sense
- 1:35:16yeah so essentially we're going to have
- 1:35:17it check this every time so exit
- 1:35:23we're going to run this
- 1:35:24checking to see
- 1:35:28i gotta be able to type
- 1:35:31print
- 1:35:32checking to see if it's time to
- 1:35:37exit
- 1:35:43okay
- 1:35:44so that looks good to me
- 1:35:48um
- 1:36:00i'm just trying to figure out how i go
- 1:36:02about this because this is going to be a
- 1:36:05fairly big function but it's not going
- 1:36:07to be crazy big
- 1:36:09that being said
- 1:36:16i just gotta make sure to do it right
- 1:36:20okay
- 1:36:22i'm gonna call this p l close p l close
- 1:36:25just because that's a little more
- 1:36:26descriptive for me
- 1:36:28and now i can know hey
- 1:36:33checking if we hit our piano
- 1:36:37okay
- 1:36:38now the first thing we want to do
- 1:36:40is set up some params
- 1:36:44params
- 1:36:46equal
- 1:36:48type this is because i'm using
- 1:36:53phoenix
- 1:36:54i gotta like do some weird stuff with
- 1:36:58with the codes of exactly how the um
- 1:37:03how to tap into my open positions
- 1:37:06so it's going to look something like
- 1:37:08that it should be a dictionary though
- 1:37:12okay
- 1:37:14and then we want to say position
- 1:37:17dictionary
- 1:37:20position dictionary equals femix.fetch
- 1:37:28fetch
- 1:37:29positions
- 1:37:32and then pass in the params so these
- 1:37:34params are because i'm using the
- 1:37:37contract
- 1:37:38um things are a little different so
- 1:37:41i need to print this out now because now
- 1:37:43i need to figure out
- 1:37:45how to get into
- 1:37:47that
- 1:37:49get into the dictionary and then figure
- 1:37:51out like what my position size is
- 1:37:55i need to put a position on
- 1:37:57in order to figure this out so
- 1:37:59let's see here let's just mark it
- 1:38:02let's uh
- 1:38:04i'm gonna short it
- 1:38:07okay
- 1:38:08perfect perfect just lost a little bit
- 1:38:10of money
- 1:38:11see how that goes for me
- 1:38:14um let's do pnl close
- 1:38:16and let's throw that
- 1:38:20here and now i'm looking for a
- 1:38:22dictionary
- 1:38:29okay there it is
- 1:38:31that's the one
- 1:38:33what just happened
- 1:38:39oh it's ah shoot i gotta be careful
- 1:38:42about that it just ran the bot
- 1:38:44um but luckily it just canceled the
- 1:38:46orders
- 1:38:48that reminds me actually i need to do
- 1:38:49something else too
- 1:38:52i need to cancel the orders
- 1:39:02okay so i got that
- 1:39:05let's do a
- 1:39:09rando.json
- 1:39:11let's throw that in there
- 1:39:13let's format it
- 1:39:16okay perfect perfect
- 1:39:19i'm going to come back to that in just a
- 1:39:20second sma bot
- 1:39:22um
- 1:39:23create
- 1:39:24limit buy orders
- 1:39:26i need to cancel all orders before i
- 1:39:29make these or else it's just going to
- 1:39:31keep making more and more orders thank
- 1:39:33god i remember
- 1:39:35phoenix.cancel
- 1:39:37all orders
- 1:39:39of the symbol
- 1:39:49oh that's another thing
- 1:39:52only run
- 1:39:56if not in position
- 1:40:01okay
- 1:40:03if
- 1:40:04in
- 1:40:06position
- 1:40:08equals
- 1:40:10false
- 1:40:12run this
- 1:40:14hey i almost forgot that part almost
- 1:40:16forgot that part and that would have
- 1:40:18been bad
- 1:40:20because what happened or what would have
- 1:40:23happened if i didn't just put in
- 1:40:24position
- 1:40:25what would have happened
- 1:40:27is
- 1:40:30i would have just kept buying over and
- 1:40:32over and over again
- 1:40:36so we need to make sure to get in
- 1:40:38position somewhere
- 1:40:44let's return it from here
- 1:40:57okay so two things i'm doing now i got
- 1:40:59the position dictionary i need to figure
- 1:41:01out how to figure out if um
- 1:41:08i need to dive in here and
- 1:41:12figure out what my p l is so i have to
- 1:41:13figure out like what leverage i'm using
- 1:41:16um
- 1:41:18and the size
- 1:41:20okay
- 1:41:21so
- 1:41:22checking to see if time to exit
- 1:41:24so it looks like btc is zero so zero
- 1:41:28dictionary and then i would need
- 1:41:32let's set that up first actually
- 1:41:35position dictionary
- 1:41:40equals
- 1:41:42position dick
- 1:41:44at zero okay so now
- 1:41:48we have that and then we have to figure
- 1:41:50out what side
- 1:41:51of order it is
- 1:41:53so i'm looking for something inside okay
- 1:41:55side
- 1:41:58perfect
- 1:42:00side equals position dictionary
- 1:42:05of side
- 1:42:07now we should have the side
- 1:42:09and
- 1:42:11we gotta get the entry price entry
- 1:42:15price
- 1:42:16equals
- 1:42:22position dictionary
- 1:42:29position dictionary and then
- 1:42:32i need the price so the average entry
- 1:42:34price what
- 1:42:37should be average avg some
- 1:42:43pretty much looking for the price
- 1:42:44because i need to figure out the
- 1:42:47average entry price ep average entry
- 1:42:50price okay perfect grab that
- 1:42:55perfect perfect
- 1:42:57and i want to make that float actually
- 1:43:03perfect perfect
- 1:43:04um
- 1:43:10let's get the leverage
- 1:43:13leverage
- 1:43:15equals
- 1:43:17position dictionary
- 1:43:20and i believe this one's just called
- 1:43:22leverage
- 1:43:30okay i also want to make that float
- 1:43:34i guess it doesn't need to be a float
- 1:43:35yeah actually no float's good floats
- 1:43:36good
- 1:43:43float okay now what
- 1:43:47i need the current price
- 1:43:52equals um
- 1:43:54how do i get the current price i need
- 1:43:55the bid and ask
- 1:43:57where has been an ass
- 1:44:04at ah the bid here
- 1:44:07this is how much somebody's willing to
- 1:44:09buy at so i'll call that current price
- 1:44:17right
- 1:44:18that makes sense
- 1:44:19because if somebody's willing to bid
- 1:44:21that means they're willing to buy so
- 1:44:23that means that's the current price
- 1:44:25in my opinion at least
- 1:44:27we'll see if that works out for us
- 1:44:33let's go ahead and print some stuff out
- 1:44:35and just see if this is working print f
- 1:44:39side
- 1:44:48what else
- 1:44:49entry
- 1:44:51price
- 1:44:58just wanna make sure i have all of this
- 1:44:59information before i move forward
- 1:45:03lav
- 1:45:07equals leverage
- 1:45:10what else do i need
- 1:45:12i think we're good here i'm gonna close
- 1:45:14this up
- 1:45:16um close or not close it but let's see
- 1:45:20here
- 1:45:23hey
- 1:45:33let's just say imposition is true for
- 1:45:34now
- 1:45:36so it doesn't run
- 1:45:38okay let's see what happens
- 1:45:44what i'm looking for is that thing i
- 1:45:46just did average entry price
- 1:45:48position dictionary key area key error
- 1:45:51why
- 1:45:53i don't get that
- 1:46:00hmm
- 1:46:04i just saw that there's average entry
- 1:46:05price right here
- 1:46:12average introvert
- 1:46:19where'd i go wrong here
- 1:46:22where did i go wrong
- 1:46:33maybe i'll just do enterprise and see if
- 1:46:35that works
- 1:46:44run it back
- 1:46:53perfect perfect perfect
- 1:46:56so the side is short
- 1:47:00leverage
- 1:47:08huh
- 1:47:09i feel like i'm in a different
- 1:47:11dictionary
- 1:47:12because it should say sell
- 1:47:16the side should say sell not sure
- 1:47:26side equals cell
- 1:47:28so
- 1:47:29another side
- 1:47:31side
- 1:47:32equals short
- 1:47:36side equals cell
- 1:47:39side equals short hmm
- 1:47:42so what's going on here
- 1:47:44i want to be in this so maybe i need to
- 1:47:46tap into info
- 1:48:06position dictionary is zero
- 1:48:12info maybe
- 1:48:51whatever that works
- 1:48:52uh we'll just do this then we'll just do
- 1:48:54uh
- 1:48:55keep it at zero
- 1:48:58and knowing that it's short or long
- 1:49:06okay
- 1:49:08so now we need to figure out
- 1:49:12because now we're trying to look at our
- 1:49:13p l right we're trying to look at our p
- 1:49:15l so we need to figure out
- 1:49:17if the side
- 1:49:19if side equals
- 1:49:21um let's say
- 1:49:23long
- 1:49:28i need to make sure that it says that
- 1:49:30word long
- 1:49:33so i'm just gonna
- 1:49:35look at that i made a little money mark
- 1:49:36it
- 1:49:37sell this
- 1:49:39and then it's long it
- 1:49:42and let's run this
- 1:49:44i want to make sure that that word says
- 1:49:46long
- 1:50:08we know the first word it says short
- 1:50:10okay perfect it says long okay so if
- 1:50:12side is long
- 1:50:15then the difference
- 1:50:18will be the current price
- 1:50:20minus
- 1:50:21the entry price right because if it's
- 1:50:25long it's the difference is going to be
- 1:50:27a little different than the
- 1:50:29if it's short it's going to be the
- 1:50:31opposite right difference equals entry
- 1:50:33price
- 1:50:34minus
- 1:50:36current price okay so now we have the
- 1:50:39difference
- 1:50:41i want to find the percentage um and i
- 1:50:43have to do this in a try block because
- 1:50:45it might not return so
- 1:50:47percentage equals
- 1:50:49round
- 1:50:53let's round it so we have to do that and
- 1:50:55then we want to make another one and
- 1:50:57another one diff
- 1:50:59entry price
- 1:51:01and then multiply that by the leverage
- 1:51:06and i just want uh
- 1:51:0810 spaces
- 1:51:10okay and then if that doesn't work and
- 1:51:12the reason this won't work sometimes is
- 1:51:14because we won't have a
- 1:51:18we won't have a position
- 1:51:21so let's go ahead and say
- 1:51:24print
- 1:51:26f
- 1:51:28side nope i don't need that
- 1:51:31diff
- 1:51:34and then also the perk
- 1:51:41so i want the difference
- 1:51:44and the percentage
- 1:51:53okay so this it shows okay there it is
- 1:51:56uh the difference
- 1:51:59between our entry and the current price
- 1:52:02is
- 1:52:02negative 10
- 1:52:04and this is our percentage actually
- 1:52:05that's not it means close to our
- 1:52:07percentage we just have to make some
- 1:52:10[Music]
- 1:52:11updates
- 1:52:13so let's go ahead and say perk
- 1:52:16part
- 1:52:18equals
- 1:52:19100 times perk because it was a decimal
- 1:52:23prior
- 1:52:24and we can say print
- 1:52:27the
- 1:52:28this
- 1:52:30this
- 1:52:31is our piano
- 1:52:35percentage
- 1:52:38and then we can double check it
- 1:52:41because you can never
- 1:52:42be
- 1:52:44sure
- 1:52:46so this should
- 1:52:48give us our p l percentage
- 1:52:50let's go check what our p l percentage
- 1:52:52is
- 1:52:53word
- 1:52:54negative point eight four
- 1:52:56percent but
- 1:52:59let's hover over point one or one
- 1:53:02percent
- 1:53:06point four three percent okay this looks
- 1:53:09about right um it's always just a little
- 1:53:11bit different because some using mark
- 1:53:13price i'm just using last price it's
- 1:53:150.38 versus 0.4
- 1:53:183. that's really close i did my own math
- 1:53:21here that's another thing so
- 1:53:23um to be that close it's great okay so
- 1:53:26now we have the p l percentage
- 1:53:29and remember our target
- 1:53:32is 30 or 25
- 1:53:38let's see hmm
- 1:53:55um
- 1:53:56how would we do this
- 1:54:03okay so
- 1:54:04if the percentage is bigger than zero
- 1:54:06that means there's a percentage
- 1:54:08we can all agree on that
- 1:54:10uh okay if percentage is bigger than
- 1:54:12zero we gotta do some stuff print
- 1:54:15we are
- 1:54:17in
- 1:54:18a winning position
- 1:54:23and then
- 1:54:26if the percent because we're making our
- 1:54:28exit here right so what i'm trying to do
- 1:54:31here is if a percent goes over our
- 1:54:32target size then we
- 1:54:36we
- 1:54:37kill the position
- 1:54:40because we want
- 1:54:41right
- 1:54:42okay so that makes sense to me so if
- 1:54:45perk is bigger than the target
- 1:54:51print
- 1:54:54um
- 1:54:55smiles
- 1:54:58starting
- 1:54:59the kill switch
- 1:55:02because
- 1:55:03we
- 1:55:04hit our
- 1:55:06target
- 1:55:12of sorry you can't see that
- 1:55:24target
- 1:55:27little ff there
- 1:55:30perfect
- 1:55:36and then we want to go ahead and say
- 1:55:42p l close
- 1:55:44equals true that will be useful later
- 1:55:48and then we want to call our kill switch
- 1:55:52which we haven't created yet
- 1:55:56so let's create that
- 1:56:08this kill switch is going to gracefully
- 1:56:10take us out
- 1:56:15so essentially instead of like market
- 1:56:17closing where you have to pay a bunch of
- 1:56:18fees i like to limit close and
- 1:56:21uh i'll build that here in a second
- 1:56:31okay starting the kill switch let's go
- 1:56:34back down here
- 1:56:35figure this all out
- 1:56:37so if percentage is over target print
- 1:56:39kill switch
- 1:56:43else
- 1:56:47print
- 1:56:49we have
- 1:56:51not hit our target
- 1:56:54yet this is actually where i would put
- 1:56:57in a um
- 1:57:04i don't want to do else do i
- 1:57:08i do want to do well this is also where
- 1:57:10i'd put a stop loss but i'm not going to
- 1:57:12do it for this one i'm using the
- 1:57:15position size as my stop loss so
- 1:57:19let's go ahead and put another else over
- 1:57:21here at the end of this you know print
- 1:57:26we are
- 1:57:27not
- 1:57:28in position
- 1:57:32okay
- 1:57:38how's this look this looks good to me
- 1:57:44i'm gonna put p l close up here
- 1:57:48before we start this
- 1:57:50as false
- 1:57:52i think it's default false actually so i
- 1:57:55didn't need to do that but
- 1:57:56that's fine
- 1:58:00i'm getting thirsty i should have
- 1:58:01brought some water over here but i think
- 1:58:03we're almost finished so i need to call
- 1:58:05that kill switch
- 1:58:06print that
- 1:58:07i think we're good on this part
- 1:58:11um
- 1:58:14let's just do some more print statements
- 1:58:16because i love them
- 1:58:18uh
- 1:58:19just finished checking
- 1:58:23p l close just so we know and then let's
- 1:58:27return p l
- 1:58:29close
- 1:58:30so essentially this is going to go
- 1:58:32through it's going to figure out all the
- 1:58:34information i need right it's
- 1:58:37like my position side um the price
- 1:58:42the leverage
- 1:58:44and then it's going to do a little math
- 1:58:47based on if it's long then the current
- 1:58:49price or the difference price difference
- 1:58:51would be the current price minus the
- 1:58:53entry price
- 1:58:58right
- 1:58:59because the entry price would be lower
- 1:59:01current price
- 1:59:06yeah that's right that's right and then
- 1:59:08down here it would try to round this
- 1:59:10percentage and do all this math to find
- 1:59:11the percentage and then multiply the
- 1:59:13percentage
- 1:59:14should put that here
- 1:59:17well i don't need this anymore actually
- 1:59:20and then it you know multiplies the
- 1:59:21percentage and this is our p l
- 1:59:23sets p l close to false which it should
- 1:59:26do by by default
- 1:59:28um if percentage is over zero that means
- 1:59:32we're in position
- 1:59:34oh snap i need in position too
- 1:59:41yes
- 1:59:45equals true
- 1:59:52all right so imposition is now true
- 1:59:56i'm going to put in position as false
- 1:59:58here i don't know why i do this but
- 2:00:01just to like remind me i guess that
- 2:00:05we're using that imposition is false and
- 2:00:08then if the percentage is over
- 2:00:10zero in position is true
- 2:00:14but snap if it's less than zero its
- 2:00:17imposition is true too
- 2:00:20hmm
- 2:00:32so i need to put a lift here
- 2:00:38perk is under zero because we might be
- 2:00:40in a losing position
- 2:00:42print
- 2:00:44we
- 2:00:45we are in a losing position
- 2:00:49but
- 2:00:50holding on
- 2:00:53and then this would be in
- 2:00:55position
- 2:00:57equals true
- 2:00:59just like that
- 2:01:01right
- 2:01:02so it's false
- 2:01:03and then it's true if it's above or
- 2:01:05under
- 2:01:07and then else it stays false
- 2:01:10so we don't need to change anything and
- 2:01:12then we return
- 2:01:13p l close
- 2:01:15equals
- 2:01:20r
- 2:01:24not here though
- 2:01:27because we don't want to piano close yet
- 2:01:30we want the p l close to be false
- 2:01:32if it's over zero we are in a winning
- 2:01:34position if perk is over target then p l
- 2:01:37closes true and we hit kill switch
- 2:01:41and
- 2:01:42okay i think we're good to go
- 2:01:47p l close
- 2:01:50let's do this so i can carry this
- 2:01:53so zero is pinot close
- 2:02:00and
- 2:02:02one is
- 2:02:04in position right
- 2:02:09p l close
- 2:02:11piano close pnl close
- 2:02:15okay so let's take this on down and
- 2:02:18before we make the kill switch i think
- 2:02:19the kill switch is the last thing so i'm
- 2:02:21getting pretty excited because we're
- 2:02:22really close
- 2:02:24so if in position
- 2:02:32in position
- 2:02:35equals
- 2:02:40[Music]
- 2:02:41p l
- 2:02:42close
- 2:02:45one okay
- 2:02:46i should say it's true or false i can
- 2:02:48delete this now
- 2:02:51and
- 2:02:52wait right
- 2:02:53yeah yeah
- 2:02:58i always forget these little guys
- 2:03:00so imposition should be set to whatever
- 2:03:02or yes true or false if it's true
- 2:03:07it's just gonna
- 2:03:09what's it gonna do it's gonna do nothing
- 2:03:15let's go ahead and
- 2:03:17it would still work without this but
- 2:03:19print
- 2:03:22we are
- 2:03:25in position
- 2:03:27already
- 2:03:29so not
- 2:03:30making
- 2:03:32new
- 2:03:34orders
- 2:03:36perfect perfect
- 2:03:40let's get rid of some of these print
- 2:03:41statements
- 2:03:48i pretty just want pretty much just want
- 2:03:49the text that i'm sending i don't want
- 2:03:51the dfs
- 2:04:00these two i don't want those
- 2:04:02pretty much
- 2:04:03and i think there might be another one
- 2:04:05print df
- 2:04:08i just want the data that i write
- 2:04:12okay
- 2:04:13i think we're good to go
- 2:04:16so if i run this now it should say we're
- 2:04:19not making a position because it's not
- 2:04:21like we're not
- 2:04:29we are in position already so not making
- 2:04:31new orders perfect perfect
- 2:04:34looks like we're down
- 2:04:361.337 percent
- 2:04:38we have a side of long entry price
- 2:04:41leverage 25. this is looking really good
- 2:04:44i don't know why it repeats the data
- 2:04:49oh it's because i call the function
- 2:04:51multiple times
- 2:04:53i don't care about that right now i just
- 2:04:55want to get this working
- 2:04:57to be honest i'm very thirsty
- 2:05:00so i got to make this kill switch i had
- 2:05:02that big cup of coffee and you know when
- 2:05:03you have coffee and
- 2:05:04you don't have much water
- 2:05:08i'm feeling that way
- 2:05:09i should probably eat something too
- 2:05:12but
- 2:05:13let's get this done i think i'm i'm
- 2:05:15almost done we just need to make the
- 2:05:16kill switch so how do we make the kill
- 2:05:19switch
- 2:05:20the kill switch is pretty much just a
- 2:05:22graceful close that's what i like to
- 2:05:24call it at least
- 2:05:26instead of like market closing
- 2:05:29because
- 2:05:31you're
- 2:05:33either your stop loss goes off or your
- 2:05:37target gets hit
- 2:05:38instead of doing that
- 2:05:40i like to just be graceful with it
- 2:05:42because femix actually pays you to
- 2:05:45create limit orders
- 2:05:47so you have to pay
- 2:05:49point zero
- 2:05:50point zero seven five percent if you
- 2:05:55use market orders but you get paid point
- 2:05:58zero two five percent if you
- 2:06:01make
- 2:06:03limit orders
- 2:06:05okay
- 2:06:10so first we need to see if we have open
- 2:06:12positions
- 2:06:17and
- 2:06:22i probably could just say that in here
- 2:06:25imposition equals true
- 2:06:27yeah
- 2:06:29perfect
- 2:06:41i'm going to call this open position
- 2:06:44equals that and that
- 2:06:48this should give the true house
- 2:06:51perfect
- 2:06:53and then law
- 2:06:56uh let's get it long true or false
- 2:07:01long equals
- 2:07:04true or false but how would i do that
- 2:07:22do i need that we'll see
- 2:07:32i should pass some more information
- 2:07:33actually
- 2:07:41side
- 2:07:45i should figure out the size as well
- 2:08:05so this will be the size
- 2:08:15okay
- 2:08:16contracts would be the size
- 2:08:19and then we could say return this size
- 2:08:21as well
- 2:08:26and then i want to say if size is
- 2:08:30if size is bigger than
- 2:08:33zero
- 2:08:35um what do i need here
- 2:08:41no i don't need that
- 2:08:44the imposition would be true but
- 2:08:46what am i looking for is the question
- 2:08:50i'm looking to see if it's long or short
- 2:08:53and i know i have that here if side is
- 2:08:57long
- 2:09:00and long equals true
- 2:09:06and
- 2:09:07long
- 2:09:08equals false
- 2:09:17pass it through long as well and see
- 2:09:18what happens so size and long are now
- 2:09:21part of this
- 2:09:22size is three or two
- 2:09:27two is size
- 2:09:29and three
- 2:09:31is long
- 2:09:33okay perfect perfect perfect perfect
- 2:09:41so p l will be size the
- 2:09:46long would be this
- 2:09:48three
- 2:09:52and size
- 2:09:55would be this
- 2:09:58two
- 2:09:59let's just make sure we have everything
- 2:10:01print
- 2:10:02f
- 2:10:03um
- 2:10:07open position
- 2:10:12long
- 2:10:15and size
- 2:10:26do you think we're gonna air probably
- 2:10:30just put a bunch of stars just so i see
- 2:10:31it kill switch
- 2:10:47piano close is not defined
- 2:10:50113.
- 2:10:54mm-hmm it's because
- 2:11:00it's below it
- 2:11:06all right i'm gonna make another
- 2:11:07function really quickly
- 2:11:09and it's going to be called open
- 2:11:11positions
- 2:11:12so i'm just going to get a bunch of data
- 2:11:14that i need and i'm just going to try to
- 2:11:16do this quickly i do this one all the
- 2:11:18time so
- 2:11:20def open
- 2:11:21positions
- 2:11:22and this is a good one to to know how to
- 2:11:25do
- 2:11:26because
- 2:11:28you're going to use it all the time or i
- 2:11:30use it all the time
- 2:11:31type
- 2:11:33swap
- 2:11:37code
- 2:11:39usd okay perfect
- 2:11:42uh fee
- 2:11:44bao equals
- 2:11:46femix dot
- 2:11:48fetch balance
- 2:11:52params equal params so i'm just gonna
- 2:11:55get all the information that i need
- 2:11:57because uh it's just giving me a hard
- 2:11:59time so open positions
- 2:12:06equals
- 2:12:08fibal
- 2:12:10i think it's info
- 2:12:13data positions
- 2:12:21okay so we got that
- 2:12:23and let's print open positions
- 2:12:32and see if we can get our open positions
- 2:12:34because then we'll have all the
- 2:12:35information we need
- 2:12:38it's going to give me error because of
- 2:12:39that last thing but that's fine okay i
- 2:12:41got open positions
- 2:12:43perfect
- 2:12:48now
- 2:12:51what do we want to do with these open
- 2:12:52positions
- 2:12:59i actually need that information because
- 2:13:01i need to format it and see
- 2:13:04where things are
- 2:13:09i cannot remember it's too many
- 2:13:11dictionaries for me
- 2:13:15let's go over here
- 2:13:19um
- 2:13:23let's throw it in here
- 2:13:26let's do a little format in here
- 2:13:28format document
- 2:13:30so zero
- 2:13:32okay so we're on the zero index
- 2:13:35and the thing i need to get is the side
- 2:13:39side is by
- 2:13:42and then the size
- 2:13:49size is one perfect so side inside side
- 2:13:52and side side and side side
- 2:13:55open
- 2:13:56position side equals open
- 2:14:02positions
- 2:14:04and it was zero here
- 2:14:07and it was side right
- 2:14:09and then the same thing for size
- 2:14:13but the difference is this part size
- 2:14:17perfect
- 2:14:22now i want to say
- 2:14:25if open
- 2:14:27position side
- 2:14:30equals just in case let's say bye
- 2:14:33oops i think it's that
- 2:14:37then open position
- 2:14:39bull
- 2:14:41equals
- 2:14:43true
- 2:14:45long equals
- 2:14:47true
- 2:14:48perfect i can use those later lf
- 2:14:51open
- 2:14:53side
- 2:14:55equals just in case
- 2:14:57cell
- 2:15:00open position bull
- 2:15:03equals true
- 2:15:05and
- 2:15:07long
- 2:15:09equals false
- 2:15:12okay
- 2:15:13that makes sense right getting all that
- 2:15:15information else
- 2:15:17open position bool equals false
- 2:15:21and long
- 2:15:24long equals let's just do none for now
- 2:15:27so now we're going to say hey if the
- 2:15:29side is bi then we know we're going to
- 2:15:31put a bull
- 2:15:32open position bull true long is true
- 2:15:35else
- 2:15:36alif if it's cell then it's open
- 2:15:38position bool is also true
- 2:15:41and long equals false because we're not
- 2:15:43long
- 2:15:46okay i think we might have all the
- 2:15:48information we need now but
- 2:15:50let's uh let's try this out let's return
- 2:15:54open positions
- 2:15:56first chisel
- 2:15:58open position bool
- 2:16:00again for a chisel
- 2:16:02open position size
- 2:16:05absolutely
- 2:16:07and long
- 2:16:13perfect
- 2:16:27okay now i can drag this around with me
- 2:16:30and i might move that up later but
- 2:16:33let's see if it just runs
- 2:16:41okay perfect perfect
- 2:16:45let's drag this in and
- 2:16:50so open position side
- 2:16:53let's try this again
- 2:17:00so open position should be open
- 2:17:03positions now
- 2:17:09and
- 2:17:10if you want and that should set a true
- 2:17:12or false
- 2:17:13and then same with this one
- 2:17:18long
- 2:17:19equals
- 2:17:22what is long 0 1 2 3. so 3
- 2:17:26and then size
- 2:17:29is open positions
- 2:17:31two
- 2:17:32right zero one two yep
- 2:17:35perfect we're doing good we're doing
- 2:17:37good
- 2:17:38and
- 2:17:41let's see if it works
- 2:17:45i'm looking for this starred line
- 2:17:47specifically
- 2:17:50ah yes there we go
- 2:17:53we're getting closer
- 2:17:57okay now let's
- 2:17:58not print this whole dictionary because
- 2:18:00that's annoying
- 2:18:03um open positions we don't need to run
- 2:18:05that anymore
- 2:18:06[Music]
- 2:18:08kill switch okay we're really really
- 2:18:09close we're really really close
- 2:18:11let's make some space in here
- 2:18:16and i'm gonna delete this
- 2:18:19and we are almost done with this
- 2:18:22this is amazing i'm really excited to
- 2:18:24launch this so
- 2:18:26um
- 2:18:30size
- 2:18:33um let's call this kill size
- 2:18:37because this is not just the size this
- 2:18:40is the size we want to kill
- 2:18:42because we're in a winning position
- 2:18:43remember p l
- 2:18:45close
- 2:18:46if our p l is over this amount we're
- 2:18:48doing a kill switch because we want to
- 2:18:50we want to take our win
- 2:18:53and our target i believe is 25
- 2:18:55we can change that later if needed
- 2:18:57um
- 2:18:59let's delete that
- 2:19:01kill size
- 2:19:03and
- 2:19:06so open position while open position is
- 2:19:09true we want to do a loop
- 2:19:12because as long as it's true
- 2:19:15that means we're still
- 2:19:17in the position and we haven't exited
- 2:19:19yet
- 2:19:20print
- 2:19:21starting
- 2:19:23kill switch loop
- 2:19:26till limit fill
- 2:19:29perfect and let's do it
- 2:19:35let's do a temp df just in case i think
- 2:19:37we might need this
- 2:19:52no i don't think we need it but you know
- 2:19:55we'll just let's do it anyways let's do
- 2:19:57femix dot cancel all orders
- 2:20:03because remember we got the kill switch
- 2:20:04going and if there's like if the
- 2:20:06market's moving really fast
- 2:20:08we want to get out we want to get out
- 2:20:10because we already took our we hit our
- 2:20:12profits so
- 2:20:15so we want to
- 2:20:16keep keep it moving so let's go ahead
- 2:20:20and
- 2:20:22say again open position
- 2:20:25equals
- 2:20:27open positions just in case
- 2:20:33if you notice i rewrite a lot of code
- 2:20:36but
- 2:20:39that's okay
- 2:20:41whatever
- 2:20:42works
- 2:20:44so this sets it along
- 2:20:46and i just want to get the kill size one
- 2:20:48more time i'm just going to copy this
- 2:20:50over
- 2:20:52kill slides
- 2:20:55the reason i'm doing this is because it
- 2:20:56can change
- 2:21:00while it's in the while loop
- 2:21:02because it's going to have a sleeve i'm
- 2:21:04going to put a sleep in it so kill size
- 2:21:08and then i want to make this an integer
- 2:21:10um
- 2:21:10kill size
- 2:21:13and
- 2:21:15kill size
- 2:21:19and
- 2:21:20let's go ahead and say print
- 2:21:23now let's
- 2:21:24not do a print we have enough let's say
- 2:21:27date time is now
- 2:21:31and the string of that
- 2:21:34i don't need that either actually
- 2:21:36i was going to do some logging but i
- 2:21:38think we probably just don't need that
- 2:21:39right now
- 2:21:40let's get the ask in here
- 2:21:45ask equals
- 2:21:47what was it bit ask no it's ask bid
- 2:21:51and the ask would be zero and the bid
- 2:21:55equals ask bid
- 2:21:57one
- 2:22:01uno
- 2:22:03okay
- 2:22:05now we have to make the actual buying
- 2:22:06logic so we're in a while loop right now
- 2:22:10if long
- 2:22:12equals false
- 2:22:16let's cancel all orders
- 2:22:19just in case
- 2:22:22you know actually
- 2:22:25probably don't need to do that again
- 2:22:26because i cancel them all right here
- 2:22:28right so we're while looping through
- 2:22:29starting kill switch cancel all orders
- 2:22:32yeah we don't need to cancel all orders
- 2:22:33again
- 2:22:36femix dot create
- 2:22:38limit buy order because we're trying to
- 2:22:40buy it back
- 2:22:46i mean it could be
- 2:22:49yeah we're trying to buy it back if
- 2:22:51long
- 2:22:52if long equals false yeah so if long
- 2:22:55equals false that means we're short so
- 2:22:57we have to buy it back
- 2:22:59this is right this is right
- 2:23:02um
- 2:23:03we would put the kill size in here
- 2:23:08kill size
- 2:23:10we put the bid
- 2:23:12because we want to put it at the bid and
- 2:23:14then the params remember the params
- 2:23:16make it so
- 2:23:20why does this give me air
- 2:23:31hmm
- 2:24:00i don't see why it would give me an
- 2:24:01error here
- 2:24:04so
- 2:24:07let's just run it not run it but let's
- 2:24:09keep going
- 2:24:13print
- 2:24:16f
- 2:24:18just made a
- 2:24:23oh this is why you just give me here
- 2:24:25sorry
- 2:24:26i don't know why i put that there
- 2:24:29just made a w what do we what are we
- 2:24:32doing here buy
- 2:24:34to close
- 2:24:36order
- 2:24:37of
- 2:24:40kill size
- 2:24:44right that sounds about right
- 2:24:50let's put the symbol on here
- 2:24:52just so we can see
- 2:24:54at
- 2:25:01so if we're long
- 2:25:03we have to buy back
- 2:25:10so we'd be bidding so we wanted the bid
- 2:25:12that's right that's right
- 2:25:16okay cool l f
- 2:25:18l if what though
- 2:25:20l if long is true
- 2:25:22we have to sell
- 2:25:25right we have to sell to get back
- 2:25:29so we do femix dot
- 2:25:33create
- 2:25:34limit sell order
- 2:25:37with the symbol
- 2:25:42uh kill size
- 2:25:46the ask because that's right right
- 2:25:49because if we're in a long is true that
- 2:25:51means we're longing it longing it long
- 2:25:52and long elongated and we want to sell
- 2:25:54it to ask because that's the limit yep
- 2:25:56that makes sense to me
- 2:25:58um
- 2:26:01gotta make sure to pass in the params so
- 2:26:03we only do post orders and then we can
- 2:26:06go ahead and just copy this
- 2:26:09just got to make sure to make the
- 2:26:11changes
- 2:26:12a cell
- 2:26:14to close a kill size symbol and ask
- 2:26:21okay
- 2:26:23now i want to put a little sleep in here
- 2:26:28print
- 2:26:31sleeping for
- 2:26:3330 seconds
- 2:26:34to see if it fills
- 2:26:38because i don't want to just keep
- 2:26:39pressing orders over and over you know
- 2:26:42exchanges don't like that i don't like
- 2:26:45that
- 2:26:46nobody likes that okay okay so let's
- 2:26:49jump into this next one here
- 2:26:52print okay perfect so now we have our
- 2:26:54kill switch i believe
- 2:26:56um i'm just gonna do this else print
- 2:27:00um
- 2:27:01something
- 2:27:05something i didn't
- 2:27:09expect
- 2:27:11and kill switch
- 2:27:14function
- 2:27:16perfect
- 2:27:19okay what else
- 2:27:23now i want to check if the open position
- 2:27:24is true
- 2:27:26because
- 2:27:28we're doing a while loop right so open
- 2:27:30position
- 2:27:32let's check if it's true one more time
- 2:27:33after we do all that information because
- 2:27:35remember we're sleeping for 30 seconds
- 2:27:37after we make the buys
- 2:27:38so it might fill and if it fills
- 2:27:42then we don't want to keep running it
- 2:27:46okay i think we're good with this now
- 2:27:54um if i run this kill switch
- 2:27:58right now
- 2:28:04i'm going to exit or close everything
- 2:28:06out i want to test this kill switch
- 2:28:08see if it works and how am i going to
- 2:28:10test it just like this super easy
- 2:28:13i'm just gonna run it it should like
- 2:28:15this is a pretty good kill switch and i
- 2:28:17really like this like
- 2:28:18um
- 2:28:19the way this is set up because it gets
- 2:28:21the exact
- 2:28:23size that is open it's not like you have
- 2:28:26to depend on your old variables because
- 2:28:27sometimes what happens is like
- 2:28:30you'll get part partially filled like if
- 2:28:32you're doing 100 contracts and you
- 2:28:34failed 25 contracts and your kill switch
- 2:28:36is based off of your size then you're
- 2:28:38gonna
- 2:28:39you have 25 contracts open and then you
- 2:28:41sell 100 now you're short or you're the
- 2:28:43opposite right so
- 2:28:45let's go ahead and run this
- 2:28:52starting 15-minute sma
- 2:28:55starting the kill switch
- 2:29:00you hear that sound right just made a
- 2:29:01cell to close
- 2:29:03order of one ubtc
- 2:29:0534
- 2:29:07to 80.
- 2:29:09so i should be seeing right on the bid
- 2:29:12yeah look at that so i'm sitting right
- 2:29:14on the oh my god i've lost 20 percent on
- 2:29:16this position
- 2:29:18but anyways it's only one
- 2:29:21contract it's a dollar 45.
- 2:29:24but you can see that it sits right on
- 2:29:26the bid
- 2:29:27and then it sleeps for 30 seconds
- 2:29:30and then it cancels it
- 2:29:32does it again sleeps for 30 seconds so
- 2:29:34this is good this kill switch is working
- 2:29:37that means i think i'm done with the bot
- 2:29:39i think i am done with the bot
- 2:29:43look at that we did it
- 2:29:45we did it
- 2:29:47i can drink some water now
- 2:29:50next time i will bring some water but i
- 2:29:53think oh we're not quite done yet we're
- 2:29:54not quite done yet we're not going
- 2:29:56we just have to do one more thing
- 2:30:00let's delete all of these things that
- 2:30:02run
- 2:30:11my question is how did that just happen
- 2:30:18how did it just cancel and run again i
- 2:30:20thought i'd just close
- 2:30:22i thought i just killed the bot but
- 2:30:26it's got a mind of its own no or what
- 2:30:32piano clothes just gonna check the piano
- 2:30:34close
- 2:30:35every time through
- 2:30:40holy smokes this is crazy to me
- 2:30:43oh i think i didn't kill it
- 2:30:46i just exited out and
- 2:30:48i was tripping out for a second there
- 2:30:49like what the heck how is it still
- 2:30:51running all right so it checks the piano
- 2:30:53clothes every time through checking to
- 2:30:55see if time to exit does all this stuff
- 2:30:58and says it's the percentage over zero
- 2:31:01if it is then okay print we're in a
- 2:31:03winning position perfect by the way that
- 2:31:05just sold
- 2:31:06um
- 2:31:08and then if the percentage over target
- 2:31:09which my target is 25
- 2:31:12then
- 2:31:13we would say smiley face we're going to
- 2:31:15do piano clothes and we're going to hit
- 2:31:16the kill switch the kill switch is going
- 2:31:18to take us up here
- 2:31:19and gracefully take us out of the
- 2:31:22position at limit so that's pretty cool
- 2:31:25i'm going to delete this because i don't
- 2:31:26want the kill switch to run every time
- 2:31:30so i think the last thing we have to do
- 2:31:32here
- 2:31:34is
- 2:31:40the last thing we have to do is set this
- 2:31:42so it runs
- 2:31:43all the time
- 2:31:46i'm just going to write uh
- 2:31:49built this spot
- 2:31:51that does the
- 2:31:53below
- 2:31:55and it's that
- 2:31:56to build
- 2:31:58in
- 2:31:59or tomorrow or something
- 2:32:01so if you want to see that let me know
- 2:32:02any type of bot you want to see done i
- 2:32:04obviously have a huge huge list of
- 2:32:06strategies i'm building
- 2:32:08and i'm going to create create them here
- 2:32:09on on youtube
- 2:32:11because i the way i feel is like this is
- 2:32:13just everybody tries to be so like
- 2:32:17secretive about this world
- 2:32:19this
- 2:32:20quant world this i'll go trading world
- 2:32:22but it's just like
- 2:32:25anybody can do it i swear to god
- 2:32:29so the last thing i'm going to do is i'm
- 2:32:30going to run this every 30 seconds
- 2:32:32so how do we do that
- 2:32:34so i'm going to delete that
- 2:32:37if i hit play nothing should happen
- 2:32:41perfect
- 2:32:42oh wait wait wait why are you happening
- 2:32:46starting sma
- 2:32:52who invited you to work
- 2:32:56this is why we triple check things
- 2:32:59got it right there
- 2:33:01now this should run nothing
- 2:33:05what the heck
- 2:33:08whatever
- 2:33:10run ask bid it's probably from this
- 2:33:14dfd do i need this anywhere i don't
- 2:33:16think i need it
- 2:33:20i don't think i need this either
- 2:33:26okay
- 2:33:27now it should run nothing
- 2:33:32perfect okay now i'm ready to set this
- 2:33:34up this is my last couple lines of code
- 2:33:36and we are off in under 300 lines of
- 2:33:39code which is awesome awesome awesome
- 2:33:42schedule dot every
- 2:33:44uh let's do this uh for example right
- 2:33:47now 10 seconds
- 2:33:50and do
- 2:33:52uh what did i call it bot
- 2:33:55i think i called it bot
- 2:33:58yeah bob
- 2:34:02and then let's set a while loop while
- 2:34:04true
- 2:34:06should be always
- 2:34:07try
- 2:34:08because there can be
- 2:34:11shaky internet where i am
- 2:34:14scheduled
- 2:34:17run
- 2:34:18pending
- 2:34:21and then accept so the reason i do this
- 2:34:23is because you know whatever happens
- 2:34:26your internet goes out whatever
- 2:34:28then it will keep running you don't have
- 2:34:30to like reset it
- 2:34:33maybe
- 2:34:34an internet
- 2:34:36prob
- 2:34:38or something
- 2:34:40and then let's run it again in 30
- 2:34:42seconds okay cool we got it perfect
- 2:34:45perfect perfect this bot should work now
- 2:34:47let's run it let's see what happens i'm
- 2:34:49just going to run it i'm just going to
- 2:34:51run it and
- 2:34:52see if we get any errors let's see if we
- 2:34:54get any buys any cells
- 2:34:58wait 10 seconds remember it's scheduled
- 2:35:00every 10 seconds it's about 10 seconds
- 2:35:02starting up now it's starting up we're
- 2:35:05starting indicators checking to see this
- 2:35:07is our sale price there it is buys so it
- 2:35:10made the two buys right there
- 2:35:14we're gucci
- 2:35:16we are good to go
- 2:35:18making the cell checking to see
- 2:35:20studying indies
- 2:35:22canceling and putting them again okay so
- 2:35:24we're great we're doing great the bot
- 2:35:26works um i'm super happy about this i
- 2:35:29need to do one thing that i forgot um
- 2:35:31time dot sleep
- 2:35:33create
- 2:35:35create we forgot to put this
- 2:35:37uncheck those sleeps because we're just
- 2:35:39gonna send them every let's do it every
- 2:35:4160 seconds
- 2:35:43no i actually don't need that
- 2:35:47yeah yeah yeah let's do 30 seconds
- 2:35:50because i'm going to run this bot every
- 2:35:5130 seconds anyways
- 2:35:53so
- 2:35:55no i want it more i want more one more
- 2:35:57one more uh
- 2:35:58let's do 120 seconds so it'll sleep for
- 2:36:01two minutes after it makes the bus
- 2:36:03or after it makes the opening orders
- 2:36:05it'll sleep for two minutes but also
- 2:36:08we're only going to run this every
- 2:36:1228 seconds
- 2:36:1330 seconds but i think it takes about
- 2:36:15two seconds to run through the code so
- 2:36:17theoretically what's going to happen is
- 2:36:19it makes the eyes it's going to sleep
- 2:36:20for
- 2:36:21two minutes
- 2:36:29just open
- 2:36:30just made
- 2:36:32opening order
- 2:36:34so
- 2:36:35going to sleep
- 2:36:38for two minutes
- 2:36:40perfect
- 2:36:42sorry i'm really excited now i love
- 2:36:44finishing a bot because now it's just
- 2:36:47like i sit back and i
- 2:36:49see if it works
- 2:36:50you know what i'm saying so if you
- 2:36:52really enjoyed this like all i ask is
- 2:36:54hit a like
- 2:36:55like on the video i mean that's all i
- 2:36:57need if i get a couple likes and i'll
- 2:36:59make a new video tomorrow and um
- 2:37:01i i literally sit here all day and make
- 2:37:03algos like this
- 2:37:05i you know
- 2:37:06obviously i do some some sneaky things
- 2:37:10as well with machine learning and a lot
- 2:37:12of deeper strategies than this but you
- 2:37:15can see my process now and as i
- 2:37:17mentioned i'm just a regular regular old
- 2:37:19dude that you saw what happens when i
- 2:37:21get stuck i just google it
- 2:37:24just ask google like that's all
- 2:37:27let's run this i'm just going to let it
- 2:37:28run now because it's going to sleep for
- 2:37:3030 seconds or it's going to run in 30
- 2:37:33seconds
- 2:37:34so i'm pretty good to go if you want to
- 2:37:36learn more i put together a boot camp
- 2:37:38that's a lot more like straightforward
- 2:37:40organized and step-by-step so you can go
- 2:37:43from you know beginner to expert i'll go
- 2:37:45trader um that there's a link for that
- 2:37:48somewhere around here but really the one
- 2:37:50thing i do ask is just if you've made it
- 2:37:52this far just hit the like button um
- 2:37:55just to signal that you enjoyed this if
- 2:37:57you have any questions or comments or
- 2:37:58anything
- 2:38:00please do let me know
- 2:38:03in the comment section below i'm super
- 2:38:06excited i'll maybe i'll make a follow up
- 2:38:07if you're interested
- 2:38:08in how this went um i've got tons of
- 2:38:11videos on i'll go training on my my
- 2:38:14youtube channel so you know if you're
- 2:38:16not ready to just take a structured boot
- 2:38:18camp where i teach you step by step in
- 2:38:21short videos as opposed to this nice
- 2:38:23long algo video
- 2:38:25and you want access to all my algos
- 2:38:27i have that boot camp of course but if
- 2:38:29you're not ready to join that no worries
- 2:38:31i have a ton of free videos here on
- 2:38:33youtube and i'll put another video up
- 2:38:34here
- 2:38:35on the screen like right now so you can
- 2:38:38go check it out and we can just keep
- 2:38:39jamming and keep uh keep working
- 2:38:41together on building out you know this
- 2:38:44empire so i'll put that screen on a
- 2:38:46video on the screen right now if go
- 2:38:48ahead and check out the boot camp
- 2:38:50there's a link below but otherwise
- 2:38:53i hope you have a wonderful day i hope
- 2:38:54you really enjoyed this video i had a
- 2:38:56lot of fun today building this bot out
- 2:38:58with you
- 2:38:59and that video on the screen right now
- 2:39:01is where i will see you in just two
- 2:39:04seconds
- 2:39:05or in the boot camp so see you soon
About this transcript
This page contains the full transcript of i coded a trading bot live.. (293%+ roi) by Moon Dev, generated from the public captions YouTube serves with the video. The transcript has 16,650 words across 3,335 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.