Trader Workstation - Automatic Start (Paper Trading)

TWS automatically logs out after about 11:45 PM. They recently added an automatic restart feature to the beta release but I have yet to get it working.

Since I am just paper trading to test algorithms I found an AutoHotKey script that will start/reopen TWS and login when the process disappears. I decided to write my own using Powershell so it works on all Windows systems without needing to install something.

1
2
3
4
5
$proc = "C:\Jts\tws.exe"
if((Get-Process -Name "tws" -ErrorAction SilentlyContinue) -eq $null) {
Start-Process $proc "username= password="
}

Use task scheduler to start this script when you want it to open. I then start my custom algorithm process about 10 minutes later.

1
2
Program/script: powershell.exe
Add arguments: -ExecutionPolicy Bypass <.ps1 script path>

Make sure the trading mode is set to paper inside C:\Jts\jts.ini.

1
tradingMode=p

This should work under Linux if you use cron to start TWS.

Trading Update - 3

I believe I finally have something usable that trades 5m bull flag setups with high accuracy. I have been letting it paper trade for weeks now and just recently got it to what I’d consider “tradable”. It took months of learning how to code a strategy that would have the proper entries, exits, and stops. Not to mention the numerous bugs that caused it to exit trades too soon or not trade certain flags at all.

I am no longer making modifications to the algo, so from this point forward I plan to log a minimum of 20 paper trades to find out its accuracy and how profitable it is with small positions. If I am satisfied with the results I will then trade my live Interactive Brokers account in the coming weeks. Each trade seems to work in one of two ways: it makes an unbelievable gain that I never thought would work, or it gets stopped out quickly for a small loss.

I will be logging all of the trades it makes below, good or bad. I also plan to record the trades and upload them to YouTube like I have been.

P/L: $55.52
Wins: 4 / 57%
Wins if I managed the trade: 8 / 72%
Losses: 3 / 42%

Break even trades are only counted in “wins if I managed the trade”.

10/12/2018
These two trades below were made Friday at almost the exact same time and both worked perfectly with it almost catching the exact top both times. Before this day it made a couple mistakes (stopped out due to a bug / trading a setup with terrible volume) but also had some nice gains. The winners were always bigger than the losers despite these issues.

Unfortunately, I was not recording when it made these trades so I can’t show them in real time.

$ATXI 5m/1m candles
$FNKO 5m/1m candles

Week 1 - 10/15/2018
Not a whole lot going on today besides $YGYI having some nice 1m flag setups. It traded $NBEV twice. One loss in the morning and one small gain around noon. Not a great start to the week but the risk/reward is always good. Let’s see what happens tomorrow!

$NBEV 5m/1m candles



10/16/2018
$NDLS was very choppy and slow. It got out break even when it spiked into $12.99 and came back down to the entry. No gain or loss on this one. I’m not planning to upload a video of it because the entire flag just went sideways forever until finally breaking over $13.00 after a strong dip.

I manually traded two different flags on $FFHL which was fun. There’s really not a lot going on this week so far. That just means it’ll take longer to get the 20 trades. It’s good because these are worst case scenario trades. Earnings season is coming up so there should be some good opportunities.

New TWS theme in the beta release! I dig it but they need to fix some of the chart bugs and add premarket/after hours shading.

$NDLS 5m/1m candles

Update: I actually see a perfect bull flag on $ALT but it was not traded because the volume on the next candle was higher. I added a separate algo that changes that check. It will now trade them both separately so it will not change the results of this “forward test”. I’ll start logging those tomorrow in a separate spreadsheet.

10/17/2018
Yet another boring day. It traded $QNST but was not getting filled so I moved the order up slightly. The stock ended up moving quite a lot but could not get over $14.95 so it sold for break even. If this was real money I would have sold into the first push to that level or dumped it when it made the lower high. This trade and yesterday’s trade could have been winners if I decided to get out before the stop was hit. Not bad I guess.

No video for this one again. It’s just too slow.

$QNST 5m/1m candles

A little later it took a decent flag setup on $HEAR. This stock always has big moves which is nice. Got a little push into $22 then it dumped hard. Algo exited for a $2 gain, but that was with only 25 shares. Not bad. Could have easily been a win if I were managing it.

$HEAR 5m/1m candles

