Trading View Integration | Tradetron Blogs

The below guide will show you how you can integrate your tradingview with Tradetron.

Prequisites:

  1. API

    token: This is a unique token that you

    can now generate for your strategy

    . The token is

    bound

    to one strategy template and cannot be used elsewhere.

  2. Tradingview account: Please note that alerts with webhook can only be set from a paid trading view subscription.

  3. A basic strategy

  4. Basic understanding of Tradetron workflow: Although, there is much to know about Tradetron, however, the below points are enough to start your first very basic strategy integration.

    1. A condition builder is a place where all your conditions should be in comparison with something, which means, each condition should return either True or false

    2. Once an entry is taken, the entry block will again execute only after the exit block is triggered.

    3. You will have to figure out how to send API calls for each instrument if your pine script is working on a list of instruments.

  5. Basic understanding of the API calls made by tradingview and how it is handled by Tradetron.

From tradingview, we send keys(variable names) and its value(variable values) from alerts via webhook, these webhooks send an HTTP post request to Tradetron.

When Tradetron gets these values from tradingview, it matches these values in its condition builder and triggers any positions defined in the Position builder.

Step 1:

Open the tradingview and select the instrument. In our example, we have selected Crude Oil Futures.

Step 2:

Set your indicators. In our example, we have selected SMA 2 and SMA 5.

01

 

Step 3:

Select Alerts and click create Alert

02

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Step 4:

Create your condition. In our Example, i am setting an alert when SMA2 cross SMA 5 from bottom to the top

03

 

 

 

 

 

 

 

 

 

 

 

Step 5:

Let us first generate a token for your strategy.

  1. G

    o to “MY STRATEGIES” Page in your Tradetron account

  2. Click the three dots on the strategy and select API OAUTH Token

04

 

 

 

 

3. This will open the menu

05

 

 

 

 

 

 

 

 

 

 

 

   

4.  Select Link and click Proceed, this generates the token and release control of Tradetron

06

 

 

 

 

 

 

 

 

 

 

 

 

 

5. The Part outlined in red is your token.

ab4ee4c7-4413-4110-993e-cf9b9b927d4a

        6.  You can go back to the same menu to unlink the API control

07

 

 

 

 

 

 

 

 

 

 

 

 

Note: Every time you unlink and relink a strategy, you will get a new API code. Just to illustrate this point I have unlinked and relinked the strategy which generated a new key.

Now go back to tradingview and select Webhook URL in the same menu and insert https://api.tradetron.tech/api in the below text box.

08

 

 

 

 

 

 

 

 

 

 

 

Step 6: 

Now comes the sending api request part. The variables and values are send in a JSON format and always in a pair. In this strategy when this alert triggers, i want trading view to send a variable and value to Trading view signifying a Long signal and Short Exit Signal

09

 

 

 

 

{“auth-token”:”2d07b8c5-dcda-4ea9-972c-cc413d654846“,”key”:”Crude_long”,”value”:”1″,”key1″:”Crude_long_lots”,”value1″:”100″,”key2″:”Crude_short”,”value2″:”0″}

10

 

 

 

 

 

 

 

 

 

 

 

 

Step 7:

I will create one more alert with opposite condition, i.e when SMA 5 crosses up SMA 2 signifying my short position and my Long Exit

{“auth-token”:”2d07b8c5-dcda-4ea9-972c-cc413d654846“,”key”:”Crude_short”,”value”:”1″,”key1″:”Crude_short_lots”,”value1″:”100″,”key2″:”Crude_long”,”value2″:”0″}

11

 

 

 

 

 

 

 

 

 

 

 

Notice that my variables are different but my auth token is the same.

Note: the key: value start from key, key1, key2, key3…

And my values also start from value, value1, value2, vlaue3…

This order should not be changed else the api call will not trigger

Step 8:

Go to Tradetron & create your strategy

In Set 1, i will define my condition as below

12

  1. The first condition is when i want the trades to start.

  2. The Get Run-time keyword is used to fetch the value of the the variable “Crude_long” and check if its value is equal to 1

  3. Position detail in only to ensure that at any given time, only one side position is open

 

Step 9:

I will define my position builder as below

13

I will select FX in Qty formula and add Get Runtime keyword with variable name Crude_long_lots in it

14

 

 

 

 

 

 

 

 

 

 

Step 10:

I will define my set 1 exit as below

15

 

Conclusion:

Now when Tradingview triggers the first alert it will send value 1 for Crude_long and 100 for Crude_long_lots

The first variable gets compared in set no 1 and a position will be taken

16

 

Now when the second alert gets triggered, it will send value 1 for Crude_short and 100 for Crude_short_lots

This will trigger an Exit for set no 1 and Entry for Set no 2.

18

You can check your Variable from Runtime Data

19

 

And that concludes the guide.
Please let us know if you have any questions on [email protected]