With the arrival of Webhooks blocks on Kryll, users can now drive their strategies usign an external or personalized platform. In this article, we show you how to run a Kryll strategy algorithm via PineScript (a programming language developed by TradingView for strategy and indicator creation).

Prerequisite: You must have at least a Pro account on TradingView  to be able to generate Webhook alerts.

We will use a TradingView example strategy developed in Pinescript v5.

In this example, the strategy will use two technical indicators that are not available on Kryll: the intersection of two moving averages of RSI and the Vortex indicator. Depending on the configuration of these indicators, the strategy will place Long, Short or Close orders.

``````//@version=5
// KRYLL Webhook - Tradingview strategy Exemple
strategy("Demo Strat", overlay=true)

// inputs zone
rsi_length =  input.int(7, title="RSI Length", minval=2)
rsi_fma_length = input.int(7, title="Fast RSI MA Length", minval=2)
rsi_sma_length = input.int(14, title="Slow RSI MA Length", minval=4)
rsi_neutral =  input.int(20, title="RSI neutral zone", minval=2)
vortex_period = input.int(14, title="Vortex Length", minval=2)

// Vortex indicator computation
VMP = math.sum( math.abs( high - low), vortex_period )
VMM = math.sum( math.abs( low - high), vortex_period )
STR = math.sum( ta.atr(1), vortex_period )
VIP = VMP / STR
VIM = VMM / STR

// Fast and Slow RSI Moving Average computation
rsi = ta.rsi(close, rsi_length)
rsiFMA = ta.sma(rsi, rsi_fma_length)
rsiSMA = ta.sma(rsi, rsi_sma_length)

// Fast and Slow RSI cross detection
co = ta.crossover(rsiFMA, rsiSMA)
cu = ta.crossunder(rsiFMA, rsiSMA)

if (not na(rsiSMA))
if (VIP < VIM)
if( cu )
else
if (VIP > VIM)
if( co )
else

### Study of the Tradingview strategy

This strategy generates 3 types of orders depending on the configuration of the indicators used.

We will have to create a Kryll strategy that will wait for one of these 3 signals to execute the corresponding trade. In this TradingView strategy, we can see that a long or short position can be followed by their opposite without necessarily going through a close first. The strategy should be designed accordingly.

### Implementation of the strategy in Kryll

The implementation of this Kryll strategy that will be driven via Webhooks could look like this.

Each webhook block will provide you with a URL generic to the strategy and a Payload message specific to each block. This information must be provided to TradingView through the pinescript code.

At this point our strategy is complete, we can even launch it.

We will now move on to modifying your TradingView strategy to allow it to send signals to the Kryll strategy.

First of all, let's modify the beginning of the strategy to add some useful statements for the following:

Let's add the variables that will allow us to store and use the 'action_id' of our different Webhook blocks:

Finally, let's modify some position entry/exit/close calls (strategy.entry and strategy.close) so that the TradingView strategy can build and send the right message to Kryll.

### Final Result

Here is what the finalized script looks like.

``````//@version=5
// KRYLL Webhook - Tradingview strategy Exemple
strategy("Demo Strat", overlay=true)

// Kryll Webhook declarations
kryll_action=""

id_block_long = "8f94aaf9-0f37-4730-8565-a40c8f151921"
id_block_short = "8f94aaf9-2f30-7430-2364-519a40c8f121"
id_block_close = "8f94aaf9-1a37-3540-5431-c8f121519a40"

// inputs zone
rsi_length =  input.int(7, title="RSI Length", minval=2)
rsi_fma_length = input.int(7, title="Fast RSI MA Length", minval=2)
rsi_sma_length = input.int(14, title="Slow RSI MA Length", minval=4)
rsi_neutral =  input.int(20, title="RSI neutral zone", minval=2)
vortex_period = input.int(14, title="Vortex Length", minval=2)

// Vortex indicator computation
VMP = math.sum( math.abs( high - low), vortex_period )
VMM = math.sum( math.abs( low - high), vortex_period )
STR = math.sum( ta.atr(1), vortex_period )
VIP = VMP / STR
VIM = VMM / STR

// Fast and Slow RSI Moving Average computation
rsi = ta.rsi(close, rsi_length)
rsiFMA = ta.sma(rsi, rsi_fma_length)
rsiSMA = ta.sma(rsi, rsi_sma_length)

// Fast and Slow RSI cross detection
co = ta.crossover(rsiFMA, rsiSMA)
cu = ta.crossunder(rsiFMA, rsiSMA)

if (not na(rsiSMA))
if (VIP < VIM)
if( cu )
else
if (VIP > VIM)
if( co )
else

Once you have finalized your script, set the pair and time unit on which you want to run your TradingView strategy. In our case, we'll set the pair to ETH/USDT and a time unit of 2 hours.

Then go to the "Pine Editor" to paste our strategy and save it.

Let's add our strategy via the 'Indicators' button to make it appear on the chart.

With our TradingView configured, let's now create the alert that will allow us to send messages to our strategy via webhook calls.

To do this, let's click on the 'Create Alert' button and configure it: select our strategy as a condition, name our alert and configure the message:

Next, let's set up the strategy's webhook URL. You will find this URL on one of the webhook blocks of your Kryll strategy.

## To go further...

The example described in this tutorial remains simple and could be enriched by adding a Take Profit or a Stop Loss which would then be new Webhook blocks leading to another flow.

The interfacing of TradingView and Kryll opens up an infinite number of possibilities for Kryll users. You can now create your own technical indicators, mix them together, clone indicators or strategies from the TradingView community and use all of this to create your own automated trading strategies!

Various tutorials are available for more information. The Kryll team has several other articles related to this subject:

Thank you for following this tutorial! To your Webhooks! Website : https://kryll.io