How to Integrate TradingView Alerts into Trade Unafraid for Powerful Trading Automation

There are only a few easy steps needed to turn TradingView Alerts into actual trades in Trade Unafraid.

Setting Up Your TradingView Alert

First, in TradingView, set up an alert that sends JSON via a webhook.  

On the chart of your choice (select your ticker symbol and time frame), add any Indicators that you may need for your alert, and then click the Alert button above the chart.  A dialog box opens, allowing you to define your alert.  (Alternatively, you can use Pine Script to generate your alerts.)


This example triggers a long trade when the 5-bar Simple Moving Average crosses above the 9-bar Simple Moving Average.  (This is not a recommendation, just an example.)  There are plenty of examples of alerts in TradingView and all over the web.  Choose the alerts that you are interested in trading.

Since you are entering a trade on the alert, be aware of the Trigger.  Each alert is a new trade, so your choice of Trigger matters.

Expiration and Alert name are up to you and have no impact on Trade Unafraid (other than the fact that after expiration, Trade Unafraid will not receive any alerts, of course).

The JSON Payload

Now, the Message is of critical importance.  This is what Trade Unafraid will receive, and your Trade Plan will be based on the contents.

If you are not familiar with JSON (JavaScript Object Notation), just copy this.  The surrounding braces, the double-quotes, the colons, and the commas are all required, so just copy it and edit the parts you need to change.

{
  "symbol": "{{ticker}}",
  "direction": "L",
  "stop":"{{low}}",
  "tradePlanTemplate":"replace-with-yours",
  "dteMin": 1,
  "dteMax": 7,
  "secret":"replace-with-yours",
  "message": "Moving Average Simple (5, close, 0, SMA, 5) Crossing Up Moving Average Simple (9, close, 0, SMA, 5) on NVDA, 5"
}

Symbol will typically be {{ticker}}, which means you can simply use that value for any chart, and the trade will be for that symbol.  On an NVDA chart, {{ticker}} will be replaced with NVDA.  (You could conceivably do something like place the alert on the QQQ chart but set "symbol" to "AAPL", but that would be an atypical use case.)

Direction can be L or LONG for a long trade, and S or SHORT for a short trade.  It is case-insensitive, so l, long, s, or short would also work.

Stop is an optional parameter, but it will be used as a stop price, if provided.  In this example, we have a long trade, so we are using TradingView's {{low}} macro to take the low of the trigger candle as the stop price.  TradingView has other macros, including open, high, and close, but check their docs for even more possibilities.

Keep in mind that the stop might not work out favorably in some cases.  For example, if your alert triggers a long trade when price is near the low of the candle, your stop may be extremely close or even equal to your entry price.  You might choose to rely solely on Trade Unafraid's Trade Plan, rather than including a stop from TradingView.  It's up to you.

While I'm talking about things to be aware of, I'll add that I have seen back-to-back triggers, such as this pair, where the first one occurred during the 12:35:00 - 12:39:59 bar, and the second one occurred eleven seconds later, during the 12:40:00 - 12:44:59 bar.  In this case, you end up with two independent trades.  Something to be aware of when setting up your alerts.

Arguably the most important parameter is the tradePlanTemplate.  This is the name you use to save your Trade Unafraid Trade Plan, and it must be an exact match.

Next, if you want to trade options, you can specify dteMin and dteMax.  DTE is Days Til Expiration, as you probably know.  You can use dteMin of 0, if you want to trade 0DTE.  Or you can use something larger, if you don't.  If you don't specify dteMin, the default is 0.  dteMax defaults to infinity.  So if you do not provide a range, then all option expirations available for the symbol are available to trade with.  You can do a range like 30 - 45, or 1 - 7.  Just be sure that some options expire in the range you provide.  For example, if you want to trade 0DTE, so you use dteMin of 0 and dteMax of 0, but it's Tuesday, then you won't be able to trade NVDA at all, because there are no options that expire on Tuesday for NVDA.

Secret is essential.  This is a shared secret that lets Trade Unafraid know that the webhook came from your account.  If the secret does not match exactly, no trade will trigger.

Message is arbitrary text.  It is currently not used, but I hope to be able to add it to the Trade Unafraid logs.  The message you see in my example was actually the default alert message generated by TradingView.  I believe you can use TradingView macros such as {{ticker}} in the message, though I have not tried yet.

Setting Up Your Webhook

You need to direct your Notifications to your Trade Unafraid server by providing the Webhook URL of your server.


You are welcome to include any of the other notifications, as well.  The only one that matters for entering trades is the Webhook URL.

