Explanation and full Tutorial 8 Trigger Scenarios Automated Triggers
Now we're going to talk about all about 8 Trigger Scenarios Automated Triggers It consists of :
Scenario 1: Nightly Trending List
Buy MSFT if it crosses above $175 in the first 15 minutes
For Scenario 1, we’ll use our nightly Trending List that we e-mail to our Stock Volatility Box subscribers as a sample condition. Each day, we go through the day’s trading activity to find stocks and ETFs that are likely to trend the next day. This list is e-mailed to all Stock Volatility Box members ahead of the next day's trading activity.
We’d like to buy Microsoft (MSFT), as an example, if it crosses above $179.18 within the first 15 minutes.
No code is required here, but instead, just some simple customizing of the conditions in the Automated Trading Triggers pane in ThinkOrSwim.
And that’s scenario 1, all done. Moving onwards to Scenario 2.
Scenario 2: Iron Condor When in Consolidation
Sell HD Iron Condor when price is between $195 and $200
For Scenario 2, let’s assume that you’re looking at a period of potential consolidation in HD we’d like to sell an Iron Condor whenever price is between $195 and $200.
That happens to also overlap with the Market Pulse indicator line, which gives you reason to believe we'll chop sideways for a bit.
Again, keep in mind, these are all just for demonstrative purposes - NOT real trades, so please don't go placing them.
You may be looking at a period of consolidation in Home Depot, but want to get a slightly better entry on the Iron Condor so you’d like to wait for price to fall.
Here, the code for the automated trading in ThinkOrSwim is quite simple:
plot signal = if close >= 195 and close < 200 then 1 else 0;
This lets us place the order conditions, and you may link it to something like the ask to avoid overpaying or even the mid-price, and set this as a GTC order.
If it gets filled, fantastic.
You can even set an expiration date, if you’d only like this order to be valid through the end of this week.
Scenario 3: Automatic Covered Call for Income at Fib Extensions
Sell a covered call on pre-existing 100 shares in LVGO when price hits the 2.00 extension to collect “rent” on a profitable position
Here, let’s assume that you already own 100 shares of Livongo Health (LVGO). LVGO has made a pretty nice move to its 1.618 retracement.
Now let’s say that you don’t think it can go much higher above the 2.000 retracement at $44.88.
Instead of having to sit there and watch the position (or even set an alert to revisit the thought later), you’d like to automatically sell a covered call against your pre-existing 100 shares.
You'd like to use the automated trading in ThinkOrSwim to automatically sell a $45 strike call, when price hits the 2.00 retracement level at $44.88.
Think of this as collecting rent, on an already profitable position.
Let’s create that. Again, we don’t need any code here. We can build the conditions using the editor.
First, we head to the options chain to choose the $45 strike call, and we go to edit the options of the automated trading pane:
We’d like to join the bid to collect the greatest credit we can (or even the mid, if you prefer), and you can set the order to GTC.
Scenario 4: Buy Put When RSI Shows Bearish Breakout Signals
Buy a pre-selected put when RSI is showing breakout signals
For Scenario 4, we’ll use the built in RSI signals to buy a put whenever we have a bearish breakout signals. Now, the larger the time frame, the more powerful the signal should be.
Let’s assume we’re doing this on a daily SPY chart, so we may want to buy a Put that is at least 90 days out, to give not only ourselves time, but also the trade without needing to re-update the Trigger conditions (with the next month’s strike).
Here, our code is fairly simple, and we attach this to the Triggers pane of the put we’d like to use:
plot signal = RSI().DownSignal[1];
That tiny, one-liner of code is enough to trigger the automated trading in ThinkOrSwim to place an order whenever we have that down signal.
We use the array "[1]" to reference the previous bar, to confirm that the signal has actually finished printing, instead of still being in progress.
Scenario 5: Buy Stock on Pullbackto 34 EMA
Buy stock if we get a pullback to the 34 EMA, with the moving averages all being stacked, triggered with an OCO order
This time, we’ll write some thinkScript to enter into a stock that has stacked moving averages (8 EMA x 21 EMA x 34 EMA). If we have stacked moving averages, let’s say bullish, then we can assume that we have a bullish trend.
And with a trend, we can buy trend pullbacks, to whichever EMA we prefer (in this case, we’re using the 34 EMA).
Here is the code, all written out so that it's easy to copy/paste:
def EMA8 = ExpAverage(close, 8);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def stacked = if EMA8>EMA21 and EMA21>EMA34 then 1 else 0;
plot signal = if stacked and close <= EMA34 then 1 else 0;
Scenario 6: Sell Position When Squeeze Loses Momentum
Close my position when squeeze momentum starts to decline
In our second to last scenario, we’ll assume that you’re already in a position, ideally because of the TTM_Squeeze.
Once the squeeze fires, you’d like to get out as soon as the histogram bars show us that we’re starting to lose momentum.
Here, you're using the automated trading in ThinkOrSwim to let you manage an existing position, instead of enter a new one.
Let’s write the code :
plot signal = if TTM_Squeeze().Histogram[1] < TTM_Squeeze().Histogram[2] then 1 else 0;
Scenario 7: Layering on Multiple Indicators
Buy pre-selected call if we have a squeeze, with greater than avg. volume, and EMAs agreeing with the direction
For the 7th scenario in this semi-automated trading series, we’re going to take a look at combining multiple conditions into one trigger.
The concept that I’m really trying to get across here is less about the actual conditions I’ve chosen, and more about the idea that you can layer on multiple “basic” indicators, and bypass some of the complexity errors in ThinkOrSwim.
The specific condition we’re going to look at here is buying a pre-selected call if:
We have a squeeze
Greater than average volume
EMAs agreeing with the overall trend
Here's the code that we use for the above conditions:
def EMA8 = ExpAverage(close, 8);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def bullish = if EMA8 > EMA21 and EMA21 > EMA34 then 1 else 0;
def squeeze = if TTM_Squeeze().SqueezeAlert == 0 then 1 else 0;
def greaterVol = VolumeAvg().Vol > VolumeAvg().VolAvg and close > close[1];
def conditions = bullish and squeeze and greaterVol;
plot signal = conditions[1];
Scenario 8a: Buy on Implied Volatility Pullbacks (Entry)
Buy on Implied Volatility pullbacks in a strong uptrend for the stock. Simultaneously, place a GTC exit order whenever moving averages are no longer stacked, on a lower time frame.
For our last and final scenario, we have two parts. In part 8a, we’re going to look at coding the entry components, which is going to be around the idea of buying on Implied Volatility pullbacks to the 34 EMA.
Yes, you read that correctly.
We’re going to run exponential moving averages using Implied Volatility as the data input, in lieu of the close price, and buy on IV trend pullbacks in otherwise strong trends on the actual underlying. And, that is going to be built into code for automated trading in ThinkOrSwim.
The goal to convey here is that you can go multiple layers deep in terms of analysis, and can very easily see when these trigger conditions were true, and what happened after.
The thing we’ll do differently here is “Buy custom” and link a close order with our entry order (i.e. Buy Custom with Stop)
Here's our entry code:
def EMA8 = ExpAverage(close, 8);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def stacked = if EMA8 > EMA21 and EMA21 > EMA34 then 1 else 0;
def ImpVol = IMP_VOLATILITY();
def IV8 = ExpAverage(impVol, 8);
def IV21 = ExpAverage(impVol, 21);
def IV34 = ExpAverage(impVol, 34);
def IVstacked = if IV8 > IV21 and IV21 > IV34 then 1 else 0;
def conditions = if stacked and IVstacked and ImpVol<= EMA34 then 1 else 0;
plot signal = conditions[1];
Scenario 8b: Sell When Trend Breaks
And finally, we’d like to add some custom code to the second component of the order – the sell order, as part of that custom order type we had built.
Here, we’ll link the closing order to the EMAs.
This is our exit code:
def EMA8 = ExpAverage(close, 8);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def stacked = if EMA8 > EMA21 and EMA21 > EMA34 then 1 else 0;
def conditions = if stacked[2] and !stacked[1] then 1 else 0;
plot signal = conditions;
This is to say that when the 3 EMAs are no longer stacked, we will close out the trade, either for a gain or a loss.
This is what the final trigger order should look like, with both the buy and sell custom codes:
And voila! We're done.
We walked through 8 different "scenarios" that are fairly close to realistic setups that you may have, and we tried to get as close as we could to automated trading in ThinkOrSwim.
The system is still not perfect, but it should still serve to be convenient and reward the hard work of finding the setup in the first place.
What Else Can I Do?
Now that you have the fundamental knowledge with regards to using automated trading in ThinkOrSwim functionality, you can take this in whichever direction you'd like.
Some examples include:
Test your own setups
If you face “complex” errors, break apart the indicator components to see if you can find another way to calculate the same trigger
Use PaperMoney as a sandbox environment
Use GTC orders to run experimental trade setup ideas you may be looking at to test their expectancy and probabilities (“free semi-automated backtesting”)
Push the capabilities of the platform and test different order types, multiple TRG brackets with custom studies, etc.
📌 Disclaimer: Forex trading carries a high risk of loss. Only invest what you can afford to lose, and ensure you understand the risks before trading.
Post a Comment