Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

How to Send Automated Orders from TradingView Buy/Sell Strategy to Algomojo Platform

4 min read

This tutorial explains how to send Automated orders from Trading view strategies to Algomojo Trading Platform.

Tradingview Supports stratgegies which contains rules in pinescript language which instructs the system when to Buy/Sell orders, Modify, Cancel Orders.

Strategies allow you to perform backtesting (emulation of a strategy trading on historical data) and forwardtesting (emulation of a strategy trading on real-time data) according to your algorithms.

If you are very new to the Algomojo Platform then kickstart with this tutorial

How to Send Automated Option Orders Tutorial

In order to send market orders from Tradingview to Algomojo in the last tutorial, we seen how to use Tradingview webhook feature to configure Automated orders using the Tradingview Alert Option.

Now this time we are going to use tradingview placeholders in the webhook Alert option to dynamically send Buy Orders when there is a Buy Signal in Supertrend and Sell Signal when there is a Sell Signal in Supertrend

List of Trading Placeholders Supported for Algotrading Alerts

Among All the Place Holders we are going to use {{strategy.order.comment}} which reads the comment from the strategy section and change the order type dynamically based on the supertrend Buy or Sell Signal

//Alerts
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")

longCondition = buySignal
if (longCondition)
    strategy.entry("BUY", strategy.long, when = window(),comment="B")
shortCondition = sellSignal
if (shortCondition)
    strategy.entry("SELL", strategy.short, when = window(),comment="S")

Comment PlaceHolder

{{strategy.order.comment}} – returns the comment of the executed order (the string used in the comment parameter in one of the function calls generating orders: strategy.entry, strategy.exit or strategy.order). If no comment is specified, then the value of strategy.order.id will be used.

Configuring Alerts

Click on the Alert option to configure alerts

Under the Alert Condition Tab use the drop down and change to Supertrend Algomojo and enable the Webhook URL option as shown below

Under the webhook url configure the relevant Algomojo – Partner Brokers url as shown below to place order

Broker - Aliceblue 
https://abapi.algomojo.com/1.0/PlaceOrder 

Broker - Tradejini
https://tjapi.algomojo.com/1.0/PlaceOrder 

Broker - Zebu
https://zbapi.algomojo.com/1.0/PlaceOrder

Configure the Webhook Message with Placeholders

Here is the sample message with necessary placeholders

configure your API Key and API Secret key from the Algomojo portal. Here is the sample code which place Buy and Sell order for Reliance with 100 shares in intraday mode.

{
    "api_key":"8f8cb9504bb91bd5472b68483cbda8bb",
    "api_secret":"845802a70c8881a66cccfde02d83934d",
    "data":
      {
        "strg_name":"Supertrend Strategy",
        "s_prdt_ali":"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML",
        "Tsym":"RELIANCE-EQ",
        "exch":"NSE",
        "Ttranstype":"{{strategy.order.comment}}",
        "Ret":"DAY",
        "prctyp":"MKT",
        "qty":"100",
        "discqty":"0",
        "MktPro":"NA",
        "Price":"0",
        "TrigPrice":"0",
        "Pcode":"MIS",
        "AMO":"NO"
      }
}

Copy the anove code modify according to your need and paste in the Alert Webhook comments block as shown below

Here is the Complete Pinescript Strategy and to place automated orders ensure one configures the Alert Settings as mentioned above.

TradingView Pinescript Strategy


// Algomojo Trading Strategy


//@version=4
strategy("SuperTrend Algomojo Trading Strategy", overlay=true)



//inputs
Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
barcoloring = input(title="Bar Coloring On/Off ?", type=input.bool, defval=true)

atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
FromMonth = input(defval = 9, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear  = input(defval = 2018, title = "From Year", minval = 999)
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear    = input(defval = 9999, title = "To Year", minval = 999)
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)       
window()  => time >= start and time <= finish ? true : false


//Alerts
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")

longCondition = buySignal
if (longCondition)
    strategy.entry("BUY", strategy.long, when = window(),comment="B")
shortCondition = sellSignal
if (shortCondition)
    strategy.entry("SELL", strategy.short, when = window(),comment="S")
buy1= barssince(buySignal)
sell1 = barssince(sellSignal)
color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na
barcolor(barcoloring ? color1 : na)

One the alert triggers automated orders will be placed instantly in algomojo platform

Where to Check the Order in Realtime in Algomojo

You can use order logs to check for any incoming automated orders generating from Tradingview Webhooks in Realtime and can also download the logs for later use.

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Supertrend v4.0 with EMA Filter – Tradingview Pinescript Code

Supertrend with a simple EMA Filter can improve the performance of the signals during a strong trending market and reduces the number of trades...
Rajandran R
1 min read

Line Trading – Algomojo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
58 sec read

Tradingview Pinescript v5 – Masterclass

This Pinescript Masterclass course covers trading system development and automation using Tradingview Pinescript v5. The course is designed for traders who want to learn...
Rajandran R
2 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More