Another slow stock. I’ve seen this exact setup work last week. Unfortunately, this one did not. I think if it managed to get over $3 it would have ran, but I guess there’s just not enough volume. Decent exit since it gave it lots of time and got out on a spike.

$OMED 5m/1m candles

I actually saw a lot of halts late day so small caps might be heating up again. Eventually there will be one where it makes a crazy gain. It has before and it will again. Just grinding for now.

10/18/2018
It traded $PYX early in the morning. I’m starting to wonder if this is even going to work now because all the traders are now watching Chinese stocks and ignoring everything else. It’s also not as volatile as it was last week. The setup is perfect but that doesn’t matter. I’ll probably increase the volume requirements in the scan after I get 20 wins/losses. Flags seems to be crappy this entire week so I may need even more than 20 to determine an accurate win/loss ratio. Last week was amazing.

$PYX 5m/1m candles

A few minutes later $ACRS. Decent setup but got stopped out for break even. A little squeeze up to $11.84 which I could have sold into so technically a win if I managed it.

$ACRS 5m/1m candles

10/19/2018
This whole week has been rather boring.

It traded $VTVT and got a nice move over $4.00 pretty quickly. However, it was yet another break even trade. I think because small caps are kind of weak (besides the China sector) it’s only able to get 15-20c out of it and dumps quicker so there’s never an exit indicator. Basically what I’d have to do is change the profit target to like +30c / 3% instead of what I have now. That would make all of these break even trades winners. I’ll have to either change it when the markets slow or manage it myself.

It traded it again on the next flag but barely got a move out of it this time. I probably would have sold it right away for a $1 gain or something.

$VTVT 5m/1m candles

Winning percentage is actually decent (72%) if the targets are lower which means there’s usually a move right after it enters. It’s just getting stopped out when it comes back down because the moves they make are generally too weak. I wrote extra code that can be manually toggled for when the market is slow and it’ll have lower targets + move the stop above break even so it will more likely have some gain. I will not have that enabled until I get 20 trades.

Let’s see what happens next week.



Disclaimer

I am not a registered financial adviser/broker/anything. Use this information for entertainment/informational purposes only. Any tickers mentioned are not recommendations to buy/sell/or sell short. They are used as examples only.

Please remember that past performance may not be indicative of future results.

Clean Windows Caches

I wrote a simple PowerShell script that will delete all files/folders inside the temporary file paths. It will also clear the shader cache for AMD GPUs. I set this up to run on every reboot.

1
2
$folders = @("C:\Windows\Temp\*", "C:\Windows\Prefetch\*", "C:\Documents and Settings\*\Local Settings\temp\*", "C:\Users\*\AppData\Local\Temp\*", "C:\Users\*\Appdata\Local\Microsoft\Windows\Temporary Internet Files\*", "C:\Users\*\AppData\Local\AMD\DxCache\*", "C:\Users\*\AppData\Local\AMD\GLCache\*")
Remove-Item $folders -force -recurse -ErrorAction SilentlyContinue

YouTube Channel

I’ve decided to create a YouTube channel and have started uploading my trades to document my progress/algos progress. There are already tons of people posting daily recaps, but how many are posting live algorithmic trades? Certainly not what I’m attempting to achieve: scanning stocks in real-time then trading patterns when they show up. I looked through YouTube and could not find anything like this. It’s always forex/futures/specific stocks ($AAPL / $TWTR). I prefer to do what I’m doing simply because the patterns I look for should appear a few times each day on different stocks; which means there’s more opportunity to test and/or profit.

As far as I know there is not any backtesting software that allows you to backtest intraday candles and ticks based on the hot stocks appearing in a scan for the day. Obviously you can do it for individual stocks you select, but not for real-time scanning based on a set criteria. The software I wrote is totally custom for IB/TWS.

For now it’s all simulated trades until I’m confident in my strategy (manual and algo). Let’s see where this goes.

Check out my about page for other social media stuff.



Trading Update - 2
Trading Update - 1



Disclaimer

I am not a registered financial adviser/broker/anything. Use this information for entertainment/informational purposes only. Any tickers mentioned are not recommendations to buy/sell/or sell short. They are used as examples only.

Trading Update - 2

