YouTube2Text

i coded a trading bot live.. (293%+ roi) — Transcript

by Moon Dev · 16,650 words · 3,335 segments · language en · Watch on YouTube

Full transcript

  1. 0:00don't know about you but the only reason
  2. 0:02i usually lose a trade is because of
  3. 0:04myself and it's because i didn't close
  4. 0:06out when i hit my target or i was in a
  5. 0:10losing trade and i didn't take my stop
  6. 0:12loss or something that has to do with
  7. 0:15myself so
  8. 0:16a couple years back i set out on a goal
  9. 0:18to just automate my trading and it's the
  10. 0:20absolute best strategy of ever best
  11. 0:23thing i've ever done in my life because
  12. 0:25now i can code algorithms and you can
  13. 0:28too i promise you if you haven't started
  14. 0:30coding yet if you're trading hey you
  15. 0:32know you can increase your profits by 10
  16. 0:3520 30 100
  17. 0:37just by
  18. 0:38coding them out and saying hey computer
  19. 0:41you do this for me because instead of
  20. 0:43you panicking when it goes down the
  21. 0:45computer might buy or based off of
  22. 0:47whatever rules you put in there maybe it
  23. 0:50sells
  24. 0:51maybe it takes a stop you know it takes
  25. 0:53a stop out or you know it takes profit
  26. 0:55at this point or whatever
  27. 0:57the thing is is computers can execute
  28. 1:00without the emotion and the only
  29. 1:02downside of humans
  30. 1:05is we we have emotion and you have to
  31. 1:07use the bathroom you have to eat what if
  32. 1:10you're in a trade and you need to exit
  33. 1:11but you got to go you got to go to the
  34. 1:13bathroom or you got to eat lunch or you
  35. 1:15have a family
  36. 1:16thing going on right so there's so many
  37. 1:18reasons i don't need to sit here and
  38. 1:20convince you to learn how to code i
  39. 1:21think if you're on this video you're
  40. 1:24everlasting learner and you're never
  41. 1:26gonna stop until you get there so this
  42. 1:28is just one of the best ways i've been
  43. 1:29able to pull alpha out of the market is
  44. 1:32learn how to code and code your
  45. 1:34algorithms to trade for you 24 7
  46. 1:38365 because you are literally
  47. 1:41unstoppable there's not many people out
  48. 1:44here that are going to spend their time
  49. 1:46searching through youtube for new
  50. 1:47strategies or algorithms but you're
  51. 1:50doing that so
  52. 1:51if you can
  53. 1:53take the best of you which is you know
  54. 1:55your persistence and you put it into
  55. 1:57code to trade for you
  56. 1:59it removes the only downside of me and
  57. 2:02you which is hey we're humans we gotta
  58. 2:04sleep we gotta eat we gotta go to the
  59. 2:06bathroom we have emotions we think it's
  60. 2:08gonna go higher or lower you know we
  61. 2:10think right computers don't think they
  62. 2:12just do
  63. 2:13so in this video what i'm gonna do is
  64. 2:16you know i'm a regular dude
  65. 2:18i i'm not a mathematician i didn't go to
  66. 2:21harvard i didn't get an engineering
  67. 2:23degree none of that stuff i think that's
  68. 2:25all
  69. 2:26you know mystical stuff that they want
  70. 2:28you to believe
  71. 2:29just so they can say hey you can't be an
  72. 2:31algo trader because you don't know how
  73. 2:33to or you didn't go to harvard or you
  74. 2:35don't you're not a mathematician yada
  75. 2:37yada well guess what i'm always trying
  76. 2:39to 24 7 365 every single day i make a
  77. 2:42new algo and i'm going to share it here
  78. 2:44with you on this channel and i'm just
  79. 2:46going to write an algo here just to show
  80. 2:48you that like you don't have to be an
  81. 2:50expert to do this you don't have to be a
  82. 2:52crazy coder you don't have to you know
  83. 2:54spend years and years of your life to
  84. 2:56figure this out
  85. 2:57but you're diligent enough you're
  86. 2:59already persistent enough that you're
  87. 3:01gonna find a way to pull alpha out of
  88. 3:03this market and in my opinion you know
  89. 3:06i'm a decade plus entrepreneur
  90. 3:08in my opinion
  91. 3:10this is the best way
  92. 3:12to pull alpha out of the market and the
  93. 3:15market is the best business if you
  94. 3:17figure it out so let's just go ahead and
  95. 3:19start coding you know um i really
  96. 3:22appreciate you being here it's super
  97. 3:24cool because you are unstoppable you
  98. 3:26will figure this out and let's just go
  99. 3:28ahead and start coding this out i'm
  100. 3:30going to build a strategy today that is
  101. 3:32it'll look at the overall trend past
  102. 3:35maybe fifty hundred two hundred days
  103. 3:37we'll get into that later
  104. 3:41and then we'll decide which way the
  105. 3:42trend is going you know from my
  106. 3:44eyeballing this looks like we're hitting
  107. 3:47long-term support kind of
  108. 3:50um we're obviously in a downturn
  109. 3:53but it might bounce here
  110. 3:55you know i i can see that right but
  111. 3:59i'm thinking and i don't really want to
  112. 4:02think i want to program a computer to
  113. 4:04just do it all for me because it's just
  114. 4:05so much better it's just such a better
  115. 4:07lifestyle i don't have to sit here and
  116. 4:09look at these charts all day um but yeah
  117. 4:12this is the daily chart so my strategy
  118. 4:14here i'm trying to build is it's not too
  119. 4:16hard uh it's gonna look at the
  120. 4:20last 100 days or so
  121. 4:24actually it'll probably be about 20 days
  122. 4:26so i'll build an sma a simple moving
  123. 4:29average and it will tell me which way is
  124. 4:31the trend
  125. 4:32and if the trend is
  126. 4:34you know bullish
  127. 4:36we're going to look for longing
  128. 4:37opportunities but if it's bearish we're
  129. 4:39going to look for shorting opportunities
  130. 4:41now this is a bitcoin chart i will will
  131. 4:44go ahead and pull up let's see
  132. 4:47pull up my femix account here because
  133. 4:51i actually don't want to trade bitcoin i
  134. 4:54would actually rather trade one of these
  135. 4:57altcoins
  136. 4:58based off of bitcoin
  137. 5:00so it's a little weird i know but
  138. 5:05it tends to work and the reason i do
  139. 5:07that is just the all coins are a little
  140. 5:09more volatile so
  141. 5:12you know they typically follow bitcoin
  142. 5:14so i might even go ahead and see what
  143. 5:17the trend is
  144. 5:18with bitcoin
  145. 5:19and then also the altcoin they're gonna
  146. 5:22be similar but i'm going to look at the
  147. 5:24trend and then i'm going to place my
  148. 5:26buys i'm going to build like a
  149. 5:31i'm going to build a 20 sma again
  150. 5:34but
  151. 5:35i'm going to have it on the 15 minute so
  152. 5:37the first sma is going to be a daily sma
  153. 5:41for the last
  154. 5:42i think 20 days maybe 15 20 days we'll
  155. 5:45figure it out when i get there test it
  156. 5:47out and then the second sma is going to
  157. 5:49be a 15 minute sma
  158. 5:52for 20 periods or so and the reason i'm
  159. 5:56going to put this sma in is
  160. 5:59because
  161. 6:01this one is going to determine where
  162. 6:03i'm going to buy
  163. 6:04it so one determines which way we're
  164. 6:07buying if we're opening as a short or a
  165. 6:10long
  166. 6:12that's the daily one and then the second
  167. 6:15parameter i'm looking at is the 15
  168. 6:18minute
  169. 6:19sma
  170. 6:20and that's where we'll place our bids
  171. 6:22i'll probably i'll probably place two
  172. 6:24eyes and they're gonna be above and
  173. 6:26below that sma so pretty simple strategy
  174. 6:29i'm not gonna use a stop loss i'm gonna
  175. 6:32use a kind of just
  176. 6:35a stop loss in the sense of
  177. 6:39size so i'm just not gonna
  178. 6:41i'm not gonna make my positions too much
  179. 6:44i will use some leverage
  180. 6:45let's go ahead and see what i have here
  181. 6:48so i only have 100 bucks in my account
  182. 6:50and that's probably good because you
  183. 6:52know this is a new strategy but once
  184. 6:54this strategy proves itself
  185. 6:58we can go ahead and level this up to
  186. 7:01probably a thousand two thousand um i
  187. 7:04like to diversify i have tons and tons
  188. 7:06of strategies so
  189. 7:07i try to keep keep it in the low
  190. 7:09thousands and then you can scale with
  191. 7:11other strategies but that being said
  192. 7:13let's just dive into it
  193. 7:15i've got this great cup of coffee here
  194. 7:17so i'm sorry if you hear me slurping a
  195. 7:18little bit
  196. 7:22it's my favorite coffee and i'm gonna
  197. 7:23need it because we're building an algo
  198. 7:25here
  199. 7:26we're building it from scratch
  200. 7:28i think i went over everything
  201. 7:31you know the strategy look at the trend
  202. 7:33from the sma
  203. 7:35we're going to do the 20 day sma
  204. 7:39and then we're going to place our buys
  205. 7:41or shorts
  206. 7:42our buys or cells
  207. 7:45to enter
  208. 7:46along the 15-minute sma so we need to
  209. 7:48create two smas that'll be one of the
  210. 7:50first things we need to do i'm going to
  211. 7:52use ccxt which is a library
  212. 7:55in python and i'm just going to get
  213. 7:57started because i think this is
  214. 7:59this is going to be good um a lot of
  215. 8:02people are scared right now like this is
  216. 8:03a
  217. 8:04downtrend i personally think
  218. 8:07i'm not going to think i'm not going to
  219. 8:08make any opinions you know from from my
  220. 8:11eye it looks like it's gonna
  221. 8:13it's gonna bounce but that being said
  222. 8:17if it doesn't bounce this is where
  223. 8:18humans go wrong like if it goes down
  224. 8:20here and it starts falling if i keep
  225. 8:22thinking it's gonna bounce i would keep
  226. 8:23longing it but
  227. 8:25i just want my code to do it for me
  228. 8:27because i at the end of the day if i
  229. 8:30program this strategy or whatever
  230. 8:32strategy i do run
  231. 8:35then the code runs it and
  232. 8:38it is what it is you take out the
  233. 8:40emotion for example like i'm sure you've
  234. 8:42been in a strategy in a trade before
  235. 8:44where it's like you're in a a winning
  236. 8:46trade and you just need to close it out
  237. 8:49and if you closed it you would have won
  238. 8:50you could have walked away enjoyed your
  239. 8:51day
  240. 8:53but what happened is you have a motion
  241. 8:55and you think hey
  242. 8:56this might go a little higher or i might
  243. 8:57make a little more
  244. 8:59and then it turns around on you and you
  245. 9:01lose it so that type of stuff happens
  246. 9:02all the time and i just want to avoid
  247. 9:04that that's why i'm an algo trader and i
  248. 9:06i just code all my algorithms
  249. 9:09in order to trade for me so let's just
  250. 9:10dive into this this might take a bit so
  251. 9:12please do stick around this is gonna i'm
  252. 9:14gonna show you a lot and like i said i'm
  253. 9:16just a normal normal dude and i want to
  254. 9:19show you that this is not like rocket
  255. 9:21science so let's make all our imports
  256. 9:23here let's import ccxt which is the
  257. 9:26library i'll be using
  258. 9:28let's import numpy
  259. 9:30let's import my don't share config
  260. 9:34as ds this is pretty much a
  261. 9:36configuration file with my keys in it
  262. 9:38let's go ahead and import
  263. 9:43um date time for sure let's import date
  264. 9:47and i'm doing this live so
  265. 9:49i don't see many people do this on
  266. 9:51youtube but
  267. 9:53if you appreciate it
  268. 9:55this transparency just go ahead and
  269. 9:58smash that like button
  270. 10:00okay so i imported all of these things
  271. 10:03it looks like i need to go ahead and tip
  272. 10:06install some of these
  273. 10:09pip install
  274. 10:11date
  275. 10:12see if that works
  276. 10:13nope
  277. 10:15pip install date time
  278. 10:18and you're gonna see like everything
  279. 10:21you can see like i'm gonna run into
  280. 10:22errors and stuff and
  281. 10:24let's go ahead i'll have to google stuff
  282. 10:26along the way of course
  283. 10:30let's go ahead and i'll handle that
  284. 10:32later if i need it
  285. 10:34i'm just going to mark them out for now
  286. 10:37import date
  287. 10:40let's go ahead and keep it moving
  288. 10:46import
  289. 10:47time
  290. 10:49and schedule okay now we need to connect
  291. 10:52to
  292. 10:53our uh
  293. 10:57our brokerages so how are we going to do
  294. 10:59that
  295. 11:02i'm going to type in phoenix equals
  296. 11:05ccxt
  297. 11:07cc xt
  298. 11:09dot vmix
  299. 11:12and then get some curly brackets and
  300. 11:14let's do enable
  301. 11:17rate limit
  302. 11:19and that will be true okay
  303. 11:22and then api key
  304. 11:26let's go ahead and you know here yours
  305. 11:29might look like that
  306. 11:30but
  307. 11:31i'm actually calling it in from this
  308. 11:33file that i call ds
  309. 11:35and let's
  310. 11:37find the key here
  311. 11:39and then the secret
  312. 11:42so ccxc is pretty cool because it
  313. 11:44connects to all exchanges all crypto
  314. 11:46exchanges pretty much is
  315. 11:48pretty much so coinbase finance
  316. 11:51v max
  317. 11:52ftx
  318. 11:54all that so let's go ahead and
  319. 11:57i'm gonna
  320. 11:58mark
  321. 12:00what was going on here from daytime
  322. 12:03i always do that
  323. 12:06okay so i'm gonna go ahead and just make
  324. 12:08sure that we're connected so i'm gonna
  325. 12:10print out femix.fetch
  326. 12:14balance
  327. 12:16and let's run this let's see if it is
  328. 12:19connected i do have a balance of like a
  329. 12:21hundred bucks or something and that's
  330. 12:22plenty plenty plenty for this algorithm
  331. 12:25because i can lever up you know i can
  332. 12:28lever up 20 times
  333. 12:29um maybe won't do that much but we are
  334. 12:32connected okay so the symbol i'm going
  335. 12:34to use for now equals let's just let's
  336. 12:38build it with btc because that will be
  337. 12:40easier
  338. 12:43okay
  339. 12:45and
  340. 12:48let's put position size
  341. 12:50position size
  342. 12:51let's just do one for now i will change
  343. 12:54that later params i this is
  344. 12:57if you've seen my other videos i show a
  345. 12:59lot of like step by steps
  346. 13:02and
  347. 13:03this is a parameter that i use
  348. 13:06for all of my algo trading within femix
  349. 13:09because what it does is it makes it so i
  350. 13:12i only do limit orders it's a post only
  351. 13:15order so
  352. 13:16i'm super handy to have all of that now
  353. 13:19we want to go ahead and figure out the
  354. 13:21indicators right so first step
  355. 13:24uh find daily
  356. 13:27sma
  357. 13:29i think i'm gonna do 20 let's do daily
  358. 13:31sma 20
  359. 13:33and then i want to find
  360. 13:36daily
  361. 13:39sms or not daily 15 minute 15 minute
  362. 13:44sma
  363. 13:4520. okay so i need to make sure i get
  364. 13:48both of these smas in here
  365. 13:51and then
  366. 13:52i also need to get the bid and ask get
  367. 13:55bid
  368. 13:56and ask because it's just a it's a
  369. 13:58better
  370. 13:59it's more accurate pricing from what
  371. 14:02i've seen
  372. 14:03um let's see what else should we get
  373. 14:05here let's start there and then we'll
  374. 14:08we'll just build this over time like i
  375. 14:09said i'm building this whole thing in
  376. 14:11front of you because i want to show you
  377. 14:13that like i'm
  378. 14:14you don't have to be a mad genius to be
  379. 14:16an elbow trader you just have to
  380. 14:18be like
  381. 14:20persistent like it took a few months to
  382. 14:22learn how to code sure
  383. 14:25sure it was kind of boring at times but
  384. 14:27if
  385. 14:30you can double your profits because you
  386. 14:32get rid of your emotion it's so worth it
  387. 14:33oh my goodness so worth it you spend so
  388. 14:35much time looking at the screen anyways
  389. 14:38um okay so
  390. 14:41i don't like making decisions so that's
  391. 14:42why i'm coding this so let's just jump
  392. 14:44back into it let's go ahead and find the
  393. 14:46sma
  394. 14:48um
  395. 14:49let's call this daily
  396. 14:51sma
  397. 14:52okay
  398. 14:58and then what we want to do
  399. 15:00is we want to say
  400. 15:03let's say df
  401. 15:09i'm going to do dfd so i'm going to make
  402. 15:10a pandas data frame
  403. 15:13and by the way if you have any questions
  404. 15:15along the way about any of this
  405. 15:18let me know let me know in the section
  406. 15:20below
  407. 15:22super easy for me to answer them for you
  408. 15:27i actually like to say something like
  409. 15:29print
  410. 15:31starting
  411. 15:36indies so indicators
  412. 15:39and
  413. 15:45just thinking here and i apologize i'm
  414. 15:47gonna there's gonna be some pauses
  415. 15:49throughout this right because i'm i
  416. 15:51literally have to think this through
  417. 15:53and this is the process of coding an
  418. 15:56algorithm so i'm just getting things set
  419. 15:58up i'm good everything's imported we're
  420. 16:01looking good got a data frame here
  421. 16:06and i need to pull in data obviously is
  422. 16:10one of the first things i need to do
  423. 16:12so
  424. 16:15let's go ahead and
  425. 16:21let's get the bars
  426. 16:22bars equal
  427. 16:27femix
  428. 16:28we got to get our data i think that's a
  429. 16:30good place to start and this is why i
  430. 16:32love coding it's because like
  431. 16:36algos because you're just like
  432. 16:38sitting here
  433. 16:40trying to figure things out and it's
  434. 16:41like a puzzle right so
  435. 16:43let's say time frame equals
  436. 16:47time frame
  437. 16:49i haven't set that variable i need to
  438. 16:50set that
  439. 16:51and then limit of bars this is how many
  440. 16:54bars we want equals num of bars
  441. 16:58okay i need to set both of these so this
  442. 17:00will be the time frame
  443. 17:05so
  444. 17:09equals one day
  445. 17:11sorry it's one day
  446. 17:13okay and number of bars
  447. 17:16give us as many as you can
  448. 17:19no actually i don't need that many i
  449. 17:20just need a hundred okay
  450. 17:22let's do a hundred
  451. 17:24okay
  452. 17:25so starting indies i made a data frame i
  453. 17:28don't know if i'm gonna use it i should
  454. 17:29use it though
  455. 17:31and now
  456. 17:35i should bring this data frame down here
  457. 17:36because i want to put these bars here
  458. 17:40and just to kind of show my work let's
  459. 17:42go ahead and
  460. 17:44just not even show my work i just want
  461. 17:47to see if this works let's print bars
  462. 17:50see if this works i should have
  463. 17:53now
  464. 17:54the um
  465. 17:57i should have the open high low and
  466. 17:59close open high low and close
  467. 18:02and the volume for the last 100 days
  468. 18:05on the daily so remember we're building
  469. 18:07the daily sma right here so
  470. 18:12starting indies okay perfect
  471. 18:16um
  472. 18:19okay
  473. 18:20so
  474. 18:21looks like it's on a list
  475. 18:24this would be the date time stamp this
  476. 18:26would be the open this is the high
  477. 18:30low
  478. 18:31close volume perfect okay so i have all
  479. 18:35the data now i need to change this data
  480. 18:37up because it looked like it was in a
  481. 18:38list
  482. 18:40let's go ahead and
  483. 18:43pause that out
  484. 18:45and then let's go ahead and make this
  485. 18:46data frame just
  486. 18:48have our
  487. 18:49data be a little nicer columns equal
  488. 18:54um
  489. 18:55timestamp
  490. 18:57okay
  491. 18:58let's do open
  492. 19:02hi
  493. 19:05low
  494. 19:06and i gotta remember to uh
  495. 19:10remember that i'm using lower cases
  496. 19:12sometimes some data sources will use
  497. 19:16upper case
  498. 19:17some will use lowercase and i'm a
  499. 19:20lowercase guy
  500. 19:21it's just easier to remember for me but
  501. 19:24okay so now i have this data frame and
  502. 19:26let's print this out
  503. 19:28see what this looks like see if we have
  504. 19:29a better
  505. 19:31better looking set of data now
  506. 19:39beautiful beautiful beautiful beautiful
  507. 19:41okay so now we have the time stamp to
  508. 19:42open the high the low the clothes and
  509. 19:44volume i don't know what date this is
  510. 19:47though so i need to change that okay so
  511. 19:49how do you change that let's see here
  512. 19:53let's call this df let's tap into it tap
  513. 19:56tap in the timestamp
  514. 19:59and then let's change it by doing pd.2
  515. 20:02datetime
  516. 20:04and then df
  517. 20:06um
  518. 20:08we would tap in the timestamp again
  519. 20:11and then oh we would just change the
  520. 20:13unit unit
  521. 20:16is we would say it's okay so essentially
  522. 20:19what we're doing with this line is
  523. 20:20saying hey the date times in
  524. 20:22milliseconds timestamp
  525. 20:24let's uh change it to date time
  526. 20:26so this should look better now
  527. 20:28let's go ahead and move this print here
  528. 20:32to uh here
  529. 20:36let's see what this looks like now
  530. 20:39beautiful beautiful beautiful okay so i
  531. 20:41have until 1 22. today is 5'7 up nope
  532. 20:45today's 5 8 so this is yesterday's data
  533. 20:48up to yesterday's data um will that work
  534. 20:53let me think
  535. 20:55i think that's fine
  536. 20:58do i need today's data on the daily
  537. 21:02let's check this out i want to see what
  538. 21:04it's going to look like with the 15
  539. 21:05minute because i do need
  540. 21:07i do need the last 15 minutes for the
  541. 21:10next one
  542. 21:11okay this works 7 15 17 15 i think right
  543. 21:15now is
  544. 21:1817 30ish
  545. 21:20okay this works this works this works
  546. 21:21okay so i was just checking to see
  547. 21:24if
  548. 21:25the if we had the right
  549. 21:28data coming in from phoenix i know
  550. 21:29phoenix is sometimes playing with their
  551. 21:31data to be to be honest
  552. 21:33um i love the exchange though it's it's
  553. 21:35nice um let's see okay what do we do now
  554. 21:38we have the data frame we have the
  555. 21:40information we need
  556. 21:43okay there's some things that i really
  557. 21:45enjoy using
  558. 21:49but i want to figure out how should we
  559. 21:51do this
  560. 21:52like i want to get the low the high
  561. 21:54and all that good information
  562. 21:56but since it's in the function i need to
  563. 21:58think this through okay so we have the
  564. 22:00daily we don't have the daily sma yet
  565. 22:02though so let's just get the daily sma
  566. 22:06daily
  567. 22:07sma
  568. 22:09and i'm gonna put this data frame again
  569. 22:11here
  570. 22:16and
  571. 22:17i have my copy
  572. 22:22and let's find the sma
  573. 22:25so i think we need to do something with
  574. 22:27like rolling closes yeah that's right so
  575. 22:29daily sma
  576. 22:31and we're going to do a 20 20 day
  577. 22:35why did i pick 20 today i don't know to
  578. 22:38be honest you could use the
  579. 22:4015 day the 10 day whatever you want but
  580. 22:43that's the thing with i'll go trading
  581. 22:45it's a bunch of parameters and you got
  582. 22:46to test things out i could backtest this
  583. 22:49and i probably will
  584. 22:51maybe i'll make another video back
  585. 22:52testing this strategy as well usually i
  586. 22:55like to backtest before i run live but
  587. 22:57at the same time
  588. 23:00i sometimes just run live you know i'm
  589. 23:02not using a crazy amount of money 100
  590. 23:04bucks i'm not going to die i'm not going
  591. 23:06to die if i lose 100 bucks so
  592. 23:09let's go ahead and say
  593. 23:12dfd
  594. 23:13let's add to the data frame the sma
  595. 23:17sma
  596. 23:2020. uh and we have to call it daily so
  597. 23:26estimate 20 day okay that makes sense
  598. 23:28right sma 20 day so i'm adding to the to
  599. 23:31the data frame and i'm going to say df
  600. 23:37um dfd
  601. 23:39i need to tap in the dfd and then i need
  602. 23:41to find the close
  603. 23:44and then i need to make the average
  604. 23:46of the close so roll in
  605. 23:51and then i think it's 20
  606. 23:53dot mean
  607. 23:55that means and then we should be good so
  608. 23:58now we should have a column here that
  609. 24:00has the 20 day sma
  610. 24:03and i think this is a really good
  611. 24:04example of like
  612. 24:08one line of code to find the 20 sma
  613. 24:11before i started coding like this seemed
  614. 24:13like something hard right
  615. 24:15it's one line
  616. 24:17it's crazy
  617. 24:18let's see if it works though
  618. 24:26okay so these have nones nan's
  619. 24:30because there wasn't 20 days of data
  620. 24:33before
  621. 24:34i might need to get rid of these
  622. 24:36and that's fine because
  623. 24:41yeah that's fine because
  624. 24:43this data goes back far enough and i'm
  625. 24:45only going to look at the 20-day sma
  626. 24:48so i'm just going to drop those and i
  627. 24:51kind of remember how to do that i think
  628. 24:52it was drop and a
  629. 24:54pd dot
  630. 24:56drop
  631. 24:57n a um
  632. 25:11let's go with this real quickly i always
  633. 25:13joke that like
  634. 25:16coding is just being a professional
  635. 25:17googler that's all that's all it is
  636. 25:20jeez louise that couldn't have been
  637. 25:22easier drop nah drop nah i was right
  638. 25:25boom
  639. 25:26let's see what it does now do i have
  640. 25:29pandas installed
  641. 25:31that's the question
  642. 25:34pandas has no attribute
  643. 25:38called dropna
  644. 25:40i got pandas
  645. 25:44[Music]
  646. 25:46i always do that
  647. 25:47i put pd
  648. 25:49but it's actually you have to call the
  649. 25:51the
  650. 25:52panda the data frame okay so let's go
  651. 25:55ahead and print that
  652. 25:57by the end of this we're going to have
  653. 25:58an algo working like it's going to work
  654. 26:02so
  655. 26:03am i going crazy yeah i am going crazy
  656. 26:08drop underscore nah who
  657. 26:11stop it
  658. 26:13who are you what are you thinking
  659. 26:18okay
  660. 26:19sweet
  661. 26:20it didn't drop now
  662. 26:40this is cody this is welcome to
  663. 26:43welcome to the show
  664. 26:45fishframe.drop 9.
  665. 27:03hmm
  666. 27:05maybe i need to put the uh
  667. 27:15all right whatever this isn't too
  668. 27:16important i'll get back to that
  669. 27:18um let's go ahead and so let's run this
  670. 27:21again make sure that we have the smas in
  671. 27:23there
  672. 27:26sorry i'm really into data science as
  673. 27:28well and machine learning so this type
  674. 27:31of stuff just kind of annoys me i feel
  675. 27:33like you know with machine learning you
  676. 27:35always want to get rid of rid of the
  677. 27:37nans
  678. 27:38the nons i really like indian non-2 but
  679. 27:42that's not the point
  680. 27:44but there's just no point right now for
  681. 27:46me to get rid of the n a n so i'm not
  682. 27:48gonna do that um
  683. 27:51sorry for getting into that but that's
  684. 27:52what codeine is you go down freaking
  685. 27:54rabbit holes
  686. 27:55so i have the sma 20 i think i want to
  687. 27:58go ahead and put another sma in there
  688. 28:00just in case let's do uh
  689. 28:02let's do a couple more sma
  690. 28:05no no i'm going down another rabbit hole
  691. 28:07let's not do that
  692. 28:10let's go ahead and make the 15 minute
  693. 28:11sma
  694. 28:13because remember we're gonna be buying
  695. 28:18around the 15 minutes i mean so let's
  696. 28:20just copy this
  697. 28:22and let's call this uh daily sma let's
  698. 28:24call this uh
  699. 28:3015.
  700. 28:35f-15 sounds good to me
  701. 28:37starting
  702. 28:4315 minute sma let's change this to 15
  703. 28:45minutes
  704. 28:46and then how many
  705. 28:48what is
  706. 28:50how many hours is that
  707. 29:03okay that's a lot it's a lot of data 15
  708. 29:06minutes 100 bars 15 minutes should be
  709. 29:08fine
  710. 29:12bars that's fine
  711. 29:15df
  712. 29:18dff let's do that dff
  713. 29:22so we're essentially just using the same
  714. 29:27same code but we're changing things up
  715. 29:29because remember now we're getting the
  716. 29:3015 minute sma
  717. 29:35dff
  718. 29:36okay does that look good
  719. 29:38to you it looks okay we're getting the
  720. 29:40data
  721. 29:41we're formatting the data
  722. 29:44we're changing the timestamp
  723. 29:47and we're creating the 20 sma
  724. 29:51but
  725. 29:52it's called 15
  726. 29:55and it would take dff dot close and find
  727. 29:58the rolling 20 minutes
  728. 30:00sorry 20 bars so essentially this is
  729. 30:02gonna find the last
  730. 30:05yeah this should be good
  731. 30:06i'll explain it here in just a second
  732. 30:09let's do
  733. 30:12f15 sma
  734. 30:15and then let's run it see what happens
  735. 30:21okay so sweet sweet sweet
  736. 30:23we have the 15 minutes you can see it's
  737. 30:25every 15 minutes
  738. 30:27have the data the open the high
  739. 30:30the low the clothes the volume
  740. 30:33and then
  741. 30:34wow it's a big volume spike
  742. 30:38what happened
  743. 30:43i need to write that down we got to make
  744. 30:44some sort of bot based off the volume
  745. 30:51i've been wanting to make a capitulation
  746. 30:53bot
  747. 31:07i like using volume a lot because i
  748. 31:08think it's a really good indicator you
  749. 31:10know
  750. 31:11how many people are buying and selling
  751. 31:14i feel like that's a really good
  752. 31:15indicator
  753. 31:16um okay so we have all this data now
  754. 31:20we've got the sma 20 15 minute
  755. 31:23and we've got the other one as well the
  756. 31:26daily and remember the strategy here
  757. 31:30is
  758. 31:33let's go ahead and put this here
  759. 31:36strategies to buy
  760. 31:39let's just refresh our memories here
  761. 31:44strat determine
  762. 31:47the
  763. 31:51the trend
  764. 31:52with
  765. 31:5420 day
  766. 31:58sma then based off
  767. 32:02trend
  768. 32:05buy
  769. 32:06or sell
  770. 32:08to open aka short or long
  771. 32:12around
  772. 32:13the
  773. 32:1515 minute sma
  774. 32:1920 day
  775. 32:21so pretty simple strategy
  776. 32:23but it's pretty awesome that you can
  777. 32:24automate this right so
  778. 32:26let's go ahead and clean this up a
  779. 32:27little bit
  780. 32:33so
  781. 32:34we're good to go i'm just thinking a
  782. 32:36little bit what should the next steps be
  783. 32:38so we found the 20 sma the daily
  784. 32:41that's awesome
  785. 32:43and
  786. 32:47we found the 15 minute sma
  787. 32:49which is awesome it's awesome awesome
  788. 32:53and let's go ahead let's return this df
  789. 32:58df
  790. 32:59f i want to combine combine these dfs
  791. 33:01now do i want to do that
  792. 33:08yeah i think that would be useful
  793. 33:10just in case
  794. 33:14dfd
  795. 33:16and then we'll call this
  796. 33:19df
  797. 33:20d
  798. 33:21equals that
  799. 33:23and then df
  800. 33:25f
  801. 33:27equals that okay
  802. 33:29so now we have both the functions
  803. 33:31and
  804. 33:35what i want to do is combine these two
  805. 33:40the reason being
  806. 33:42is because it'll be nice to work with
  807. 33:44combine
  808. 33:45the two data frames
  809. 33:49okay
  810. 33:50so let's just make sure everything's
  811. 33:52working dfd
  812. 33:54and print
  813. 33:58comma df
  814. 34:00f okay let's run this make sure both of
  815. 34:02the data frames
  816. 34:04are out here
  817. 34:11what's up with this though
  818. 34:15why is that
  819. 34:17sma 20
  820. 34:19make
  821. 34:24i think i should not print them here
  822. 34:27let's run that back just make sure
  823. 34:29everything's set up correctly
  824. 34:38weird thing happened here the sma 20
  825. 34:41jumped over here
  826. 34:42and i don't know why
  827. 34:47hmm
  828. 34:48is it my screen maybe
  829. 34:56does it shift it over
  830. 34:59interesting
  831. 35:03i think it's just an error with the uh
  832. 35:06the shift in
  833. 35:08on the output but
  834. 35:11oh it's because i did this stupid comma
  835. 35:13thing yeah that's
  836. 35:14why okay let's try this again
  837. 35:28all right now let's run it let's see if
  838. 35:30this looks nice
  839. 35:33okay perfect
  840. 35:35so
  841. 35:38time stamp
  842. 35:40i wonder why this time stamp has a
  843. 35:41minute oh it's because it's the 15
  844. 35:43minute that's why it's wider okay got it
  845. 35:45got it got it
  846. 35:47i actually don't want to combine those i
  847. 35:48forgot you don't want to combine those
  848. 35:50because one's on the 15 minute interval
  849. 35:53and one's on the daily i'm sure you
  850. 35:54already caught that to be honest
  851. 35:56but you know i'm making a video as well
  852. 35:58so
  853. 35:59i'm kind of multitasking um
  854. 36:02let's see here next thing we want to do
  855. 36:06let's look at the strategy
  856. 36:08we're determining the trend
  857. 36:11with the 20-day sma
  858. 36:14so let's determine the trend
  859. 36:21i think the way to determine the trend
  860. 36:23is if bid
  861. 36:26is under
  862. 36:29the
  863. 36:3020-day
  864. 36:31sma
  865. 36:32then it's
  866. 36:35equals bearish
  867. 36:38if
  868. 36:42bid is over
  869. 36:45sorry we shouldn't do bid we should do
  870. 36:48no let's do bid i like bid so that's the
  871. 36:50reason i like to bring the bid and
  872. 36:52asking is because it's a more real price
  873. 36:54it's like what's happening right now
  874. 36:56you know not 15 minutes ago what's
  875. 36:58happening right now if bid is bigger
  876. 37:00than
  877. 37:0220 day sma
  878. 37:04then um
  879. 37:06it goes bullish
  880. 37:09i think i'll just go ahead and build
  881. 37:11that into this function here
  882. 37:19okay
  883. 37:20i need to build a function here to get
  884. 37:22the bid and ask def
  885. 37:25bid
  886. 37:27our ask bid bid ask ask bid
  887. 37:34i know that's weird to do ask then bid
  888. 37:36but
  889. 37:37for some reason i outputted the ask
  890. 37:39first
  891. 37:40when i first got started
  892. 37:42got started
  893. 37:44and now i have to stick with it or else
  894. 37:46i'll forget
  895. 37:47okay so return to ask in a bit and to
  896. 37:50get the bin ask it's pretty easy i think
  897. 37:52we just do femix
  898. 37:54dot um
  899. 37:57fetch
  900. 37:58fetch uh
  901. 38:00order book
  902. 38:04and then
  903. 38:06symbol
  904. 38:07which is btc
  905. 38:09and then let's print
  906. 38:12order book
  907. 38:16print ob
  908. 38:19we got to make that variable real quick
  909. 38:23okay
  910. 38:24so this should print order book
  911. 38:27let's mark this out
  912. 38:30and i just have to figure out what the
  913. 38:32order back book looks like
  914. 38:35let's do a pretty print
  915. 38:38no i'm not gonna do that
  916. 38:44let's run this real quickly
  917. 38:49i'm gonna mark all of this stuff out for
  918. 38:52now
  919. 38:54i don't want anything else printed
  920. 38:57just want a bit in the ask and what i'm
  921. 38:59trying to do
  922. 39:00i'm getting the order book right here
  923. 39:02and then i need to tap into this so
  924. 39:05to tap it this is a dictionary and it
  925. 39:08looks like the bids are right here
  926. 39:10so i would type in bids let's keep this
  927. 39:14up here just so
  928. 39:15i can see it
  929. 39:19so these are the the most recent bids
  930. 39:21three four four seven nine
  931. 39:24and that's the number i need
  932. 39:26so where am i up here okay
  933. 39:29let's say bid
  934. 39:31equals
  935. 39:33and that would be order book
  936. 39:37and then i think i'd said bids right
  937. 39:39yeah bids
  938. 39:42and then it would be
  939. 39:44inside here
  940. 39:45i think that's zero zero
  941. 39:47if i remember correctly
  942. 39:50and then the ass
  943. 39:55would be ask right here
  944. 39:59and then
  945. 40:00change this to ask
  946. 40:03ask jeeves
  947. 40:05let's go ahead and do that
  948. 40:09and
  949. 40:10let's mark this out let's see if this
  950. 40:12works it should return like a tuple
  951. 40:15of my two things
  952. 40:19ask and bid so ask should be first bid
  953. 40:21should be second let's see if it works
  954. 40:30okay there we go so this is the ask this
  955. 40:33is the bid perfect
  956. 40:36okay so what i like to do sometimes is
  957. 40:37just note to self here
  958. 40:44um zero
  959. 40:46equals ask and
  960. 40:50one
  961. 40:53equals
  962. 40:55equals bid
  963. 40:57and then i can put it up here
  964. 41:00and then i can just get rid of that not
  965. 41:02get rid of it i didn't get rid of it
  966. 41:04don't worry don't worry don't worry it's
  967. 41:06just
  968. 41:07making this a little more beautiful
  969. 41:09okay so now we have bid ask and why do
  970. 41:12we need the bid ask if bid okay so we
  971. 41:14need to pull in bit
  972. 41:17bid equals
  973. 41:19what's it equal
  974. 41:21ask bid one
  975. 41:28okay
  976. 41:30and then so if bid is under
  977. 41:33let's make a little if statement if
  978. 41:35bid
  979. 41:36is under the sma
  980. 41:41i wonder if you can compare these two
  981. 41:43um i don't know if you can but we'll see
  982. 41:47i always trip up right here
  983. 41:48um
  984. 41:51if bid is under df
  985. 41:54sma 20
  986. 41:56print
  987. 41:58bearish
  988. 42:02else
  989. 42:06print
  990. 42:08bullish
  991. 42:10okay i'm just doing this because
  992. 42:12i don't know if this is gonna work
  993. 42:14because the bid is
  994. 42:16this is a panda's data frame
  995. 42:19it's always a little tricky but
  996. 42:22we'll figure it out together don't worry
  997. 42:24don't worry
  998. 42:27when you're working with pandas it's
  999. 42:29always kind of
  1000. 42:32different
  1001. 42:34let's go ahead and print
  1002. 42:38i can just run that
  1003. 42:46yep that's right so
  1004. 42:48the truth value of a series is ambiguous
  1005. 43:04okay i know how to do this i just need
  1006. 43:06to think a little bit so i'm thinking if
  1007. 43:08it's worth it to do it this way or if we
  1008. 43:10should just use
  1009. 43:13the
  1010. 43:14clothes the reason i don't really want
  1011. 43:17to use the clothes though is because
  1012. 43:18it's yesterday's clothes
  1013. 43:20and
  1014. 43:21things can change pretty quickly
  1015. 43:24so like for example if there's a huge
  1016. 43:26green bar or something we could pop into
  1017. 43:29a
  1018. 43:30bullish trend
  1019. 43:34so i kind of don't want to do that
  1020. 43:38um
  1021. 43:41just trying to think
  1022. 43:43the error essentially is you can't
  1023. 43:45compare this you can't compare like a
  1024. 43:47number
  1025. 43:49to um
  1026. 43:51a series
  1027. 43:53because this is actually like a data
  1028. 43:54frame full of numbers
  1029. 43:57and there's a pretty easy way to fix
  1030. 43:58that
  1031. 44:00just kind of racking my brain
  1032. 44:21one way i could do it is
  1033. 44:23no i'm not gonna do it that way
  1034. 44:51i've done this so many times
  1035. 44:53that
  1036. 44:54it's funny that i i don't
  1037. 44:58have the answer right here for me
  1038. 45:03okay so
  1039. 45:04i think
  1040. 45:06we're gonna try this
  1041. 45:13okay so
  1042. 45:14df
  1043. 45:16dot
  1044. 45:17d
  1045. 45:18dot low
  1046. 45:20df
  1047. 45:22d
  1048. 45:29and essentially i just need to compare
  1049. 45:31within
  1050. 45:38the bid um let's do 20 day sma okay
  1051. 45:43if that is bigger than the bid
  1052. 45:49then
  1053. 45:54we would do
  1054. 45:57sig which is
  1055. 45:59for signal
  1056. 46:01equals
  1057. 46:04if the sma is bigger than the bid it's
  1058. 46:07bearish
  1059. 46:10so let's do that
  1060. 46:12okay
  1061. 46:18see if this works i don't know if it's
  1062. 46:21gonna work
  1063. 46:27okay perfect it does
  1064. 46:31oh
  1065. 46:33the pandas is always a little tricky to
  1066. 46:34play with um
  1067. 46:37so it says sell sell sell
  1068. 46:40and i just want to make sure that's
  1069. 46:41correct
  1070. 46:43so the bid would be
  1071. 46:45about
  1072. 46:4735
  1073. 46:4934 523
  1074. 46:51and the sma is
  1075. 46:54holy smokes yes also so let's just
  1076. 46:57double check this works by flipping this
  1077. 47:00i always like to double check because
  1078. 47:02this is like a pretty important part of
  1079. 47:04the code right we want this is figuring
  1080. 47:06out the trend so
  1081. 47:08none oh it's because i didn't do
  1082. 47:11anything
  1083. 47:12okay
  1084. 47:23that's why okay so i have to set up two
  1085. 47:24of these actually
  1086. 47:26this is why we double check
  1087. 47:31and then let's do this
  1088. 47:36and let's call this buy
  1089. 47:38so just to make sure this is clear this
  1090. 47:40is like we're tapping into the df sma20
  1091. 47:43if it's if the sma20 is smaller than the
  1092. 47:45current bid this is the bid right now
  1093. 47:48then the signal column is going to say
  1094. 47:50bye
  1095. 47:58sell sells out okay okay
  1096. 48:00and
  1097. 48:03i'm just trying to think how can we
  1098. 48:04double check to make sure this is
  1099. 48:06correct
  1100. 48:07um
  1101. 48:10oh i know how
  1102. 48:13what if we change the bid
  1103. 48:16to
  1104. 48:1860 thousand
  1105. 48:22so
  1106. 48:23now the bid is sixty thousand that
  1107. 48:25should be higher than the sma
  1108. 48:28so it should say buy if this code works
  1109. 48:30correctly this should say
  1110. 48:33or the last few rows
  1111. 48:36okay perfect i think it's working
  1112. 48:38so
  1113. 48:40let me run this one more time and just
  1114. 48:43kind of
  1115. 48:44talk you through it
  1116. 48:45just in case you're
  1117. 48:47you're interested
  1118. 48:49kind of talking to myself at this point
  1119. 48:51but
  1120. 48:52essentially we pull in all the data and
  1121. 48:53then if the current bid here
  1122. 48:57it's actually not on here but we got the
  1123. 48:59bid from the bid and ask the actual bid
  1124. 49:02and ask
  1125. 49:03if that bid is smaller than this sma
  1126. 49:08then we should be selling we should open
  1127. 49:10as a cell
  1128. 49:12we should open as a cell
  1129. 49:16so i'm just going to write some notes
  1130. 49:18here
  1131. 49:20for myself
  1132. 49:26if
  1133. 49:27some a is bigger than
  1134. 49:31bid
  1135. 49:33equals
  1136. 49:35cell
  1137. 49:37if
  1138. 49:38sma is smaller than bid
  1139. 49:42equals buy okay perfect perfect perfect
  1140. 49:45perfect
  1141. 49:47now
  1142. 49:48i think we're really making progress
  1143. 49:49here this is awesome
  1144. 49:51i think we're good on this
  1145. 49:54this function right because
  1146. 49:56we're just trying to find the trend
  1147. 49:59and we do find that trend
  1148. 50:01it's going to tell us by ourselves and
  1149. 50:02this is why i love love love love love
  1150. 50:05algo trading because you don't have to
  1151. 50:07think after you code it it's just like
  1152. 50:09it is what it is computers are going to
  1153. 50:10do it and this way you don't have to
  1154. 50:13like be like oh my god it's going to go
  1155. 50:14higher it's going to go lower
  1156. 50:17oh because we all know how that works
  1157. 50:19out so um
  1158. 50:21all right so i think we're good to go
  1159. 50:23here
  1160. 50:25so let's just mark this out for now we
  1161. 50:27don't need it
  1162. 50:28we might need it later
  1163. 50:31let's go back to our strategy strat is
  1164. 50:33to determine the trend
  1165. 50:35with 20 day sma
  1166. 50:40done
  1167. 50:41buy and sell to open around the 15
  1168. 50:45minute sma
  1169. 50:47let's do
  1170. 50:48um
  1171. 50:50point
  1172. 50:51one no yeah point one percent under
  1173. 50:54and point
  1174. 50:56three percent
  1175. 50:58over
  1176. 50:59why did i pick those numbers well
  1177. 51:03i'm kind of guessing but
  1178. 51:05that being said that is like you know
  1179. 51:07when i hand trade this is kind of like a
  1180. 51:09strategy that i would try to follow i
  1181. 51:12would see okay well we're in a trend
  1182. 51:16let me see what the trend is and then
  1183. 51:18let's buy or sell around the smas you
  1184. 51:20know i think a lot of people follow
  1185. 51:22strategies similar to this so this this
  1186. 51:23could be all right
  1187. 51:25but the cool thing about algo trading is
  1188. 51:27like if you find an all right strategy
  1189. 51:30guess what tomorrow you have another day
  1190. 51:32and you can make that alright strategy
  1191. 51:35better and then the next day guess what
  1192. 51:38as long as you're healthy you wake up
  1193. 51:40you have another day and you make that
  1194. 51:41better and better and better so the the
  1195. 51:44key is to just get the strategies out
  1196. 51:46there right like every single day that's
  1197. 51:48why you see me here
  1198. 51:50my youtube channel is literally me
  1199. 51:52making strategies every day because
  1200. 51:55you know i've got a goal in my mind and
  1201. 51:56i'm going to get there i'm just going to
  1202. 51:57keep swimming until i get there and
  1203. 52:00if i can share this with you
  1204. 52:03that's amazing
  1205. 52:05because you're going to change your
  1206. 52:06trading forever right like it i'm not
  1207. 52:09saying you're going to have
  1208. 52:11i'm not guaranteeing profits or any of
  1209. 52:13that stuff but i am guaranteeing that
  1210. 52:16code can execute your trades for you if
  1211. 52:19you know how to code and then it's on
  1212. 52:22you i'm making the strategy like i'm
  1213. 52:24going to help you as much as possible by
  1214. 52:26creating these strategies
  1215. 52:28on youtube and of course
  1216. 52:30i have boot camps and whatnot that will
  1217. 52:32really accelerate your learning but
  1218. 52:35i'm here to help and i'm here to build
  1219. 52:37you know so
  1220. 52:40let's go ahead and build out the buying
  1221. 52:42part so
  1222. 52:44bye
  1223. 52:49so we have the bin ask we have the smas
  1224. 52:53we would be buying
  1225. 52:58oh let's put a buy price
  1226. 53:01um
  1227. 53:01[Music]
  1228. 53:08we need to figure out if it's a figure
  1229. 53:10out if by or sell to open
  1230. 53:17set
  1231. 53:19buy or sell
  1232. 53:21to open
  1233. 53:23price
  1234. 53:24and df
  1235. 53:25those are the two things we're going to
  1236. 53:26do right now so figure out if it's a buy
  1237. 53:28or sell to open we know that
  1238. 53:30we just have to pull this guy
  1239. 53:33how do you pull it you just pull this
  1240. 53:35over here we're gonna pull this data
  1241. 53:37frame into this data frame we'll get
  1242. 53:39data frames inside of data frames df
  1243. 53:44d equals that okay so we have that data
  1244. 53:46frame
  1245. 53:48and then
  1246. 53:51to get the last we want the last entry
  1247. 53:53of that data frame so dfd
  1248. 53:58d
  1249. 53:58and we want the last entry of the what
  1250. 54:01would i call it
  1251. 54:02the signal
  1252. 54:06sig
  1253. 54:08negative one this should give us the
  1254. 54:10last one
  1255. 54:13let's just see if we can get it
  1256. 54:17print
  1257. 54:32holy moly what am i doing
  1258. 54:35i just want to run this to make sure
  1259. 54:36that we can print it
  1260. 54:40we should go ahead and save really
  1261. 54:41quickly
  1262. 54:42it's always a good practice you know
  1263. 54:58dfd say
  1264. 55:15okay so so
  1265. 55:21let's try this let's call this sig
  1266. 55:27and then let's print
  1267. 55:29save
  1268. 55:30you one
  1269. 55:32see if that works
  1270. 55:39hmm
  1271. 55:44well you know what it's a good thing we
  1272. 55:46got google because
  1273. 55:48i do this all the time
  1274. 55:59okay
  1275. 56:17do you have the highlight
  1276. 56:29okay i could use a location if i wanted
  1277. 56:31to
  1278. 56:37but i kind of want to just pull pull one
  1279. 56:40value out of data frame
  1280. 56:52zero would do
  1281. 56:54zero
  1282. 56:56negative one hey
  1283. 56:59okay i think i got it
  1284. 57:02just use the location and try to get the
  1285. 57:04last one
  1286. 57:06so let me just write this down okay so
  1287. 57:09sig equals
  1288. 57:10df dot d
  1289. 57:12dot i log
  1290. 57:14slash
  1291. 57:17negative one
  1292. 57:19okay and then
  1293. 57:21let's see if this prints it out
  1294. 57:24i hope so
  1295. 57:30hey there it is
  1296. 57:32so okay um
  1297. 57:36i think that should be that should be
  1298. 57:38cool
  1299. 57:39because we're getting the last okay
  1300. 57:42last
  1301. 57:43signal
  1302. 57:46yeah the last signal
  1303. 57:48it prints the last signal okay
  1304. 57:51so we figured out if it's a buy or so
  1305. 57:56and then let's say
  1306. 57:59if sig
  1307. 58:02equals
  1308. 58:06cell print
  1309. 58:10we should be opening
  1310. 58:13as a cell
  1311. 58:17else
  1312. 58:19it's just
  1313. 58:21hopefully
  1314. 58:22the only thing else i can think of we
  1315. 58:25should be
  1316. 58:28opening as a
  1317. 58:31buy
  1318. 58:32okay i want to get rid of some print
  1319. 58:34statements
  1320. 58:37because there's a lot a lot a lot
  1321. 58:40see where else we're having printies at
  1322. 58:43that's a good one i like it
  1323. 58:46this one i don't want
  1324. 58:49no more
  1325. 58:52no more profile bar
  1326. 58:58let's run it see what happens
  1327. 59:04we should be opening it as a cell
  1328. 59:05perfect
  1329. 59:06okay
  1330. 59:07so now it knows
  1331. 59:09it's looking at the data
  1332. 59:12and says to me we should be opening as a
  1333. 59:15cell
  1334. 59:33um
  1335. 59:35i want to make a variable here
  1336. 59:38let's make open
  1337. 59:47as
  1338. 59:48by equals false
  1339. 59:56do i need that though
  1340. 1:00:00where am i doing this i'm doing it
  1341. 1:00:01inside of this 15 minute thing i don't
  1342. 1:00:03know if that's the right decision
  1343. 1:00:05put it in this function
  1344. 1:00:08because what are we trying to do here
  1345. 1:00:10set buy or sell price okay that's what
  1346. 1:00:13we're trying to do
  1347. 1:00:14i don't even know don't know if i need
  1348. 1:00:16all of this but
  1349. 1:00:18so this is a true at least so
  1350. 1:00:19essentially it's going to say it's open
  1351. 1:00:21is by is a false or open is by as a true
  1352. 1:00:26if it's a cell it's gonna be false
  1353. 1:00:28else it's gonna be true
  1354. 1:00:30so
  1355. 1:00:31df
  1356. 1:00:40do i need the open price yes i do
  1357. 1:00:47set buy or sell to open price in df
  1358. 1:00:51oh i can so i can do it here got it so
  1359. 1:00:54i'm just gonna set the data frame df dot
  1360. 1:00:57i think it was what f
  1361. 1:00:59um
  1362. 1:01:02sig
  1363. 1:01:03equals
  1364. 1:01:10bye
  1365. 1:01:11no so
  1366. 1:01:13i don't know if that's gonna work to be
  1367. 1:01:14honest
  1368. 1:01:16but
  1369. 1:01:18no that's not gonna work
  1370. 1:01:21again i'm running into that stupid
  1371. 1:01:23pandas thing
  1372. 1:01:33where you can't compare things when
  1373. 1:01:35pandas okay so i'm just gonna copy this
  1374. 1:01:36over
  1375. 1:01:37and use this as my comparer
  1376. 1:01:40instead of an if statement so
  1377. 1:01:42pandas can't really do this statements
  1378. 1:01:44in some ways because
  1379. 1:01:48it makes sense
  1380. 1:01:49but
  1381. 1:01:51essentially it
  1382. 1:01:52pandas can't do data uh compare
  1383. 1:01:55comparing
  1384. 1:01:58because it's a series of data not just
  1385. 1:02:00like one piece it's like i'm trying to
  1386. 1:02:02compare uh
  1387. 1:02:04one thing two
  1388. 1:02:06multiple things
  1389. 1:02:07so let's just get rid of that
  1390. 1:02:11now i'm gonna keep it for now okay so
  1391. 1:02:12now we want df.location
  1392. 1:02:15if
  1393. 1:02:31we should put sig here
  1394. 1:02:36sig
  1395. 1:02:48yeah
  1396. 1:02:50change this to f
  1397. 1:03:09i have a better way to do this so
  1398. 1:03:11essentially what i'm trying to
  1399. 1:03:14to do is figure out if it should be buy
  1400. 1:03:16or sell to open right so
  1401. 1:03:18df.daily smi
  1402. 1:03:21sma sig equals the last sig
  1403. 1:03:28but i actually don't need to do this
  1404. 1:03:30part so what i'm going to do instead
  1405. 1:03:33is
  1406. 1:03:38we'll make a buy price
  1407. 1:03:42and sell price
  1408. 1:03:45then
  1409. 1:03:47later
  1410. 1:03:48figure
  1411. 1:03:50out
  1412. 1:03:51which i should choose
  1413. 1:03:54so buy price one and sell price two uh
  1414. 1:03:58n2
  1415. 1:04:00so because we want to
  1416. 1:04:02i want to be able to you know i i'm sure
  1417. 1:04:04my entry is not gonna be perfect
  1418. 1:04:06so i wanna put in two so
  1419. 1:04:09let's say d let's make a bunch of data
  1420. 1:04:11frames here
  1421. 1:04:16and i'm going to call this uh buy price
  1422. 1:04:21buy price one
  1423. 1:04:24and
  1424. 1:04:26buy price two
  1425. 1:04:29and
  1426. 1:04:30sell price
  1427. 1:04:32one
  1428. 1:04:35and sell price too
  1429. 1:04:41okay
  1430. 1:04:42so we're good to go here
  1431. 1:04:45essentially i'm making four new columns
  1432. 1:04:47buy prices sell prices
  1433. 1:04:48and what did we say we wanted like 0.3
  1434. 1:04:51or something
  1435. 1:04:530.1
  1436. 1:04:56just copy this over
  1437. 1:05:12and this is what we're going to be doing
  1438. 1:05:13here buy and sell to open around the 15
  1439. 1:05:17minute
  1440. 1:05:18so this would be
  1441. 1:05:31buy price one
  1442. 1:05:36would be the 15 minute sma
  1443. 1:05:55one person point one percent under point
  1444. 1:05:57one percent under
  1445. 1:05:59and
  1446. 1:06:00point three percent over okay
  1447. 1:06:04so what is the sma
  1448. 1:06:06well it's up here
  1449. 1:06:0815-minute sma
  1450. 1:06:16value i believe
  1451. 1:06:24times
  1452. 1:06:261.001
  1453. 1:06:36i gotta mark all this out
  1454. 1:06:46let's print this df
  1455. 1:06:48okay
  1456. 1:06:50see if this works
  1457. 1:07:16okay perfect buy price one
  1458. 1:07:19would be
  1459. 1:07:20the sma
  1460. 1:07:23times
  1461. 1:07:28one point zero zero one it looks about
  1462. 1:07:30right
  1463. 1:07:32okay perfect perfect
  1464. 1:07:36and that's actually not right because we
  1465. 1:07:38want it one percent under
  1466. 1:07:40so it would be .999
  1467. 1:07:42[Music]
  1468. 1:07:46and then let's go ahead and copy this
  1469. 1:07:48over
  1470. 1:07:50and buy price two
  1471. 1:07:54would be over
  1472. 1:07:58bigger than one point zero zero
  1473. 1:08:02three remember i said point three
  1474. 1:08:03percent so move that over point three
  1475. 1:08:05this would be point one under point one
  1476. 1:08:08perfect
  1477. 1:08:12and then
  1478. 1:08:16i think that works right
  1479. 1:08:18do i even need the other two
  1480. 1:08:21let's just print it out and see what
  1481. 1:08:23happens
  1482. 1:08:30sheesh
  1483. 1:08:31it's getting big
  1484. 1:08:36so this would be sma 15
  1485. 1:08:48and
  1486. 1:08:50this will be the buy price one it'd be
  1487. 1:08:52right under the sma 15
  1488. 1:08:56and this would be right over the sma 15.
  1489. 1:09:04but but but but that's why we need four
  1490. 1:09:08columns okay i got it so this would be
  1491. 1:09:12point one percent under the sma
  1492. 1:09:15by one
  1493. 1:09:17and this would be
  1494. 1:09:18point three over the sma but remember
  1495. 1:09:21this
  1496. 1:09:23let's pretend the sma's right here
  1497. 1:09:26point one under will be right here and
  1498. 1:09:29point three over will be right here
  1499. 1:09:31so
  1500. 1:09:32that's good for the buys
  1501. 1:09:35but
  1502. 1:09:42not sure you go for the cells because
  1503. 1:09:43we'll be shorting here at the first one
  1504. 1:09:45and then shorting here at the second one
  1505. 1:09:47since this is selling
  1506. 1:09:48but then if we were going down here and
  1507. 1:09:50the sma were down below
  1508. 1:09:53by
  1509. 1:09:540.1
  1510. 1:09:56and then under 0.3
  1511. 1:09:59okay so that's why so the buy prices
  1512. 1:10:01they're going to be inverse so
  1513. 1:10:03this needs to be 1.001
  1514. 1:10:07and this needs to be
  1515. 1:10:110.997
  1516. 1:10:14and
  1517. 1:10:15essentially
  1518. 1:10:17this
  1519. 1:10:18the sell prices need to be the inverse
  1520. 1:10:20of that because we always want to sell
  1521. 1:10:23higher so what i'm trying to get at here
  1522. 1:10:24is like if the sma was down here
  1523. 1:10:28we'd want a 0.1 above to buy right here
  1524. 1:10:31and then our point three below be under
  1525. 1:10:34it because that's a better bot so it's
  1526. 1:10:35like falling into it boom fill fill but
  1527. 1:10:38if it's up here we want the point one to
  1528. 1:10:40be below so that'd be 0.999
  1529. 1:10:42and then the second buy will be over
  1530. 1:10:440.103
  1531. 1:10:46so
  1532. 1:10:480.999
  1533. 1:10:49and equals
  1534. 1:10:52equals
  1535. 1:10:531.003
  1536. 1:10:57okay cool cool cool i'm glad i got that
  1537. 1:10:59um
  1538. 1:11:01that would have been not terrible
  1539. 1:11:03but it would have been weird
  1540. 1:11:06we would just wouldn't have got as good
  1541. 1:11:07of entries so
  1542. 1:11:09that's the i mean that's the one thing
  1543. 1:11:11about augur trading though is like
  1544. 1:11:12you got to make sure you're you're right
  1545. 1:11:16oh you got to be correct it's fun though
  1546. 1:11:18because it's i'd rather be correct or
  1547. 1:11:20wrong i'd rather be wrong through code
  1548. 1:11:23than like emotionally like looking at
  1549. 1:11:25the chart all day and stuff it's
  1550. 1:11:27terrible
  1551. 1:11:28um
  1552. 1:11:30okay so
  1553. 1:11:31three four okay the let's say the open
  1554. 1:11:34three four okay
  1555. 1:11:36this looks fine to me um
  1556. 1:11:40all right so cool cool we've made some
  1557. 1:11:43progress here let's go ahead and delete
  1558. 1:11:45all this junk
  1559. 1:11:47i don't even know what i did there but
  1560. 1:11:49bye
  1561. 1:11:51okay
  1562. 1:11:53so we have a strategy now
  1563. 1:11:58we need to figure out the exit too
  1564. 1:12:01the entry
  1565. 1:12:05exit
  1566. 1:12:06i'm not gonna build a stop loss like i
  1567. 1:12:08said like i'm just gonna yolo it it's
  1568. 1:12:10100 we'll see what happens
  1569. 1:12:12let me know in the comment section below
  1570. 1:12:14if you're enjoying this you have any
  1571. 1:12:16questions if you want to see the results
  1572. 1:12:18later
  1573. 1:12:19let me know comment below but um
  1574. 1:12:23yeah this is fun
  1575. 1:12:24we're making progress here i think we're
  1576. 1:12:26about done too
  1577. 1:12:27so let's just um
  1578. 1:12:32let's print both our dfs
  1579. 1:12:34just to check in on them see if they're
  1580. 1:12:36still doing all right
  1581. 1:12:38like they've changed
  1582. 1:12:41literally why i code because things
  1583. 1:12:43don't change okay
  1584. 1:12:44there's a lot going on here now
  1585. 1:12:47bp
  1586. 1:12:48this is the one we need
  1587. 1:12:51tells us sell
  1588. 1:12:53boom boom
  1589. 1:12:55and then we would make okay if we're
  1590. 1:12:57selling we would make the first bid
  1591. 1:12:59here at two four two eight and then the
  1592. 1:13:02second bid will be a little bit higher
  1593. 1:13:04so
  1594. 1:13:05buy one
  1595. 1:13:06buy two
  1596. 1:13:09okay let's go ahead and make the buys i
  1597. 1:13:12think
  1598. 1:13:15entry and exit
  1599. 1:13:28okay i think i think we're good to go
  1600. 1:13:29let's go ahead and say def bot
  1601. 1:13:33just call this bot body bop
  1602. 1:13:37okay
  1603. 1:13:39let's bring in all this information that
  1604. 1:13:41we need
  1605. 1:13:42so this one
  1606. 1:13:46the f
  1607. 1:13:47sma oh i already have that actually
  1608. 1:13:51it's all there
  1609. 1:13:53and then bid ask
  1610. 1:13:56bid oops sorry
  1611. 1:13:58ask equals
  1612. 1:14:03ask bid
  1613. 1:14:06one
  1614. 1:14:07zero
  1615. 1:14:09and bid equals
  1616. 1:14:16ask
  1617. 1:14:18bid
  1618. 1:14:19one
  1619. 1:14:22let's just pull all this information in
  1620. 1:14:24here
  1621. 1:14:26to our bot
  1622. 1:14:36okay
  1623. 1:14:38so we get the daily sma
  1624. 1:14:42determines
  1625. 1:14:44long
  1626. 1:14:45short
  1627. 1:14:4615-minute sma
  1628. 1:14:50provides
  1629. 1:14:53prices
  1630. 1:14:58and what did i call them
  1631. 1:15:02dp and sp
  1632. 1:15:14okay so
  1633. 1:15:16didn't ask those are self-explanatory
  1634. 1:15:20let's make our entry
  1635. 1:15:26make the screen a little smaller again
  1636. 1:15:30and to enter this
  1637. 1:15:34how do we want to play this
  1638. 1:15:40of course we already set our params up
  1639. 1:15:45so we're good to go there
  1640. 1:15:48we've got the buy prices we've got the
  1641. 1:15:49long short
  1642. 1:16:17so inside the bar we need to figure out
  1643. 1:16:18first okay
  1644. 1:16:20make
  1645. 1:16:21open order
  1646. 1:16:25long or short
  1647. 1:16:28so to see long or short it'd be d f
  1648. 1:16:32d
  1649. 1:16:34i just did this so i'm just going to
  1650. 1:16:36grab it from up here i'm going to tap
  1651. 1:16:38into that df
  1652. 1:16:40df.lope
  1653. 1:16:43not that one
  1654. 1:16:48the one i did negative one remember
  1655. 1:16:53whoa whoa whoa whoa
  1656. 1:17:08df what was it df
  1657. 1:17:12dot lok i think
  1658. 1:17:17the um
  1659. 1:17:18sig
  1660. 1:17:20negative one
  1661. 1:17:30do you have the i look zero
  1662. 1:17:50i could have sworn i just wrote that
  1663. 1:17:56anyways i must have deleted it in that
  1664. 1:17:59whole
  1665. 1:18:00rage quit that's why you don't rage quit
  1666. 1:18:02that's why you don't just delete things
  1667. 1:18:03but
  1668. 1:18:05say print sick just to make sure
  1669. 1:18:09and then
  1670. 1:18:12from the bot let's run the bot
  1671. 1:18:28bid ask
  1672. 1:18:3092
  1673. 1:18:31made a silly mistake though
  1674. 1:18:46what
  1675. 1:18:47again
  1676. 1:18:51sheesh
  1677. 1:18:52she sheesh
  1678. 1:18:54fool me once for me twice for me thrice
  1679. 1:18:57let's see
  1680. 1:19:04okay so i got the cell perfect
  1681. 1:19:09and we'll call that
  1682. 1:19:12where we where we at
  1683. 1:19:14sig
  1684. 1:19:15um let's go ahead and get rid of that
  1685. 1:19:19let's go ahead
  1686. 1:19:20if sig
  1687. 1:19:24equals
  1688. 1:19:28by
  1689. 1:19:30print
  1690. 1:19:41as a buy okay
  1691. 1:19:45else
  1692. 1:19:52making an opening order
  1693. 1:19:54as a
  1694. 1:19:56cell let's run it one more time let's
  1695. 1:19:58just make sure
  1696. 1:19:59like i said i like to be double triple
  1697. 1:20:01quadruple checking things because this
  1698. 1:20:04is real money on the line
  1699. 1:20:06uh making an opening order as a
  1700. 1:20:09cell
  1701. 1:20:09perfect
  1702. 1:20:13now let's make the orders
  1703. 1:20:21actually i need to get the order prices
  1704. 1:20:34df
  1705. 1:20:39dff
  1706. 1:20:42dot i lock
  1707. 1:20:46negative one
  1708. 1:20:49um price what was that name bp bp1
  1709. 1:20:54bp1
  1710. 1:20:57that's not how i spelt it though
  1711. 1:21:01bp
  1712. 1:21:02one equals
  1713. 1:21:04and then bp2 equals that same thing but
  1714. 1:21:08a little different so i'm going into the
  1715. 1:21:11data frame getting the last one now i'm
  1716. 1:21:14getting buy price two
  1717. 1:21:16now let's do the same thing for sale
  1718. 1:21:18price
  1719. 1:21:29change to s's
  1720. 1:21:32things like this just make me fall in
  1721. 1:21:34love over and over again with coding
  1722. 1:21:37because it just changing letters is so
  1723. 1:21:40much better than looking at charts
  1724. 1:21:43oh gosh
  1725. 1:21:45okay so
  1726. 1:21:49print
  1727. 1:21:50f
  1728. 1:21:52this is
  1729. 1:21:53bp
  1730. 1:21:551
  1731. 1:21:57this is
  1732. 1:21:59bp
  1733. 1:22:002.
  1734. 1:22:02little f literal action here
  1735. 1:22:06bp
  1736. 1:22:082.
  1737. 1:22:10vp
  1738. 1:22:12one
  1739. 1:22:13perfect
  1740. 1:22:21let's change the letters again
  1741. 1:22:29okay perfect perfect
  1742. 1:22:33let's just run it
  1743. 1:22:43okay making an open order of cell this
  1744. 1:22:45is sell price one so
  1745. 1:22:48three four two eight one and three four
  1746. 1:22:51four one eight let's go over to my
  1747. 1:22:53exchange change change
  1748. 1:22:56and see what's going on here
  1749. 1:23:00ah this is such a great example of like
  1750. 1:23:03well i'm an algo trader because i would
  1751. 1:23:05just try to short this right here
  1752. 1:23:07but in reality i don't know
  1753. 1:23:09i don't know
  1754. 1:23:11i think my algo would too but
  1755. 1:23:14i don't know i don't know
  1756. 1:23:16i wouldn't be able to exit but with my
  1757. 1:23:19mind though
  1758. 1:23:20so a current price is three four five
  1759. 1:23:23two eight
  1760. 1:23:25three four five to it
  1761. 1:23:35and
  1762. 1:23:37the sma is three four
  1763. 1:23:41sell price one is three four
  1764. 1:23:43two eight one
  1765. 1:23:46three four
  1766. 1:23:48four one eight
  1767. 1:23:50so we must just be over the 15-minute
  1768. 1:23:52sma right now
  1769. 1:24:00hmm put the sma on here
  1770. 1:24:04um
  1771. 1:24:11whoa whoa whoa whoa whoa whoa
  1772. 1:24:15there's a lot i just want a simple
  1773. 1:24:17estimate
  1774. 1:24:19simple
  1775. 1:24:20moving
  1776. 1:24:23average
  1777. 1:24:25community scripts favorite scripts
  1778. 1:24:29technicals
  1779. 1:24:31indicators
  1780. 1:24:35so what i'm thinking is happening right
  1781. 1:24:36now is just
  1782. 1:24:39this is a smoothened
  1783. 1:24:42moving average
  1784. 1:24:43i think we're just over
  1785. 1:24:46sma
  1786. 1:24:48so
  1787. 1:24:51let's get rid of this one
  1788. 1:24:55and let's make this what did i say what
  1789. 1:24:56were we doing at 20
  1790. 1:24:5820 sma
  1791. 1:25:00style let's make it a little darker
  1792. 1:25:03a little bigger
  1793. 1:25:04oh
  1794. 1:25:06there we go
  1795. 1:25:12okay
  1796. 1:25:13so
  1797. 1:25:16let's change this to 15 minutes
  1798. 1:25:20okay that's that's the thing so this
  1799. 1:25:22looks a little weird because we're over
  1800. 1:25:24the sma
  1801. 1:25:25now the thing that i said at the very
  1802. 1:25:27start though won't let us submit this
  1803. 1:25:29order which is awesome
  1804. 1:25:32because i did post only orders i've got
  1805. 1:25:34another video about that but essentially
  1806. 1:25:36it allows you to say hey if this isn't
  1807. 1:25:38going to work as a limit order just
  1808. 1:25:40cancel it
  1809. 1:25:45speaking of that i'm going to go ahead
  1810. 1:25:47and put a time sleep
  1811. 1:25:52time dot sleep i'm gonna put um
  1812. 1:25:5610 minutes now let's do five minutes
  1813. 1:25:59because
  1814. 1:26:00if the the orders do get submitted and
  1815. 1:26:04canceled because the sma is higher
  1816. 1:26:07well
  1817. 1:26:08i don't want to
  1818. 1:26:14i don't want to um
  1819. 1:26:16i don't want to just keep sending orders
  1820. 1:26:18in okay so we're good to go we're good
  1821. 1:26:20to go we're good to go we're back on
  1822. 1:26:21track so we need to buy if signal equals
  1823. 1:26:24buy
  1824. 1:26:26print making buy order bp1
  1825. 1:26:31i got to figure out the size
  1826. 1:26:37i already put size of one at the very
  1827. 1:26:39top
  1828. 1:26:40but
  1829. 1:26:41let's see how much i can buy
  1830. 1:26:43i'm gonna i have leverage on here let's
  1831. 1:26:4725 x yolo that's crazy
  1832. 1:26:49but
  1833. 1:26:50whatever
  1834. 1:26:53btc usd margin
  1835. 1:26:56okay
  1836. 1:26:58let's say 10
  1837. 1:27:00how much does that cost
  1838. 1:27:0114
  1839. 1:27:03okay let's do 50 then
  1840. 1:27:05yeah 50 contracts will be good
  1841. 1:27:10so let's change our size to 50
  1842. 1:27:13and
  1843. 1:27:17that's position size is 50
  1844. 1:27:19but
  1845. 1:27:21i'm gonna have an open size too
  1846. 1:27:24why
  1847. 1:27:26watch
  1848. 1:27:29equals
  1849. 1:27:31you know it could be more sophisticated
  1850. 1:27:32than that but i'm essentially taking my
  1851. 1:27:35position size which is 50 and making
  1852. 1:27:38open size half of that so i can do two
  1853. 1:27:40orders because i have bio-order one by
  1854. 1:27:42order two so let's make these buy
  1855. 1:27:44orders um i want to make sure to do this
  1856. 1:27:47correctly i don't i'm not going to use a
  1857. 1:27:49stop stop loss like i said but
  1858. 1:27:53i am going to only do limit orders
  1859. 1:27:55that's for sure
  1860. 1:27:57so
  1861. 1:28:00themex
  1862. 1:28:02v mix
  1863. 1:28:04dot
  1864. 1:28:06create
  1865. 1:28:07limit buy order
  1866. 1:28:09and then we need to pass in the symbol
  1867. 1:28:12we need to pass in
  1868. 1:28:17um
  1869. 1:28:18open size
  1870. 1:28:20we need to pass in
  1871. 1:28:22the bid
  1872. 1:28:24so bp one
  1873. 1:28:27and then the params so this is what i
  1874. 1:28:30was talking about so in this example
  1875. 1:28:32right now like how the market currently
  1876. 1:28:35is
  1877. 1:28:36we're above the sma
  1878. 1:28:38but i believe on the daily
  1879. 1:28:41so remember our the way our bot works is
  1880. 1:28:44it sees where we're at
  1881. 1:28:46and if we're under this yellow line
  1882. 1:28:48right here
  1883. 1:28:49we're in a bear trend and we're only
  1884. 1:28:51selling to open
  1885. 1:28:53but then it's coming over here and
  1886. 1:28:55saying hey
  1887. 1:28:56the where are we going to open this at
  1888. 1:28:58well we're going to do this around the
  1889. 1:29:0015 minute
  1890. 1:29:01we're going to do 0.1 under and 0.3 over
  1891. 1:29:04but in this situation we just pop
  1892. 1:29:06through this so it's going to send the
  1893. 1:29:08orders but they're going to get
  1894. 1:29:10cancelled right away because i only
  1895. 1:29:12accept
  1896. 1:29:13limit orders if you go ahead and we look
  1897. 1:29:15at this params here this is what i set
  1898. 1:29:17up at the start params times time and
  1899. 1:29:20force means post only aka if this
  1900. 1:29:22doesn't work as a limit order do not
  1901. 1:29:26accept my order
  1902. 1:29:28pretty much never ever
  1903. 1:29:30ever please ever ever
  1904. 1:29:33never
  1905. 1:29:34let me be a market order
  1906. 1:29:36so we're doing two orders so let's do
  1907. 1:29:38this boom boom boom
  1908. 1:29:42and bp2 will be the second one and then
  1909. 1:29:45we want to do the same thing for
  1910. 1:29:47the cell orders
  1911. 1:29:51now i have to be sure to do this one
  1912. 1:29:53right
  1913. 1:29:54because
  1914. 1:29:55this
  1915. 1:29:56s open size symbol symbol i got to make
  1916. 1:29:59sure to make it sell
  1917. 1:30:01i have done that before whereas like i
  1918. 1:30:03copy like it's sometimes good to copy
  1919. 1:30:05but sometimes bad so this is a sell
  1920. 1:30:07price create order blah blah blah then
  1921. 1:30:09we'd sleep 300 seconds and i believe 300
  1922. 1:30:11seconds is 5 minutes
  1923. 1:30:14i think we're good
  1924. 1:30:19i think we are good to go i'm going to
  1925. 1:30:21pause these sleeps here
  1926. 1:30:23because
  1927. 1:30:26just for example purposes what we're
  1928. 1:30:28testing
  1929. 1:30:31this shouldn't fill any orders because
  1930. 1:30:32they're pretty out there
  1931. 1:30:34what else do we need to do
  1932. 1:30:36you know normally not normally actually
  1933. 1:30:38i don't always use a stop light loss
  1934. 1:30:40because i use my position size as my
  1935. 1:30:42stop-loss and like
  1936. 1:30:44just hey if it
  1937. 1:30:46works it works but if it doesn't it
  1938. 1:30:48doesn't and then just make sure to
  1939. 1:30:50control your push position size that's
  1940. 1:30:51how i control my risk a lot of the time
  1941. 1:30:53uh some some of my strategies though
  1942. 1:30:56definitely definitely definitely
  1943. 1:30:57definitely use a stop loss
  1944. 1:30:59um the one thing i think we're missing
  1945. 1:31:01here
  1946. 1:31:02is
  1947. 1:31:04the exit
  1948. 1:31:06so we got to do that
  1949. 1:31:09um i kind of want to test this out
  1950. 1:31:10though
  1951. 1:31:12let's just run it
  1952. 1:31:13what's the worst that could happen
  1953. 1:31:15i buy a hundred dollars worth
  1954. 1:31:22see if it makes the orders
  1955. 1:31:26okay perfect you can see it made the
  1956. 1:31:27orders but cancel them immediately
  1957. 1:31:30because of the post only that's awesome
  1958. 1:31:32once this drops down it will try to make
  1959. 1:31:34the orders again you know what we'll
  1960. 1:31:36loop that here at the end just so it
  1961. 1:31:38keeps running
  1962. 1:31:39but perfect perfect
  1963. 1:31:48okay
  1964. 1:31:49so i need to make an exit
  1965. 1:31:53death
  1966. 1:31:54exit
  1967. 1:31:59and
  1968. 1:32:01i think what i'm going to do with this
  1969. 1:32:03is
  1970. 1:32:04make an exit based on
  1971. 1:32:07my target
  1972. 1:32:09percentage
  1973. 1:32:11so let's go ahead and make a target
  1974. 1:32:14i'm gonna do uh
  1975. 1:32:1720
  1976. 1:32:20no
  1977. 1:32:22i'm risking a lot here
  1978. 1:32:24because i'm going i'm not having a stop
  1979. 1:32:26loss so i need to think this through i'm
  1980. 1:32:28going to do 30 so it's a little higher
  1981. 1:32:30but since i'm using leverage that's only
  1982. 1:32:32really like a one percent move
  1983. 1:32:35um
  1984. 1:32:37i think i wanted 25
  1985. 1:32:39okay so it'll take me out of the market
  1986. 1:32:4125
  1987. 1:32:44and
  1988. 1:32:45i don't want to just put a i guess i
  1989. 1:32:48could just put a
  1990. 1:32:52take profit
  1991. 1:32:57hmm
  1992. 1:33:00i could just set up a take profit on the
  1993. 1:33:02buy orders
  1994. 1:33:08i actually like this way better so i'm
  1995. 1:33:10gonna set up a function and then in that
  1996. 1:33:12function i'm gonna say hey if we hit my
  1997. 1:33:13target
  1998. 1:33:19if we hit target
  1999. 1:33:25then close
  2000. 1:33:29so
  2001. 1:33:29[Music]
  2002. 1:33:31how do we do this
  2003. 1:33:32we have to tap in now this is going to
  2004. 1:33:34be a little tricky because we have to
  2005. 1:33:35tap into a bunch of dictionaries but i
  2006. 1:33:38think this is the last thing
  2007. 1:33:44yeah i'm pretty sure this is the last
  2008. 1:33:46thing so
  2009. 1:33:48let's see how we're to pull this off
  2010. 1:33:55let me think about this for a second
  2011. 1:34:16so i think i'm gonna make this
  2012. 1:34:19um
  2013. 1:34:22it's pretty much gonna look
  2014. 1:34:25into my current positions
  2015. 1:34:30and
  2016. 1:34:32yeah okay so it's going to look into my
  2017. 1:34:33current positions
  2018. 1:34:36and
  2019. 1:34:39it will run every time the bot runs
  2020. 1:34:43right so
  2021. 1:34:49i think that makes sense
  2022. 1:35:16yeah so essentially we're going to have
  2023. 1:35:17it check this every time so exit
  2024. 1:35:23we're going to run this
  2025. 1:35:24checking to see
  2026. 1:35:28i gotta be able to type
  2027. 1:35:31print
  2028. 1:35:32checking to see if it's time to
  2029. 1:35:37exit
  2030. 1:35:43okay
  2031. 1:35:44so that looks good to me
  2032. 1:35:48um
  2033. 1:36:00i'm just trying to figure out how i go
  2034. 1:36:02about this because this is going to be a
  2035. 1:36:05fairly big function but it's not going
  2036. 1:36:07to be crazy big
  2037. 1:36:09that being said
  2038. 1:36:16i just gotta make sure to do it right
  2039. 1:36:20okay
  2040. 1:36:22i'm gonna call this p l close p l close
  2041. 1:36:25just because that's a little more
  2042. 1:36:26descriptive for me
  2043. 1:36:28and now i can know hey
  2044. 1:36:33checking if we hit our piano
  2045. 1:36:37okay
  2046. 1:36:38now the first thing we want to do
  2047. 1:36:40is set up some params
  2048. 1:36:44params
  2049. 1:36:46equal
  2050. 1:36:48type this is because i'm using
  2051. 1:36:53phoenix
  2052. 1:36:54i gotta like do some weird stuff with
  2053. 1:36:58with the codes of exactly how the um
  2054. 1:37:03how to tap into my open positions
  2055. 1:37:06so it's going to look something like
  2056. 1:37:08that it should be a dictionary though
  2057. 1:37:12okay
  2058. 1:37:14and then we want to say position
  2059. 1:37:17dictionary
  2060. 1:37:20position dictionary equals femix.fetch
  2061. 1:37:28fetch
  2062. 1:37:29positions
  2063. 1:37:32and then pass in the params so these
  2064. 1:37:34params are because i'm using the
  2065. 1:37:37contract
  2066. 1:37:38um things are a little different so
  2067. 1:37:41i need to print this out now because now
  2068. 1:37:43i need to figure out
  2069. 1:37:45how to get into
  2070. 1:37:47that
  2071. 1:37:49get into the dictionary and then figure
  2072. 1:37:51out like what my position size is
  2073. 1:37:55i need to put a position on
  2074. 1:37:57in order to figure this out so
  2075. 1:37:59let's see here let's just mark it
  2076. 1:38:02let's uh
  2077. 1:38:04i'm gonna short it
  2078. 1:38:07okay
  2079. 1:38:08perfect perfect just lost a little bit
  2080. 1:38:10of money
  2081. 1:38:11see how that goes for me
  2082. 1:38:14um let's do pnl close
  2083. 1:38:16and let's throw that
  2084. 1:38:20here and now i'm looking for a
  2085. 1:38:22dictionary
  2086. 1:38:29okay there it is
  2087. 1:38:31that's the one
  2088. 1:38:33what just happened
  2089. 1:38:39oh it's ah shoot i gotta be careful
  2090. 1:38:42about that it just ran the bot
  2091. 1:38:44um but luckily it just canceled the
  2092. 1:38:46orders
  2093. 1:38:48that reminds me actually i need to do
  2094. 1:38:49something else too
  2095. 1:38:52i need to cancel the orders
  2096. 1:39:02okay so i got that
  2097. 1:39:05let's do a
  2098. 1:39:09rando.json
  2099. 1:39:11let's throw that in there
  2100. 1:39:13let's format it
  2101. 1:39:16okay perfect perfect
  2102. 1:39:19i'm going to come back to that in just a
  2103. 1:39:20second sma bot
  2104. 1:39:22um
  2105. 1:39:23create
  2106. 1:39:24limit buy orders
  2107. 1:39:26i need to cancel all orders before i
  2108. 1:39:29make these or else it's just going to
  2109. 1:39:31keep making more and more orders thank
  2110. 1:39:33god i remember
  2111. 1:39:35phoenix.cancel
  2112. 1:39:37all orders
  2113. 1:39:39of the symbol
  2114. 1:39:49oh that's another thing
  2115. 1:39:52only run
  2116. 1:39:56if not in position
  2117. 1:40:01okay
  2118. 1:40:03if
  2119. 1:40:04in
  2120. 1:40:06position
  2121. 1:40:08equals
  2122. 1:40:10false
  2123. 1:40:12run this
  2124. 1:40:14hey i almost forgot that part almost
  2125. 1:40:16forgot that part and that would have
  2126. 1:40:18been bad
  2127. 1:40:20because what happened or what would have
  2128. 1:40:23happened if i didn't just put in
  2129. 1:40:24position
  2130. 1:40:25what would have happened
  2131. 1:40:27is
  2132. 1:40:30i would have just kept buying over and
  2133. 1:40:32over and over again
  2134. 1:40:36so we need to make sure to get in
  2135. 1:40:38position somewhere
  2136. 1:40:44let's return it from here
  2137. 1:40:57okay so two things i'm doing now i got
  2138. 1:40:59the position dictionary i need to figure
  2139. 1:41:01out how to figure out if um
  2140. 1:41:08i need to dive in here and
  2141. 1:41:12figure out what my p l is so i have to
  2142. 1:41:13figure out like what leverage i'm using
  2143. 1:41:16um
  2144. 1:41:18and the size
  2145. 1:41:20okay
  2146. 1:41:21so
  2147. 1:41:22checking to see if time to exit
  2148. 1:41:24so it looks like btc is zero so zero
  2149. 1:41:28dictionary and then i would need
  2150. 1:41:32let's set that up first actually
  2151. 1:41:35position dictionary
  2152. 1:41:40equals
  2153. 1:41:42position dick
  2154. 1:41:44at zero okay so now
  2155. 1:41:48we have that and then we have to figure
  2156. 1:41:50out what side
  2157. 1:41:51of order it is
  2158. 1:41:53so i'm looking for something inside okay
  2159. 1:41:55side
  2160. 1:41:58perfect
  2161. 1:42:00side equals position dictionary
  2162. 1:42:05of side
  2163. 1:42:07now we should have the side
  2164. 1:42:09and
  2165. 1:42:11we gotta get the entry price entry
  2166. 1:42:15price
  2167. 1:42:16equals
  2168. 1:42:22position dictionary
  2169. 1:42:29position dictionary and then
  2170. 1:42:32i need the price so the average entry
  2171. 1:42:34price what
  2172. 1:42:37should be average avg some
  2173. 1:42:43pretty much looking for the price
  2174. 1:42:44because i need to figure out the
  2175. 1:42:47average entry price ep average entry
  2176. 1:42:50price okay perfect grab that
  2177. 1:42:55perfect perfect
  2178. 1:42:57and i want to make that float actually
  2179. 1:43:03perfect perfect
  2180. 1:43:04um
  2181. 1:43:10let's get the leverage
  2182. 1:43:13leverage
  2183. 1:43:15equals
  2184. 1:43:17position dictionary
  2185. 1:43:20and i believe this one's just called
  2186. 1:43:22leverage
  2187. 1:43:30okay i also want to make that float
  2188. 1:43:34i guess it doesn't need to be a float
  2189. 1:43:35yeah actually no float's good floats
  2190. 1:43:36good
  2191. 1:43:43float okay now what
  2192. 1:43:47i need the current price
  2193. 1:43:52equals um
  2194. 1:43:54how do i get the current price i need
  2195. 1:43:55the bid and ask
  2196. 1:43:57where has been an ass
  2197. 1:44:04at ah the bid here
  2198. 1:44:07this is how much somebody's willing to
  2199. 1:44:09buy at so i'll call that current price
  2200. 1:44:17right
  2201. 1:44:18that makes sense
  2202. 1:44:19because if somebody's willing to bid
  2203. 1:44:21that means they're willing to buy so
  2204. 1:44:23that means that's the current price
  2205. 1:44:25in my opinion at least
  2206. 1:44:27we'll see if that works out for us
  2207. 1:44:33let's go ahead and print some stuff out
  2208. 1:44:35and just see if this is working print f
  2209. 1:44:39side
  2210. 1:44:48what else
  2211. 1:44:49entry
  2212. 1:44:51price
  2213. 1:44:58just wanna make sure i have all of this
  2214. 1:44:59information before i move forward
  2215. 1:45:03lav
  2216. 1:45:07equals leverage
  2217. 1:45:10what else do i need
  2218. 1:45:12i think we're good here i'm gonna close
  2219. 1:45:14this up
  2220. 1:45:16um close or not close it but let's see
  2221. 1:45:20here
  2222. 1:45:23hey
  2223. 1:45:33let's just say imposition is true for
  2224. 1:45:34now
  2225. 1:45:36so it doesn't run
  2226. 1:45:38okay let's see what happens
  2227. 1:45:44what i'm looking for is that thing i
  2228. 1:45:46just did average entry price
  2229. 1:45:48position dictionary key area key error
  2230. 1:45:51why
  2231. 1:45:53i don't get that
  2232. 1:46:00hmm
  2233. 1:46:04i just saw that there's average entry
  2234. 1:46:05price right here
  2235. 1:46:12average introvert
  2236. 1:46:19where'd i go wrong here
  2237. 1:46:22where did i go wrong
  2238. 1:46:33maybe i'll just do enterprise and see if
  2239. 1:46:35that works
  2240. 1:46:44run it back
  2241. 1:46:53perfect perfect perfect
  2242. 1:46:56so the side is short
  2243. 1:47:00leverage
  2244. 1:47:08huh
  2245. 1:47:09i feel like i'm in a different
  2246. 1:47:11dictionary
  2247. 1:47:12because it should say sell
  2248. 1:47:16the side should say sell not sure
  2249. 1:47:26side equals cell
  2250. 1:47:28so
  2251. 1:47:29another side
  2252. 1:47:31side
  2253. 1:47:32equals short
  2254. 1:47:36side equals cell
  2255. 1:47:39side equals short hmm
  2256. 1:47:42so what's going on here
  2257. 1:47:44i want to be in this so maybe i need to
  2258. 1:47:46tap into info
  2259. 1:48:06position dictionary is zero
  2260. 1:48:12info maybe
  2261. 1:48:51whatever that works
  2262. 1:48:52uh we'll just do this then we'll just do
  2263. 1:48:54uh
  2264. 1:48:55keep it at zero
  2265. 1:48:58and knowing that it's short or long
  2266. 1:49:06okay
  2267. 1:49:08so now we need to figure out
  2268. 1:49:12because now we're trying to look at our
  2269. 1:49:13p l right we're trying to look at our p
  2270. 1:49:15l so we need to figure out
  2271. 1:49:17if the side
  2272. 1:49:19if side equals
  2273. 1:49:21um let's say
  2274. 1:49:23long
  2275. 1:49:28i need to make sure that it says that
  2276. 1:49:30word long
  2277. 1:49:33so i'm just gonna
  2278. 1:49:35look at that i made a little money mark
  2279. 1:49:36it
  2280. 1:49:37sell this
  2281. 1:49:39and then it's long it
  2282. 1:49:42and let's run this
  2283. 1:49:44i want to make sure that that word says
  2284. 1:49:46long
  2285. 1:50:08we know the first word it says short
  2286. 1:50:10okay perfect it says long okay so if
  2287. 1:50:12side is long
  2288. 1:50:15then the difference
  2289. 1:50:18will be the current price
  2290. 1:50:20minus
  2291. 1:50:21the entry price right because if it's
  2292. 1:50:25long it's the difference is going to be
  2293. 1:50:27a little different than the
  2294. 1:50:29if it's short it's going to be the
  2295. 1:50:31opposite right difference equals entry
  2296. 1:50:33price
  2297. 1:50:34minus
  2298. 1:50:36current price okay so now we have the
  2299. 1:50:39difference
  2300. 1:50:41i want to find the percentage um and i
  2301. 1:50:43have to do this in a try block because
  2302. 1:50:45it might not return so
  2303. 1:50:47percentage equals
  2304. 1:50:49round
  2305. 1:50:53let's round it so we have to do that and
  2306. 1:50:55then we want to make another one and
  2307. 1:50:57another one diff
  2308. 1:50:59entry price
  2309. 1:51:01and then multiply that by the leverage
  2310. 1:51:06and i just want uh
  2311. 1:51:0810 spaces
  2312. 1:51:10okay and then if that doesn't work and
  2313. 1:51:12the reason this won't work sometimes is
  2314. 1:51:14because we won't have a
  2315. 1:51:18we won't have a position
  2316. 1:51:21so let's go ahead and say
  2317. 1:51:24print
  2318. 1:51:26f
  2319. 1:51:28side nope i don't need that
  2320. 1:51:31diff
  2321. 1:51:34and then also the perk
  2322. 1:51:41so i want the difference
  2323. 1:51:44and the percentage
  2324. 1:51:53okay so this it shows okay there it is
  2325. 1:51:56uh the difference
  2326. 1:51:59between our entry and the current price
  2327. 1:52:02is
  2328. 1:52:02negative 10
  2329. 1:52:04and this is our percentage actually
  2330. 1:52:05that's not it means close to our
  2331. 1:52:07percentage we just have to make some
  2332. 1:52:10[Music]
  2333. 1:52:11updates
  2334. 1:52:13so let's go ahead and say perk
  2335. 1:52:16part
  2336. 1:52:18equals
  2337. 1:52:19100 times perk because it was a decimal
  2338. 1:52:23prior
  2339. 1:52:24and we can say print
  2340. 1:52:27the
  2341. 1:52:28this
  2342. 1:52:30this
  2343. 1:52:31is our piano
  2344. 1:52:35percentage
  2345. 1:52:38and then we can double check it
  2346. 1:52:41because you can never
  2347. 1:52:42be
  2348. 1:52:44sure
  2349. 1:52:46so this should
  2350. 1:52:48give us our p l percentage
  2351. 1:52:50let's go check what our p l percentage
  2352. 1:52:52is
  2353. 1:52:53word
  2354. 1:52:54negative point eight four
  2355. 1:52:56percent but
  2356. 1:52:59let's hover over point one or one
  2357. 1:53:02percent
  2358. 1:53:06point four three percent okay this looks
  2359. 1:53:09about right um it's always just a little
  2360. 1:53:11bit different because some using mark
  2361. 1:53:13price i'm just using last price it's
  2362. 1:53:150.38 versus 0.4
  2363. 1:53:183. that's really close i did my own math
  2364. 1:53:21here that's another thing so
  2365. 1:53:23um to be that close it's great okay so
  2366. 1:53:26now we have the p l percentage
  2367. 1:53:29and remember our target
  2368. 1:53:32is 30 or 25
  2369. 1:53:38let's see hmm
  2370. 1:53:55um
  2371. 1:53:56how would we do this
  2372. 1:54:03okay so
  2373. 1:54:04if the percentage is bigger than zero
  2374. 1:54:06that means there's a percentage
  2375. 1:54:08we can all agree on that
  2376. 1:54:10uh okay if percentage is bigger than
  2377. 1:54:12zero we gotta do some stuff print
  2378. 1:54:15we are
  2379. 1:54:17in
  2380. 1:54:18a winning position
  2381. 1:54:23and then
  2382. 1:54:26if the percent because we're making our
  2383. 1:54:28exit here right so what i'm trying to do
  2384. 1:54:31here is if a percent goes over our
  2385. 1:54:32target size then we
  2386. 1:54:36we
  2387. 1:54:37kill the position
  2388. 1:54:40because we want
  2389. 1:54:41right
  2390. 1:54:42okay so that makes sense to me so if
  2391. 1:54:45perk is bigger than the target
  2392. 1:54:51print
  2393. 1:54:54um
  2394. 1:54:55smiles
  2395. 1:54:58starting
  2396. 1:54:59the kill switch
  2397. 1:55:02because
  2398. 1:55:03we
  2399. 1:55:04hit our
  2400. 1:55:06target
  2401. 1:55:12of sorry you can't see that
  2402. 1:55:24target
  2403. 1:55:27little ff there
  2404. 1:55:30perfect
  2405. 1:55:36and then we want to go ahead and say
  2406. 1:55:42p l close
  2407. 1:55:44equals true that will be useful later
  2408. 1:55:48and then we want to call our kill switch
  2409. 1:55:52which we haven't created yet
  2410. 1:55:56so let's create that
  2411. 1:56:08this kill switch is going to gracefully
  2412. 1:56:10take us out
  2413. 1:56:15so essentially instead of like market
  2414. 1:56:17closing where you have to pay a bunch of
  2415. 1:56:18fees i like to limit close and
  2416. 1:56:21uh i'll build that here in a second
  2417. 1:56:31okay starting the kill switch let's go
  2418. 1:56:34back down here
  2419. 1:56:35figure this all out
  2420. 1:56:37so if percentage is over target print
  2421. 1:56:39kill switch
  2422. 1:56:43else
  2423. 1:56:47print
  2424. 1:56:49we have
  2425. 1:56:51not hit our target
  2426. 1:56:54yet this is actually where i would put
  2427. 1:56:57in a um
  2428. 1:57:04i don't want to do else do i
  2429. 1:57:08i do want to do well this is also where
  2430. 1:57:10i'd put a stop loss but i'm not going to
  2431. 1:57:12do it for this one i'm using the
  2432. 1:57:15position size as my stop loss so
  2433. 1:57:19let's go ahead and put another else over
  2434. 1:57:21here at the end of this you know print
  2435. 1:57:26we are
  2436. 1:57:27not
  2437. 1:57:28in position
  2438. 1:57:32okay
  2439. 1:57:38how's this look this looks good to me
  2440. 1:57:44i'm gonna put p l close up here
  2441. 1:57:48before we start this
  2442. 1:57:50as false
  2443. 1:57:52i think it's default false actually so i
  2444. 1:57:55didn't need to do that but
  2445. 1:57:56that's fine
  2446. 1:58:00i'm getting thirsty i should have
  2447. 1:58:01brought some water over here but i think
  2448. 1:58:03we're almost finished so i need to call
  2449. 1:58:05that kill switch
  2450. 1:58:06print that
  2451. 1:58:07i think we're good on this part
  2452. 1:58:11um
  2453. 1:58:14let's just do some more print statements
  2454. 1:58:16because i love them
  2455. 1:58:18uh
  2456. 1:58:19just finished checking
  2457. 1:58:23p l close just so we know and then let's
  2458. 1:58:27return p l
  2459. 1:58:29close
  2460. 1:58:30so essentially this is going to go
  2461. 1:58:32through it's going to figure out all the
  2462. 1:58:34information i need right it's
  2463. 1:58:37like my position side um the price
  2464. 1:58:42the leverage
  2465. 1:58:44and then it's going to do a little math
  2466. 1:58:47based on if it's long then the current
  2467. 1:58:49price or the difference price difference
  2468. 1:58:51would be the current price minus the
  2469. 1:58:53entry price
  2470. 1:58:58right
  2471. 1:58:59because the entry price would be lower
  2472. 1:59:01current price
  2473. 1:59:06yeah that's right that's right and then
  2474. 1:59:08down here it would try to round this
  2475. 1:59:10percentage and do all this math to find
  2476. 1:59:11the percentage and then multiply the
  2477. 1:59:13percentage
  2478. 1:59:14should put that here
  2479. 1:59:17well i don't need this anymore actually
  2480. 1:59:20and then it you know multiplies the
  2481. 1:59:21percentage and this is our p l
  2482. 1:59:23sets p l close to false which it should
  2483. 1:59:26do by by default
  2484. 1:59:28um if percentage is over zero that means
  2485. 1:59:32we're in position
  2486. 1:59:34oh snap i need in position too
  2487. 1:59:41yes
  2488. 1:59:45equals true
  2489. 1:59:52all right so imposition is now true
  2490. 1:59:56i'm going to put in position as false
  2491. 1:59:58here i don't know why i do this but
  2492. 2:00:01just to like remind me i guess that
  2493. 2:00:05we're using that imposition is false and
  2494. 2:00:08then if the percentage is over
  2495. 2:00:10zero in position is true
  2496. 2:00:14but snap if it's less than zero its
  2497. 2:00:17imposition is true too
  2498. 2:00:20hmm
  2499. 2:00:32so i need to put a lift here
  2500. 2:00:38perk is under zero because we might be
  2501. 2:00:40in a losing position
  2502. 2:00:42print
  2503. 2:00:44we
  2504. 2:00:45we are in a losing position
  2505. 2:00:49but
  2506. 2:00:50holding on
  2507. 2:00:53and then this would be in
  2508. 2:00:55position
  2509. 2:00:57equals true
  2510. 2:00:59just like that
  2511. 2:01:01right
  2512. 2:01:02so it's false
  2513. 2:01:03and then it's true if it's above or
  2514. 2:01:05under
  2515. 2:01:07and then else it stays false
  2516. 2:01:10so we don't need to change anything and
  2517. 2:01:12then we return
  2518. 2:01:13p l close
  2519. 2:01:15equals
  2520. 2:01:20r
  2521. 2:01:24not here though
  2522. 2:01:27because we don't want to piano close yet
  2523. 2:01:30we want the p l close to be false
  2524. 2:01:32if it's over zero we are in a winning
  2525. 2:01:34position if perk is over target then p l
  2526. 2:01:37closes true and we hit kill switch
  2527. 2:01:41and
  2528. 2:01:42okay i think we're good to go
  2529. 2:01:47p l close
  2530. 2:01:50let's do this so i can carry this
  2531. 2:01:53so zero is pinot close
  2532. 2:02:00and
  2533. 2:02:02one is
  2534. 2:02:04in position right
  2535. 2:02:09p l close
  2536. 2:02:11piano close pnl close
  2537. 2:02:15okay so let's take this on down and
  2538. 2:02:18before we make the kill switch i think
  2539. 2:02:19the kill switch is the last thing so i'm
  2540. 2:02:21getting pretty excited because we're
  2541. 2:02:22really close
  2542. 2:02:24so if in position
  2543. 2:02:32in position
  2544. 2:02:35equals
  2545. 2:02:40[Music]
  2546. 2:02:41p l
  2547. 2:02:42close
  2548. 2:02:45one okay
  2549. 2:02:46i should say it's true or false i can
  2550. 2:02:48delete this now
  2551. 2:02:51and
  2552. 2:02:52wait right
  2553. 2:02:53yeah yeah
  2554. 2:02:58i always forget these little guys
  2555. 2:03:00so imposition should be set to whatever
  2556. 2:03:02or yes true or false if it's true
  2557. 2:03:07it's just gonna
  2558. 2:03:09what's it gonna do it's gonna do nothing
  2559. 2:03:15let's go ahead and
  2560. 2:03:17it would still work without this but
  2561. 2:03:19print
  2562. 2:03:22we are
  2563. 2:03:25in position
  2564. 2:03:27already
  2565. 2:03:29so not
  2566. 2:03:30making
  2567. 2:03:32new
  2568. 2:03:34orders
  2569. 2:03:36perfect perfect
  2570. 2:03:40let's get rid of some of these print
  2571. 2:03:41statements
  2572. 2:03:48i pretty just want pretty much just want
  2573. 2:03:49the text that i'm sending i don't want
  2574. 2:03:51the dfs
  2575. 2:04:00these two i don't want those
  2576. 2:04:02pretty much
  2577. 2:04:03and i think there might be another one
  2578. 2:04:05print df
  2579. 2:04:08i just want the data that i write
  2580. 2:04:12okay
  2581. 2:04:13i think we're good to go
  2582. 2:04:16so if i run this now it should say we're
  2583. 2:04:19not making a position because it's not
  2584. 2:04:21like we're not
  2585. 2:04:29we are in position already so not making
  2586. 2:04:31new orders perfect perfect
  2587. 2:04:34looks like we're down
  2588. 2:04:361.337 percent
  2589. 2:04:38we have a side of long entry price
  2590. 2:04:41leverage 25. this is looking really good
  2591. 2:04:44i don't know why it repeats the data
  2592. 2:04:49oh it's because i call the function
  2593. 2:04:51multiple times
  2594. 2:04:53i don't care about that right now i just
  2595. 2:04:55want to get this working
  2596. 2:04:57to be honest i'm very thirsty
  2597. 2:05:00so i got to make this kill switch i had
  2598. 2:05:02that big cup of coffee and you know when
  2599. 2:05:03you have coffee and
  2600. 2:05:04you don't have much water
  2601. 2:05:08i'm feeling that way
  2602. 2:05:09i should probably eat something too
  2603. 2:05:12but
  2604. 2:05:13let's get this done i think i'm i'm
  2605. 2:05:15almost done we just need to make the
  2606. 2:05:16kill switch so how do we make the kill
  2607. 2:05:19switch
  2608. 2:05:20the kill switch is pretty much just a
  2609. 2:05:22graceful close that's what i like to
  2610. 2:05:24call it at least
  2611. 2:05:26instead of like market closing
  2612. 2:05:29because
  2613. 2:05:31you're
  2614. 2:05:33either your stop loss goes off or your
  2615. 2:05:37target gets hit
  2616. 2:05:38instead of doing that
  2617. 2:05:40i like to just be graceful with it
  2618. 2:05:42because femix actually pays you to
  2619. 2:05:45create limit orders
  2620. 2:05:47so you have to pay
  2621. 2:05:49point zero
  2622. 2:05:50point zero seven five percent if you
  2623. 2:05:55use market orders but you get paid point
  2624. 2:05:58zero two five percent if you
  2625. 2:06:01make
  2626. 2:06:03limit orders
  2627. 2:06:05okay
  2628. 2:06:10so first we need to see if we have open
  2629. 2:06:12positions
  2630. 2:06:17and
  2631. 2:06:22i probably could just say that in here
  2632. 2:06:25imposition equals true
  2633. 2:06:27yeah
  2634. 2:06:29perfect
  2635. 2:06:41i'm going to call this open position
  2636. 2:06:44equals that and that
  2637. 2:06:48this should give the true house
  2638. 2:06:51perfect
  2639. 2:06:53and then law
  2640. 2:06:56uh let's get it long true or false
  2641. 2:07:01long equals
  2642. 2:07:04true or false but how would i do that
  2643. 2:07:22do i need that we'll see
  2644. 2:07:32i should pass some more information
  2645. 2:07:33actually
  2646. 2:07:41side
  2647. 2:07:45i should figure out the size as well
  2648. 2:08:05so this will be the size
  2649. 2:08:15okay
  2650. 2:08:16contracts would be the size
  2651. 2:08:19and then we could say return this size
  2652. 2:08:21as well
  2653. 2:08:26and then i want to say if size is
  2654. 2:08:30if size is bigger than
  2655. 2:08:33zero
  2656. 2:08:35um what do i need here
  2657. 2:08:41no i don't need that
  2658. 2:08:44the imposition would be true but
  2659. 2:08:46what am i looking for is the question
  2660. 2:08:50i'm looking to see if it's long or short
  2661. 2:08:53and i know i have that here if side is
  2662. 2:08:57long
  2663. 2:09:00and long equals true
  2664. 2:09:06and
  2665. 2:09:07long
  2666. 2:09:08equals false
  2667. 2:09:17pass it through long as well and see
  2668. 2:09:18what happens so size and long are now
  2669. 2:09:21part of this
  2670. 2:09:22size is three or two
  2671. 2:09:27two is size
  2672. 2:09:29and three
  2673. 2:09:31is long
  2674. 2:09:33okay perfect perfect perfect perfect
  2675. 2:09:41so p l will be size the
  2676. 2:09:46long would be this
  2677. 2:09:48three
  2678. 2:09:52and size
  2679. 2:09:55would be this
  2680. 2:09:58two
  2681. 2:09:59let's just make sure we have everything
  2682. 2:10:01print
  2683. 2:10:02f
  2684. 2:10:03um
  2685. 2:10:07open position
  2686. 2:10:12long
  2687. 2:10:15and size
  2688. 2:10:26do you think we're gonna air probably
  2689. 2:10:30just put a bunch of stars just so i see
  2690. 2:10:31it kill switch
  2691. 2:10:47piano close is not defined
  2692. 2:10:50113.
  2693. 2:10:54mm-hmm it's because
  2694. 2:11:00it's below it
  2695. 2:11:06all right i'm gonna make another
  2696. 2:11:07function really quickly
  2697. 2:11:09and it's going to be called open
  2698. 2:11:11positions
  2699. 2:11:12so i'm just going to get a bunch of data
  2700. 2:11:14that i need and i'm just going to try to
  2701. 2:11:16do this quickly i do this one all the
  2702. 2:11:18time so
  2703. 2:11:20def open
  2704. 2:11:21positions
  2705. 2:11:22and this is a good one to to know how to
  2706. 2:11:25do
  2707. 2:11:26because
  2708. 2:11:28you're going to use it all the time or i
  2709. 2:11:30use it all the time
  2710. 2:11:31type
  2711. 2:11:33swap
  2712. 2:11:37code
  2713. 2:11:39usd okay perfect
  2714. 2:11:42uh fee
  2715. 2:11:44bao equals
  2716. 2:11:46femix dot
  2717. 2:11:48fetch balance
  2718. 2:11:52params equal params so i'm just gonna
  2719. 2:11:55get all the information that i need
  2720. 2:11:57because uh it's just giving me a hard
  2721. 2:11:59time so open positions
  2722. 2:12:06equals
  2723. 2:12:08fibal
  2724. 2:12:10i think it's info
  2725. 2:12:13data positions
  2726. 2:12:21okay so we got that
  2727. 2:12:23and let's print open positions
  2728. 2:12:32and see if we can get our open positions
  2729. 2:12:34because then we'll have all the
  2730. 2:12:35information we need
  2731. 2:12:38it's going to give me error because of
  2732. 2:12:39that last thing but that's fine okay i
  2733. 2:12:41got open positions
  2734. 2:12:43perfect
  2735. 2:12:48now
  2736. 2:12:51what do we want to do with these open
  2737. 2:12:52positions
  2738. 2:12:59i actually need that information because
  2739. 2:13:01i need to format it and see
  2740. 2:13:04where things are
  2741. 2:13:09i cannot remember it's too many
  2742. 2:13:11dictionaries for me
  2743. 2:13:15let's go over here
  2744. 2:13:19um
  2745. 2:13:23let's throw it in here
  2746. 2:13:26let's do a little format in here
  2747. 2:13:28format document
  2748. 2:13:30so zero
  2749. 2:13:32okay so we're on the zero index
  2750. 2:13:35and the thing i need to get is the side
  2751. 2:13:39side is by
  2752. 2:13:42and then the size
  2753. 2:13:49size is one perfect so side inside side
  2754. 2:13:52and side side and side side
  2755. 2:13:55open
  2756. 2:13:56position side equals open
  2757. 2:14:02positions
  2758. 2:14:04and it was zero here
  2759. 2:14:07and it was side right
  2760. 2:14:09and then the same thing for size
  2761. 2:14:13but the difference is this part size
  2762. 2:14:17perfect
  2763. 2:14:22now i want to say
  2764. 2:14:25if open
  2765. 2:14:27position side
  2766. 2:14:30equals just in case let's say bye
  2767. 2:14:33oops i think it's that
  2768. 2:14:37then open position
  2769. 2:14:39bull
  2770. 2:14:41equals
  2771. 2:14:43true
  2772. 2:14:45long equals
  2773. 2:14:47true
  2774. 2:14:48perfect i can use those later lf
  2775. 2:14:51open
  2776. 2:14:53side
  2777. 2:14:55equals just in case
  2778. 2:14:57cell
  2779. 2:15:00open position bull
  2780. 2:15:03equals true
  2781. 2:15:05and
  2782. 2:15:07long
  2783. 2:15:09equals false
  2784. 2:15:12okay
  2785. 2:15:13that makes sense right getting all that
  2786. 2:15:15information else
  2787. 2:15:17open position bool equals false
  2788. 2:15:21and long
  2789. 2:15:24long equals let's just do none for now
  2790. 2:15:27so now we're going to say hey if the
  2791. 2:15:29side is bi then we know we're going to
  2792. 2:15:31put a bull
  2793. 2:15:32open position bull true long is true
  2794. 2:15:35else
  2795. 2:15:36alif if it's cell then it's open
  2796. 2:15:38position bool is also true
  2797. 2:15:41and long equals false because we're not
  2798. 2:15:43long
  2799. 2:15:46okay i think we might have all the
  2800. 2:15:48information we need now but
  2801. 2:15:50let's uh let's try this out let's return
  2802. 2:15:54open positions
  2803. 2:15:56first chisel
  2804. 2:15:58open position bool
  2805. 2:16:00again for a chisel
  2806. 2:16:02open position size
  2807. 2:16:05absolutely
  2808. 2:16:07and long
  2809. 2:16:13perfect
  2810. 2:16:27okay now i can drag this around with me
  2811. 2:16:30and i might move that up later but
  2812. 2:16:33let's see if it just runs
  2813. 2:16:41okay perfect perfect
  2814. 2:16:45let's drag this in and
  2815. 2:16:50so open position side
  2816. 2:16:53let's try this again
  2817. 2:17:00so open position should be open
  2818. 2:17:03positions now
  2819. 2:17:09and
  2820. 2:17:10if you want and that should set a true
  2821. 2:17:12or false
  2822. 2:17:13and then same with this one
  2823. 2:17:18long
  2824. 2:17:19equals
  2825. 2:17:22what is long 0 1 2 3. so 3
  2826. 2:17:26and then size
  2827. 2:17:29is open positions
  2828. 2:17:31two
  2829. 2:17:32right zero one two yep
  2830. 2:17:35perfect we're doing good we're doing
  2831. 2:17:37good
  2832. 2:17:38and
  2833. 2:17:41let's see if it works
  2834. 2:17:45i'm looking for this starred line
  2835. 2:17:47specifically
  2836. 2:17:50ah yes there we go
  2837. 2:17:53we're getting closer
  2838. 2:17:57okay now let's
  2839. 2:17:58not print this whole dictionary because
  2840. 2:18:00that's annoying
  2841. 2:18:03um open positions we don't need to run
  2842. 2:18:05that anymore
  2843. 2:18:06[Music]
  2844. 2:18:08kill switch okay we're really really
  2845. 2:18:09close we're really really close
  2846. 2:18:11let's make some space in here
  2847. 2:18:16and i'm gonna delete this
  2848. 2:18:19and we are almost done with this
  2849. 2:18:22this is amazing i'm really excited to
  2850. 2:18:24launch this so
  2851. 2:18:26um
  2852. 2:18:30size
  2853. 2:18:33um let's call this kill size
  2854. 2:18:37because this is not just the size this
  2855. 2:18:40is the size we want to kill
  2856. 2:18:42because we're in a winning position
  2857. 2:18:43remember p l
  2858. 2:18:45close
  2859. 2:18:46if our p l is over this amount we're
  2860. 2:18:48doing a kill switch because we want to
  2861. 2:18:50we want to take our win
  2862. 2:18:53and our target i believe is 25
  2863. 2:18:55we can change that later if needed
  2864. 2:18:57um
  2865. 2:18:59let's delete that
  2866. 2:19:01kill size
  2867. 2:19:03and
  2868. 2:19:06so open position while open position is
  2869. 2:19:09true we want to do a loop
  2870. 2:19:12because as long as it's true
  2871. 2:19:15that means we're still
  2872. 2:19:17in the position and we haven't exited
  2873. 2:19:19yet
  2874. 2:19:20print
  2875. 2:19:21starting
  2876. 2:19:23kill switch loop
  2877. 2:19:26till limit fill
  2878. 2:19:29perfect and let's do it
  2879. 2:19:35let's do a temp df just in case i think
  2880. 2:19:37we might need this
  2881. 2:19:52no i don't think we need it but you know
  2882. 2:19:55we'll just let's do it anyways let's do
  2883. 2:19:57femix dot cancel all orders
  2884. 2:20:03because remember we got the kill switch
  2885. 2:20:04going and if there's like if the
  2886. 2:20:06market's moving really fast
  2887. 2:20:08we want to get out we want to get out
  2888. 2:20:10because we already took our we hit our
  2889. 2:20:12profits so
  2890. 2:20:15so we want to
  2891. 2:20:16keep keep it moving so let's go ahead
  2892. 2:20:20and
  2893. 2:20:22say again open position
  2894. 2:20:25equals
  2895. 2:20:27open positions just in case
  2896. 2:20:33if you notice i rewrite a lot of code
  2897. 2:20:36but
  2898. 2:20:39that's okay
  2899. 2:20:41whatever
  2900. 2:20:42works
  2901. 2:20:44so this sets it along
  2902. 2:20:46and i just want to get the kill size one
  2903. 2:20:48more time i'm just going to copy this
  2904. 2:20:50over
  2905. 2:20:52kill slides
  2906. 2:20:55the reason i'm doing this is because it
  2907. 2:20:56can change
  2908. 2:21:00while it's in the while loop
  2909. 2:21:02because it's going to have a sleeve i'm
  2910. 2:21:04going to put a sleep in it so kill size
  2911. 2:21:08and then i want to make this an integer
  2912. 2:21:10um
  2913. 2:21:10kill size
  2914. 2:21:13and
  2915. 2:21:15kill size
  2916. 2:21:19and
  2917. 2:21:20let's go ahead and say print
  2918. 2:21:23now let's
  2919. 2:21:24not do a print we have enough let's say
  2920. 2:21:27date time is now
  2921. 2:21:31and the string of that
  2922. 2:21:34i don't need that either actually
  2923. 2:21:36i was going to do some logging but i
  2924. 2:21:38think we probably just don't need that
  2925. 2:21:39right now
  2926. 2:21:40let's get the ask in here
  2927. 2:21:45ask equals
  2928. 2:21:47what was it bit ask no it's ask bid
  2929. 2:21:51and the ask would be zero and the bid
  2930. 2:21:55equals ask bid
  2931. 2:21:57one
  2932. 2:22:01uno
  2933. 2:22:03okay
  2934. 2:22:05now we have to make the actual buying
  2935. 2:22:06logic so we're in a while loop right now
  2936. 2:22:10if long
  2937. 2:22:12equals false
  2938. 2:22:16let's cancel all orders
  2939. 2:22:19just in case
  2940. 2:22:22you know actually
  2941. 2:22:25probably don't need to do that again
  2942. 2:22:26because i cancel them all right here
  2943. 2:22:28right so we're while looping through
  2944. 2:22:29starting kill switch cancel all orders
  2945. 2:22:32yeah we don't need to cancel all orders
  2946. 2:22:33again
  2947. 2:22:36femix dot create
  2948. 2:22:38limit buy order because we're trying to
  2949. 2:22:40buy it back
  2950. 2:22:46i mean it could be
  2951. 2:22:49yeah we're trying to buy it back if
  2952. 2:22:51long
  2953. 2:22:52if long equals false yeah so if long
  2954. 2:22:55equals false that means we're short so
  2955. 2:22:57we have to buy it back
  2956. 2:22:59this is right this is right
  2957. 2:23:02um
  2958. 2:23:03we would put the kill size in here
  2959. 2:23:08kill size
  2960. 2:23:10we put the bid
  2961. 2:23:12because we want to put it at the bid and
  2962. 2:23:14then the params remember the params
  2963. 2:23:16make it so
  2964. 2:23:20why does this give me air
  2965. 2:23:31hmm
  2966. 2:24:00i don't see why it would give me an
  2967. 2:24:01error here
  2968. 2:24:04so
  2969. 2:24:07let's just run it not run it but let's
  2970. 2:24:09keep going
  2971. 2:24:13print
  2972. 2:24:16f
  2973. 2:24:18just made a
  2974. 2:24:23oh this is why you just give me here
  2975. 2:24:25sorry
  2976. 2:24:26i don't know why i put that there
  2977. 2:24:29just made a w what do we what are we
  2978. 2:24:32doing here buy
  2979. 2:24:34to close
  2980. 2:24:36order
  2981. 2:24:37of
  2982. 2:24:40kill size
  2983. 2:24:44right that sounds about right
  2984. 2:24:50let's put the symbol on here
  2985. 2:24:52just so we can see
  2986. 2:24:54at
  2987. 2:25:01so if we're long
  2988. 2:25:03we have to buy back
  2989. 2:25:10so we'd be bidding so we wanted the bid
  2990. 2:25:12that's right that's right
  2991. 2:25:16okay cool l f
  2992. 2:25:18l if what though
  2993. 2:25:20l if long is true
  2994. 2:25:22we have to sell
  2995. 2:25:25right we have to sell to get back
  2996. 2:25:29so we do femix dot
  2997. 2:25:33create
  2998. 2:25:34limit sell order
  2999. 2:25:37with the symbol
  3000. 2:25:42uh kill size
  3001. 2:25:46the ask because that's right right
  3002. 2:25:49because if we're in a long is true that
  3003. 2:25:51means we're longing it longing it long
  3004. 2:25:52and long elongated and we want to sell
  3005. 2:25:54it to ask because that's the limit yep
  3006. 2:25:56that makes sense to me
  3007. 2:25:58um
  3008. 2:26:01gotta make sure to pass in the params so
  3009. 2:26:03we only do post orders and then we can
  3010. 2:26:06go ahead and just copy this
  3011. 2:26:09just got to make sure to make the
  3012. 2:26:11changes
  3013. 2:26:12a cell
  3014. 2:26:14to close a kill size symbol and ask
  3015. 2:26:21okay
  3016. 2:26:23now i want to put a little sleep in here
  3017. 2:26:28print
  3018. 2:26:31sleeping for
  3019. 2:26:3330 seconds
  3020. 2:26:34to see if it fills
  3021. 2:26:38because i don't want to just keep
  3022. 2:26:39pressing orders over and over you know
  3023. 2:26:42exchanges don't like that i don't like
  3024. 2:26:45that
  3025. 2:26:46nobody likes that okay okay so let's
  3026. 2:26:49jump into this next one here
  3027. 2:26:52print okay perfect so now we have our
  3028. 2:26:54kill switch i believe
  3029. 2:26:56um i'm just gonna do this else print
  3030. 2:27:00um
  3031. 2:27:01something
  3032. 2:27:05something i didn't
  3033. 2:27:09expect
  3034. 2:27:11and kill switch
  3035. 2:27:14function
  3036. 2:27:16perfect
  3037. 2:27:19okay what else
  3038. 2:27:23now i want to check if the open position
  3039. 2:27:24is true
  3040. 2:27:26because
  3041. 2:27:28we're doing a while loop right so open
  3042. 2:27:30position
  3043. 2:27:32let's check if it's true one more time
  3044. 2:27:33after we do all that information because
  3045. 2:27:35remember we're sleeping for 30 seconds
  3046. 2:27:37after we make the buys
  3047. 2:27:38so it might fill and if it fills
  3048. 2:27:42then we don't want to keep running it
  3049. 2:27:46okay i think we're good with this now
  3050. 2:27:54um if i run this kill switch
  3051. 2:27:58right now
  3052. 2:28:04i'm going to exit or close everything
  3053. 2:28:06out i want to test this kill switch
  3054. 2:28:08see if it works and how am i going to
  3055. 2:28:10test it just like this super easy
  3056. 2:28:13i'm just gonna run it it should like
  3057. 2:28:15this is a pretty good kill switch and i
  3058. 2:28:17really like this like
  3059. 2:28:18um
  3060. 2:28:19the way this is set up because it gets
  3061. 2:28:21the exact
  3062. 2:28:23size that is open it's not like you have
  3063. 2:28:26to depend on your old variables because
  3064. 2:28:27sometimes what happens is like
  3065. 2:28:30you'll get part partially filled like if
  3066. 2:28:32you're doing 100 contracts and you
  3067. 2:28:34failed 25 contracts and your kill switch
  3068. 2:28:36is based off of your size then you're
  3069. 2:28:38gonna
  3070. 2:28:39you have 25 contracts open and then you
  3071. 2:28:41sell 100 now you're short or you're the
  3072. 2:28:43opposite right so
  3073. 2:28:45let's go ahead and run this
  3074. 2:28:52starting 15-minute sma
  3075. 2:28:55starting the kill switch
  3076. 2:29:00you hear that sound right just made a
  3077. 2:29:01cell to close
  3078. 2:29:03order of one ubtc
  3079. 2:29:0534
  3080. 2:29:07to 80.
  3081. 2:29:09so i should be seeing right on the bid
  3082. 2:29:12yeah look at that so i'm sitting right
  3083. 2:29:14on the oh my god i've lost 20 percent on
  3084. 2:29:16this position
  3085. 2:29:18but anyways it's only one
  3086. 2:29:21contract it's a dollar 45.
  3087. 2:29:24but you can see that it sits right on
  3088. 2:29:26the bid
  3089. 2:29:27and then it sleeps for 30 seconds
  3090. 2:29:30and then it cancels it
  3091. 2:29:32does it again sleeps for 30 seconds so
  3092. 2:29:34this is good this kill switch is working
  3093. 2:29:37that means i think i'm done with the bot
  3094. 2:29:39i think i am done with the bot
  3095. 2:29:43look at that we did it
  3096. 2:29:45we did it
  3097. 2:29:47i can drink some water now
  3098. 2:29:50next time i will bring some water but i
  3099. 2:29:53think oh we're not quite done yet we're
  3100. 2:29:54not quite done yet we're not going
  3101. 2:29:56we just have to do one more thing
  3102. 2:30:00let's delete all of these things that
  3103. 2:30:02run
  3104. 2:30:11my question is how did that just happen
  3105. 2:30:18how did it just cancel and run again i
  3106. 2:30:20thought i'd just close
  3107. 2:30:22i thought i just killed the bot but
  3108. 2:30:26it's got a mind of its own no or what
  3109. 2:30:32piano clothes just gonna check the piano
  3110. 2:30:34close
  3111. 2:30:35every time through
  3112. 2:30:40holy smokes this is crazy to me
  3113. 2:30:43oh i think i didn't kill it
  3114. 2:30:46i just exited out and
  3115. 2:30:48i was tripping out for a second there
  3116. 2:30:49like what the heck how is it still
  3117. 2:30:51running all right so it checks the piano
  3118. 2:30:53clothes every time through checking to
  3119. 2:30:55see if time to exit does all this stuff
  3120. 2:30:58and says it's the percentage over zero
  3121. 2:31:01if it is then okay print we're in a
  3122. 2:31:03winning position perfect by the way that
  3123. 2:31:05just sold
  3124. 2:31:06um
  3125. 2:31:08and then if the percentage over target
  3126. 2:31:09which my target is 25
  3127. 2:31:12then
  3128. 2:31:13we would say smiley face we're going to
  3129. 2:31:15do piano clothes and we're going to hit
  3130. 2:31:16the kill switch the kill switch is going
  3131. 2:31:18to take us up here
  3132. 2:31:19and gracefully take us out of the
  3133. 2:31:22position at limit so that's pretty cool
  3134. 2:31:25i'm going to delete this because i don't
  3135. 2:31:26want the kill switch to run every time
  3136. 2:31:30so i think the last thing we have to do
  3137. 2:31:32here
  3138. 2:31:34is
  3139. 2:31:40the last thing we have to do is set this
  3140. 2:31:42so it runs
  3141. 2:31:43all the time
  3142. 2:31:46i'm just going to write uh
  3143. 2:31:49built this spot
  3144. 2:31:51that does the
  3145. 2:31:53below
  3146. 2:31:55and it's that
  3147. 2:31:56to build
  3148. 2:31:58in
  3149. 2:31:59or tomorrow or something
  3150. 2:32:01so if you want to see that let me know
  3151. 2:32:02any type of bot you want to see done i
  3152. 2:32:04obviously have a huge huge list of
  3153. 2:32:06strategies i'm building
  3154. 2:32:08and i'm going to create create them here
  3155. 2:32:09on on youtube
  3156. 2:32:11because i the way i feel is like this is
  3157. 2:32:13just everybody tries to be so like
  3158. 2:32:17secretive about this world
  3159. 2:32:19this
  3160. 2:32:20quant world this i'll go trading world
  3161. 2:32:22but it's just like
  3162. 2:32:25anybody can do it i swear to god
  3163. 2:32:29so the last thing i'm going to do is i'm
  3164. 2:32:30going to run this every 30 seconds
  3165. 2:32:32so how do we do that
  3166. 2:32:34so i'm going to delete that
  3167. 2:32:37if i hit play nothing should happen
  3168. 2:32:41perfect
  3169. 2:32:42oh wait wait wait why are you happening
  3170. 2:32:46starting sma
  3171. 2:32:52who invited you to work
  3172. 2:32:56this is why we triple check things
  3173. 2:32:59got it right there
  3174. 2:33:01now this should run nothing
  3175. 2:33:05what the heck
  3176. 2:33:08whatever
  3177. 2:33:10run ask bid it's probably from this
  3178. 2:33:14dfd do i need this anywhere i don't
  3179. 2:33:16think i need it
  3180. 2:33:20i don't think i need this either
  3181. 2:33:26okay
  3182. 2:33:27now it should run nothing
  3183. 2:33:32perfect okay now i'm ready to set this
  3184. 2:33:34up this is my last couple lines of code
  3185. 2:33:36and we are off in under 300 lines of
  3186. 2:33:39code which is awesome awesome awesome
  3187. 2:33:42schedule dot every
  3188. 2:33:44uh let's do this uh for example right
  3189. 2:33:47now 10 seconds
  3190. 2:33:50and do
  3191. 2:33:52uh what did i call it bot
  3192. 2:33:55i think i called it bot
  3193. 2:33:58yeah bob
  3194. 2:34:02and then let's set a while loop while
  3195. 2:34:04true
  3196. 2:34:06should be always
  3197. 2:34:07try
  3198. 2:34:08because there can be
  3199. 2:34:11shaky internet where i am
  3200. 2:34:14scheduled
  3201. 2:34:17run
  3202. 2:34:18pending
  3203. 2:34:21and then accept so the reason i do this
  3204. 2:34:23is because you know whatever happens
  3205. 2:34:26your internet goes out whatever
  3206. 2:34:28then it will keep running you don't have
  3207. 2:34:30to like reset it
  3208. 2:34:33maybe
  3209. 2:34:34an internet
  3210. 2:34:36prob
  3211. 2:34:38or something
  3212. 2:34:40and then let's run it again in 30
  3213. 2:34:42seconds okay cool we got it perfect
  3214. 2:34:45perfect perfect this bot should work now
  3215. 2:34:47let's run it let's see what happens i'm
  3216. 2:34:49just going to run it i'm just going to
  3217. 2:34:51run it and
  3218. 2:34:52see if we get any errors let's see if we
  3219. 2:34:54get any buys any cells
  3220. 2:34:58wait 10 seconds remember it's scheduled
  3221. 2:35:00every 10 seconds it's about 10 seconds
  3222. 2:35:02starting up now it's starting up we're
  3223. 2:35:05starting indicators checking to see this
  3224. 2:35:07is our sale price there it is buys so it
  3225. 2:35:10made the two buys right there
  3226. 2:35:14we're gucci
  3227. 2:35:16we are good to go
  3228. 2:35:18making the cell checking to see
  3229. 2:35:20studying indies
  3230. 2:35:22canceling and putting them again okay so
  3231. 2:35:24we're great we're doing great the bot
  3232. 2:35:26works um i'm super happy about this i
  3233. 2:35:29need to do one thing that i forgot um
  3234. 2:35:31time dot sleep
  3235. 2:35:33create
  3236. 2:35:35create we forgot to put this
  3237. 2:35:37uncheck those sleeps because we're just
  3238. 2:35:39gonna send them every let's do it every
  3239. 2:35:4160 seconds
  3240. 2:35:43no i actually don't need that
  3241. 2:35:47yeah yeah yeah let's do 30 seconds
  3242. 2:35:50because i'm going to run this bot every
  3243. 2:35:5130 seconds anyways
  3244. 2:35:53so
  3245. 2:35:55no i want it more i want more one more
  3246. 2:35:57one more uh
  3247. 2:35:58let's do 120 seconds so it'll sleep for
  3248. 2:36:01two minutes after it makes the bus
  3249. 2:36:03or after it makes the opening orders
  3250. 2:36:05it'll sleep for two minutes but also
  3251. 2:36:08we're only going to run this every
  3252. 2:36:1228 seconds
  3253. 2:36:1330 seconds but i think it takes about
  3254. 2:36:15two seconds to run through the code so
  3255. 2:36:17theoretically what's going to happen is
  3256. 2:36:19it makes the eyes it's going to sleep
  3257. 2:36:20for
  3258. 2:36:21two minutes
  3259. 2:36:29just open
  3260. 2:36:30just made
  3261. 2:36:32opening order
  3262. 2:36:34so
  3263. 2:36:35going to sleep
  3264. 2:36:38for two minutes
  3265. 2:36:40perfect
  3266. 2:36:42sorry i'm really excited now i love
  3267. 2:36:44finishing a bot because now it's just
  3268. 2:36:47like i sit back and i
  3269. 2:36:49see if it works
  3270. 2:36:50you know what i'm saying so if you
  3271. 2:36:52really enjoyed this like all i ask is
  3272. 2:36:54hit a like
  3273. 2:36:55like on the video i mean that's all i
  3274. 2:36:57need if i get a couple likes and i'll
  3275. 2:36:59make a new video tomorrow and um
  3276. 2:37:01i i literally sit here all day and make
  3277. 2:37:03algos like this
  3278. 2:37:05i you know
  3279. 2:37:06obviously i do some some sneaky things
  3280. 2:37:10as well with machine learning and a lot
  3281. 2:37:12of deeper strategies than this but you
  3282. 2:37:15can see my process now and as i
  3283. 2:37:17mentioned i'm just a regular regular old
  3284. 2:37:19dude that you saw what happens when i
  3285. 2:37:21get stuck i just google it
  3286. 2:37:24just ask google like that's all
  3287. 2:37:27let's run this i'm just going to let it
  3288. 2:37:28run now because it's going to sleep for
  3289. 2:37:3030 seconds or it's going to run in 30
  3290. 2:37:33seconds
  3291. 2:37:34so i'm pretty good to go if you want to
  3292. 2:37:36learn more i put together a boot camp
  3293. 2:37:38that's a lot more like straightforward
  3294. 2:37:40organized and step-by-step so you can go
  3295. 2:37:43from you know beginner to expert i'll go
  3296. 2:37:45trader um that there's a link for that
  3297. 2:37:48somewhere around here but really the one
  3298. 2:37:50thing i do ask is just if you've made it
  3299. 2:37:52this far just hit the like button um
  3300. 2:37:55just to signal that you enjoyed this if
  3301. 2:37:57you have any questions or comments or
  3302. 2:37:58anything
  3303. 2:38:00please do let me know
  3304. 2:38:03in the comment section below i'm super
  3305. 2:38:06excited i'll maybe i'll make a follow up
  3306. 2:38:07if you're interested
  3307. 2:38:08in how this went um i've got tons of
  3308. 2:38:11videos on i'll go training on my my
  3309. 2:38:14youtube channel so you know if you're
  3310. 2:38:16not ready to just take a structured boot
  3311. 2:38:18camp where i teach you step by step in
  3312. 2:38:21short videos as opposed to this nice
  3313. 2:38:23long algo video
  3314. 2:38:25and you want access to all my algos
  3315. 2:38:27i have that boot camp of course but if
  3316. 2:38:29you're not ready to join that no worries
  3317. 2:38:31i have a ton of free videos here on
  3318. 2:38:33youtube and i'll put another video up
  3319. 2:38:34here
  3320. 2:38:35on the screen like right now so you can
  3321. 2:38:38go check it out and we can just keep
  3322. 2:38:39jamming and keep uh keep working
  3323. 2:38:41together on building out you know this
  3324. 2:38:44empire so i'll put that screen on a
  3325. 2:38:46video on the screen right now if go
  3326. 2:38:48ahead and check out the boot camp
  3327. 2:38:50there's a link below but otherwise
  3328. 2:38:53i hope you have a wonderful day i hope
  3329. 2:38:54you really enjoyed this video i had a
  3330. 2:38:56lot of fun today building this bot out
  3331. 2:38:58with you
  3332. 2:38:59and that video on the screen right now
  3333. 2:39:01is where i will see you in just two
  3334. 2:39:04seconds
  3335. 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.