Of course, you need to replace "yourTradeUnafraidURL" with the same domain you use to log in to Trade Unafraid.  The /tradingViewWebhook path is required.

You have now set up a TradingView alert.  Now it's time to get Trade Unafraid ready to handle it.

Setting Up Your Trade Unafraid Trade Plan

Because I used the tradePlanTemplate name of tvwh:opt, I must create a Trade Plan template with that exact name, for this to work.  Of course, I can always go edit the TradingView alert to use a different value for tradePlanTemplate.  But they have to match exactly, or nothing will happen.

Unlike other Trade Plans you may have in Trade Unafraid, Direction does not matter and can be blank.  Same with Symbol and your option expiration selections.  These things are now coming from TradingView instead.

Several important things to take note of:
  1. Save the template using the exact name, as I've already mentioned too many times. :-)
  2. No need to specify Direction, because the JSON direction parameter will override it.
  3. No need to provide a Symbol, because the JSON symbol parameter will override it.
  4. As with all other Trade Unafraid Trade Plans, your Quantity Basis is used to determine whether to trade based on a dollar amount or a quantity.
  5. No need to check All options or select Calls or Puts, because symbol combined with dteMin and dteMax will perform this function.
  6. PLEASE practice with SIMULATED Brokerage and SIM Account before you put real money at risk.
  7. Turn Repeating OFF!  Each triggered alert will be a new trade with a new Trade Plan.  You do not want this Trade Plan to repeat.
  8. Unless you intend to hold overnight, check Flatten at Market Close.  You never know if an alert might trigger at 3:59pm.  Important Note: It just occurred to me that you could conceivably have an alert trigger at 3:59:59pm, AFTER the Flatten at Market Close process has run.  There is the possibility that you could end up in a trade just before the market closes.  If it is an option trade, you could be stuck in the trade until the market opens next.  Please consider these things when setting up your alert and your Trade Plan and when deciding how much risk to take.  Please be aware that this is beta software, so expect the unexpected.
  1. You can trade Stock or Options.
  2. Ignore the not expiring today checkbox.  It is overridden by the value of dteMin.
  3. IMPORTANT: You cannot use the Tightest Spread Option Chain Strategy.  If you do, your Trade Plan will not enter a trade.  If you are trading options, for your safety, your only choices are ITM1 or OTM1.  Whichever one you choose, that strike will be used for all the expirations that fall within your dteMin to dteMax range.
  4. You can still use Option Filters to protect yourself from wide spreads or to control the price and/or quantity of the option contracts.
  5. Since the TradingView alert has effectively determined the Setup, use the AD HOC Trade Unafraid Setup, which is an instant trigger.  There are no configurations for the AD HOC setup.
  6. Having set your Quantity Basis as either Dollars or Quantity, your Entry Tactic is then specified with that type of value.  In this example, I am trading $5000 worth of one-strike OTM options.  Keep in mind that, depending on the expirations you allow, the option prices can vary widely.  You can use Price Range and Qty Range Option Filters to exert some control over this.
  7. Instead of the Market Entry, you could consider the Candle Break Entry Tactic to prevent an immediate entry, waiting instead for a confirming move in the direction of your trade.
  8. You could still use Setup Filters to potentially reject certain entries based on other criteria.  The other alternative is to use Pine Script or other indicators in TradingView to filter your alerts.
  9. The rest of your Trade Plan, the Exit Tactics and Position Tactics, work as with any other Trade Plan.  Once in the trade, Trade Unafraid will use all of its dynamic tactics to manage the trade as your Trade Plan specifies.
  10. You also always have the ability to override and use manual controls.  Once triggered, there is no difference between a trade that came from TradingView and one that was triggered normally from within Trade Unafraid.

Consistent, Reproducible Trade Plans

I encourage you to use a version number in your Trade Plan Template name (despite the fact that I did not in this example).  For example, call it tvwh v1.  When you make tweaks, don't save it with the same name.  Save it as tvwh v2.  When we get into the coming quant analysis, you will appreciate the ability to compare the results of version 2 to version 1, which might inspire version 3.  (By the way, in case it wasn't obvious, tvwh stands for TradingView WebHook.  There is nothing special about that name.)

Unlike discretionary trading, where you do different things at different times because of different moods or how you slept or whatever, the power of trading with a consistent, reproducible Trade Plan is that you can do real data science on it.  You can actually see what works best over time.  You can harness the Law of Large Numbers and put it to work for you, free from emotions, lapses in judgement, or whatever else makes your trading more art than science.

Go Forth and Multiply Your Gains

This ended up being much longer than I expected, but I hope it's a clear and complete walk-through of making this integration work.  Please direct your questions to support.

Happy Trading!

Comments