I found an interesting bug that caused my algorithms to only trade from one IB scan that I had listed. I discovered it because it did not trade a perfect flag setup on $SYN a few days ago despite it being in most of the scans.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Starting backtest on $SYN...
Retrieving intraday candles/ticks...
Retrieving daily candles...
Backtesting 09/28/2018...
[09/28/2018 10:10:00] Entry 50 @ $4.15, target $4.57, stop $3.88 [ Bull Flag ]
Trailing stop: 3.88, 4.01, 4.15
[09/28/2018 10:15:00] Exit @ $4.59 [ $0.44 ]
Drawdown: $0.33 / -7.85%
Max profit: $0.52 / 12.66%
P/L: $21.89
[09/28/2018 11:00:00] Entry 25 @ $6.65, target $7.32, stop $6.06 [ Bull Flag ]
Trailing stop: 6.06, 6.65, 7.01
[09/28/2018 11:10:00] Exit @ $7.33 [ $0.68 ]
Drawdown: $0.32 / -4.94%
Max profit: $1.26 / 19.44%
P/L: $17.00
Gross P/L: $38.89 / $0.00
Commissions: $-4.00
Net P/L: $34.89
Win/Loss: 2 / 0 (100.00% / ∞)
Trades: 2 (2 long, 0 short)
Avg $ win/loss: $19.44 / $0.00
Best/Worst: $21.89 [ Bull Flag ] / $0.00 [ ]

After fixing it on Friday I figured on Monday it would do one of the following:

  1. Still take the same amount of trades because the ideal perfect setup is not occurring that frequently.
  2. Take more trades but probably all terrible.
  3. More trades but all great because the pattern is well known.

#2 is exactly what happened. The pattern is still good (I’ve seen it work many times) but because there’s a lack of volume and/or trades occurring, the stock does not move up and has a higher probability of working as a short.

As you can tell from the entries/exits from below, the trades didn’t exactly work. Both setups do look pretty good so it is trading the right pattern, and the second one actually worked. It didn’t hit the target so it stopped out near break even. The problem is if you look at the 1 minute chart it’s extremely illiquid with gaps and barely any volume on each 1m candle.

$NTGN 5 minute candles

$NTGN 1 minute candles (illiquid)

I believe this stock came from the TOP_PERC_GAIN / TOP_OPEN_PERC_GAIN scans. These are good basic scans but they don’t tell you anything useful except that the stock is up on the day. IB allows you to see the volume and trades for each candle but I have yet to find a good indicator to determine how “hot” or volatile a stock is.

I could look at the volume of each candle or trades per candle or even relative volume. It’s not that meaningful though since what happens when the pattern occurs perfectly before the volume conditions are met then it takes the trade at a later time and it ends up with a loss. I’ve had this happen with relative volume > 1 checks. Volume pours in immediately after the pattern sets up and you get in too late and buy high or short low.

There are other scans like TOP_TRADE_RATE / TOP_TRADE_COUNT / MOST_ACTIVE that return the stocks with the most volume/trades/trade rate so I will be testing those to see what it trades. I have a decent algo for trading flags now, so it just needs to be applied to the correct stocks.

Fall has just started, which is a great time to be trading with real money, so I’d really like to get this working. I could set the API to read-only and see what it wants to trade that way, but it’s just not the same and you don’t get a complete picture of what it’s doing with fills/moving stops/random bugs.


Scans

I went through a few of the different scans and landed on HOT_BY_VOLUME and TOP_TRADE_COUNT. The latter is what it originally traded with when it had the bug I described earlier. Both of these scans seem to return similar stocks so it should cover all the bases (lots of volume / lots of trades). After changing this, it traded $CRBP at 11:57 AM while I wasn’t even here.

$CRBP 5m/1m candles

It should have gotten in on the previous candle but it was not up enough on the day to warrant a flag. Still making minor adjustments.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Starting backtest on $CRBP...
Retrieving intraday candles/ticks...
Retrieving daily candles...
Backtesting 10/02/2018...
[10/02/2018 11:50:00] Entry 50 @ $7.47, target $8.22, stop $7.28 [ Bull Flag ]
Trailing stop: 7.28, 7.47, 8.01
[10/02/2018 12:00:00] Exit @ $8.23 [ $0.76 ]
Drawdown: $0.17 / -2.25%
Max profit: $0.68 / 8.99%
P/L: $38.00
Gross P/L: $38.00 / $0.00
Commissions: $-2.00
Net P/L: $36.00
Win/Loss: 1 / 0 (100.00% / ∞)
Trades: 1 (1 long, 0 short)
Avg $ win/loss: $38.00 / $0.00
Best/Worst: $38.00 [ Bull Flag ] / $0.00 [ ]

$VTVT

I recorded a lengthy video of me trading $VTVT manually on a 1m setup then a perfect 5m bull flag formed and my algo took it a few seconds after me. I’ll try to post more of these if I get something interesting.






Disclaimer

I am not a registered financial adviser/broker/anything. Use this information for entertainment/informational purposes only. Any tickers mentioned are not recommendations to buy/sell/or sell short. They are used as examples only.

Please remember that past performance may not be indicative of future results.

EZ Arch Encrypted Installation

  1. Download the Arch ISO.

  2. Find your disk.
    fdisk -l

  3. Partition (zero out the drive first using dd / secure erase if you want to).

    • fdisk /dev/nvme1n1
    • n
    • 1
    • enter
    • +550M
    • n
    • 2
    • enter
    • enter
    • t
    • 1
    • 1
    • w
  4. Encrypt. aes-xts should be the fastest if your CPU supports AES instructions. Most modern CPUs do. Also, Grub does not support LUKS2 yet so do not bother trying it.

    • cryptsetup benchmark
    • cryptsetup -v --cipher aes-xts-plain64 --key-size 512 --hash sha512 --iter-time 5000 --use-urandom luksFormat /dev/nvme1n1p2
    • cryptsetup luksOpen /dev/nvme1n1p2 rootfs
  5. Format.

    • mkfs.vfat -F32 /dev/nvme1n1p1
    • mkfs.ext4 /dev/mapper/rootfs
  6. Mount.

    • mount /dev/mapper/rootfs /mnt
    • mkdir /mnt/boot
    • mount /dev/nvme1n1p1 /mnt/boot
  7. Install.

    • pacstrap /mnt base base-devel
    • genfstab -U /mnt > /mnt/etc/fstab
    • arch-chroot /mnt bash
  8. Grub.

    • pacman -S grub efibootmgr
    • Edit /etc/mkinitcpio.conf and add encrypt to the HOOKS field
    • mkinitcpio -p linux
    • Edit /etc/default/grub and uncomment GRUB_ENABLE_CRYPTODISK
    • Change GRUB_CMDLINE_LINUX to GRUB_CMDLINE_LINUX="cryptdevice=UUID=<uuid>:rootfs"
    • Replace the UUID above with the encrypted partition UUID from blkid
    • grub-install --target=x86_64-efi --bootloader-id=arch --efi-directory=/boot --recheck
    • grub-mkconfig -o /boot/grub/grub.cfg
  9. Swap. If you have tons of RAM this isn’t really necessary. Having a swap file instead of a partition makes things easier in case you need to remove the swap device or increase/decrease its size. It will also be encrypted since it’s located inside the LUKS partition.

    • dd if=/dev/zero of=/swap bs=1M count=2k
    • chmod 0600 /swap
    • mkswap /swap
    • swapon /swap
    • Edit /etc/fstab and add /swap none swap defaults 0 0
  10. Time zone.

    • ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
  11. Locale.

    • Edit /etc/locale.gen and uncomment your locale. Probably en_US.UTF-8.
    • locale-gen
    • Edit /etc/locale.conf and add LANG=en_US.UTF-8
  12. Hostname.

    • Edit /etc/hostname and set it to what the machine should be called.
  13. User.

    • useradd -m -g users -G wheel,storage,network,power,rfkill -s /bin/bash <username>
    • passwd <username>
    • passwd root
    • Edit /etc/sudoers and uncomment %wheel ALL=(ALL) ALL
  14. Reboot.

    • exit
    • reboot
  15. If you did everything correctly, you should see a Grub OS selection that will take you to a prompt to enter your password.

  16. I’ll be installing GNOME, but you can choose anything you like.

    • sudo systemctl start dhcpcd.service
    • sudo pacman -S xorg xorg-server gnome gnome-extra
    • sudo systemctl enable NetworkManager.service
    • sudo systemctl enable gdm.service
    • reboot

That’s pretty much it. Check out my short guide about improving desktop responsiveness.

Pot Stocks In 2018

When the cannabis sector heats up you can reference this list for potential trades. If you know of any more, leave a comment and I’ll add it.

Listed

OTC

  • $ACBFF
  • $HEMP
  • $KSHB
  • $POTN
  • $MJNA
  • $GRNH
  • $CANN
  • $EMHTF
  • $NUGS
  • $BUDZ



Disclaimer

I am not a registered financial adviser/broker/anything. Use this information for entertainment/informational purposes only. Any tickers mentioned are not recommendations to buy/sell/or sell short. They are used as examples only.

Learning to Day Trade - Part 19

Swing Trading

Lately I’ve been looking at swing trading or at least looking for obvious breakouts / flags on the daily chart. I created a screener to narrow the search down.

finviz screener

What this screener does is look for small caps (not low float) that are “half up” on decent volume. These are stocks that are trending higher and not trending down. It’s much more likely that a stock will continue higher if it’s trending that way.

  1. The stock does not need to be breaking out when you’re looking for potential plays. Add it to your watchlist and set alerts near the pivot point.
  2. Price does not matter so long as there is decent range.
  3. There should be a recent catalyst to carry it higher or the chart setup is perfect/obvious and will bring in buyers.
  4. There should be decent volume traded each day otherwise the spreads will be terrible.
  5. Take partials once you have some profit in order to lessen the risk.
  6. Profits take care of themselves, it’s the losses you have to worry about.

This is a perfect example of something to look for. A nice uptrending chart that is consolidating with an obvious breakout of around $28.15. This one was on the screener for serveral days so it is possible to make these trades with ample preperation.

The intraday chart is not as pretty. It had a midday crash then rebounded. You do not need to buy instantly at the open. Wait for it to prove itself.

$BOOT daily chart from finviz.com (breakout)



Disclaimer

I am not a registered financial adviser/broker/anything. Use this information for entertainment/informational purposes only. Any tickers mentioned are not recommendations to buy/sell/or sell short. They are used as examples only.

Convert PAL 25 to NTSC 23.976

This script will convert PAL MKVs to NTSC 23.976 MP4s. You can play around with the container format (MKV instead) or audio codec.

It appears to work by slowing down the video/audio so the duration ends up being a little longer and the audio pitch is lower. Some frames are still dropped and I’m not quite sure why. The duration of the file is longer though. I’ve tested it with 42 episodes of a PAL DVD TV series. They all appear to be correct without any problems showing up.

DVD ISO VOBs -> Handbrake (0 CRF for max quality & copy audio) -> ffmpeg script

1
2
3
4
5
6
7
#!/bin/bash
for f in *.mkv
do
echo "Converting $f"
ffmpeg -loglevel panic -y -i "$f" -vcodec libx264 -preset veryslow -tune film -x264opts crf=16:videoformat=undef:force-cfr -acodec aac -strict -2 -ab 448k -filter:v setpts='25025/24000*(PTS-STARTPTS)' -filter:a asetpts='25025/24000*(PTS-STARTPTS)',aresample=48000:async=1:min_comp=0.01:comp_duration=1:max_soft_comp=100000000:min_hard_comp=0.3 -r 24000/1001 "${f%.mkv}.mp4"
done

Reviewing My $ALLY Trade

This is my first attempt at buying at trend line support with real money. It ended up working perfectly and I got in almost at the exact bottom on Wednesday.

As you can see from the daily chart, I drew the support/resistance lines and had been actively watching this stock for several days. It had two things going for it: running into the 200 day EMA as well as another touch of the uptrending trend line. My plan was to buy around $26.55 with a goal of selling near $27 in a few days.

$ALLY daily candles

It tapped the bottom trend line almost perfectly and started to reverse. I bought 100 shares with a limit of $26.49. Low of day was $26.45. Luckily I had a good entry and it reversed off that bottom.

The next day it gapped up just over $26.90, so I was in the green over 40c and didn’t have to worry about being red. I gave it as much time as I could stand to get over $27, but it started to top at $27.10. I decided to just take the 54c profit and call it a day. This was pretty good even though it managed to get to $27.23. Can never get the exact bottom or top and that’s OK.

$ALLY 5m candles

I’ll be watching it for another setup like this. Possibly a little higher like $26.60 or $26.65 when it sets up again. Just have to be patient and wait for it.



Disclaimer

I am not a registered financial adviser/broker/anything. Use this information for entertainment/informational purposes only. Any tickers mentioned are not recommendations to buy/sell/or sell short. They are used as examples only.