{"id":167,"date":"2021-01-29T06:50:28","date_gmt":"2021-01-29T06:50:28","guid":{"rendered":"https:\/\/algomojo.com\/blog\/?p=167"},"modified":"2025-02-27T07:32:06","modified_gmt":"2025-02-27T07:32:06","slug":"how-to-send-cover-orders-from-tradingview-to-algomojo-platform","status":"publish","type":"post","link":"https:\/\/algomojo.com\/blog\/how-to-send-cover-orders-from-tradingview-to-algomojo-platform\/","title":{"rendered":"How to Send Cover Orders from Tradingview to Algomojo Platform"},"content":{"rendered":"\n<p>This tutorial helps you to understand how to send cover orders from the Tradingview platform using the webhook method to&nbsp;the Algomojo Trading Platform.<\/p>\n\n\n\n<p><strong>Supported Brokers<\/strong><\/p>\n\n\n\n<p>Aliceblue, Upstox, Tradejini, Zebu<\/p>\n\n\n\n<p><strong>What is a Cover Order?<\/strong><\/p>\n\n\n\n<p><strong>Cover Order is a 2 legged Intraday order <\/strong><br>1)Leg 1 is the main Buy or Sell Order (Market Order \/ SL-Limit Order)<br>2)Leg 2 is a compulsory stop-loss Order (SL-Market Order)<\/p>\n\n\n\n<p><strong>Benefit of Cover Order<\/strong><\/p>\n\n\n\n<p>1)Intraday Risk is Pre-Defined and Controlled<br>2)Order Goes to the Exchange and rest there. Even if the Broker Server goes for Outage or Even if the traders internet goes down no matter what Cover Order gets a fill.<\/p>\n\n\n\n<p><strong>TradingView Webhook<\/strong><\/p>\n\n\n\n<p>Tradingview&nbsp;Webhooks allow you to send a POST request to a certain URL every time the alert is triggered. This feature can be enabled when you create or edit an alert<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/i2.wp.com\/www.marketcalls.in\/wp-content\/uploads\/2020\/10\/image-6.png?resize=715%2C268&amp;ssl=1\" alt=\"This image has an empty alt attribute; its file name is image-6.png\"\/><\/figure>\n\n\n\n<p>Various Modes One can send Alerts from Tradingview Platform<\/p>\n\n\n\n<p>1)Horizontal Line Trigger Alerts<br>2)Price Crossover Alerts<br>3)Trendline\/Channel Alerts<br>4)Custom Indicator\/Strategy Alerts<br>5)Tradingview Screener Alerts<\/p>\n\n\n\n<p><strong>Free Version or Paid Version in Tradingview?<\/strong><\/p>\n\n\n\n<p>Both free version and paid version support real-time data for NSE Cash, NSE Futures, MCX Futures with Alerts. However, Webhook Alerts are available in the Tradingview Pro version onwards.<\/p>\n\n\n\n<p><strong>Tradingview Strategy to Place Cover Orders<\/strong><\/p>\n\n\n\n<p>Tradingview Supports strategies which contains rules in pinescript language which instructs the system when to Buy\/Sell orders, Modify, Cancel Orders.<\/p>\n\n\n\n<p><strong>Supertrend with Cover-Order Stoploss Plot<\/strong><\/p>\n\n\n\n<p>CoverOrder Price for Buy = closing value when buy got triggered &#8211; stoploss<br>CoverOrder Price for Sell = closing value when short got triggered &#8211; stoploss<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/www.tradingview.com\/x\/cWlhG6S2\/\" alt=\"cWlhG6S2 (1471\u00d7922)\"\/><\/figure>\n\n\n\n<p><strong>Tradingview Alerts Settings<\/strong><\/p>\n\n\n\n<p><strong>Supertrend Pinescript Code for Placing Cover Orders<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">\n\/\/ Algomojo Trading Strategy\n\n\n\/\/@version=4\nstrategy(&quot;SuperTrend Algomojo Cover Order Strategy&quot;, overlay=true)\n\n\n\n\/\/inputs\nPeriods = input(title=&quot;ATR Period&quot;, type=input.integer, defval=10)\nsrc = input(hl2, title=&quot;Source&quot;)\nMultiplier = input(title=&quot;ATR Multiplier&quot;, type=input.float, step=0.1, defval=3.0)\nchangeATR= input(title=&quot;Change ATR Calculation Method ?&quot;, type=input.bool, defval=true)\nshowsignals = input(title=&quot;Show Buy\/Sell Signals ?&quot;, type=input.bool, defval=true)\nhighlighting = input(title=&quot;Highlighter On\/Off ?&quot;, type=input.bool, defval=true)\nbarcoloring = input(title=&quot;Bar Coloring On\/Off ?&quot;, type=input.bool, defval=true)\nplotstop = input(title=&quot;Plot Stoploss On\/Off ?&quot;, type=input.bool, defval=true)\nstoploss = input(title=&quot;Stoploss&quot;, type=input.integer, defval=10)\n\n\natr2 = sma(tr, Periods)\natr= changeATR ? atr(Periods) : atr2\nup=src-(Multiplier*atr)\nup1 = nz(up[1],up)\nup := close[1] &gt; up1 ? max(up,up1) : up\ndn=src+(Multiplier*atr)\ndn1 = nz(dn[1], dn)\ndn := close[1] &lt; dn1 ? min(dn, dn1) : dn\n\ntrend = 1\ntrend := nz(trend[1], trend)\ntrend := trend == -1 and close &gt; dn1 ? 1 : trend == 1 and close &lt; up1 ? -1 : trend\n\nupPlot = plot(trend == 1 ? up : na, title=&quot;Up Trend&quot;, style=plot.style_linebr, linewidth=2, color=color.green)\nbuySignal = trend == 1 and trend[1] == -1\nplotshape(buySignal ? up : na, title=&quot;UpTrend Begins&quot;, location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)\nplotshape(buySignal and showsignals ? up : na, title=&quot;Buy&quot;, text=&quot;Buy&quot;, location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)\n\ndnPlot = plot(trend == 1 ? na : dn, title=&quot;Down Trend&quot;, style=plot.style_linebr, linewidth=2, color=color.red)\nsellSignal = trend == -1 and trend[1] == 1\nplotshape(sellSignal ? dn : na, title=&quot;DownTrend Begins&quot;, location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)\nplotshape(sellSignal and showsignals ? dn : na, title=&quot;Sell&quot;, text=&quot;Sell&quot;, location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)\n\nmPlot = plot(ohlc4, title=&quot;&quot;, style=plot.style_circles, linewidth=0)\nlongFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white\nshortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white\nfill(mPlot, upPlot, title=&quot;UpTrend Highligter&quot;, color=longFillColor)\nfill(mPlot, dnPlot, title=&quot;DownTrend Highligter&quot;, color=shortFillColor)\n\nFromMonth = input(defval = 9, title = &quot;From Month&quot;, minval = 1, maxval = 12)\nFromDay   = input(defval = 1, title = &quot;From Day&quot;, minval = 1, maxval = 31)\nFromYear  = input(defval = 2019, title = &quot;From Year&quot;, minval = 999)\nToMonth   = input(defval = 1, title = &quot;To Month&quot;, minval = 1, maxval = 12)\nToDay     = input(defval = 1, title = &quot;To Day&quot;, minval = 1, maxval = 31)\nToYear    = input(defval = 2100, title = &quot;To Year&quot;, minval = 999)\nstart     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  \nfinish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)       \nwindow()  =&gt; time &gt;= start and time &lt;= finish ? true : false\n\n\ntradestop = close\n\ntradestop := iff(buySignal, valuewhen(buySignal,close[1]-stoploss,0),iff(sellSignal,valuewhen(sellSignal,close[1]+stoploss,0),tradestop[1]))\n\n\nplot(tradestop,title=&quot;tradestop&quot;,color=color.yellow)\n\n\n\n\n\/\/Alerts\nalertcondition(buySignal, title=&quot;SuperTrend Buy&quot;, message=&quot;SuperTrend Buy!&quot;)\nalertcondition(sellSignal, title=&quot;SuperTrend Sell&quot;, message=&quot;SuperTrend Sell!&quot;)\n\nlongCondition = buySignal\nif (longCondition)\n    strategy.entry(&quot;BUY&quot;, strategy.long, when = window(),comment=&quot;B&quot;)\nshortCondition = sellSignal\nif (shortCondition)\n    strategy.entry(&quot;SELL&quot;, strategy.short, when = window(),comment=&quot;S&quot;)\nbuy1= barssince(buySignal)\nsell1 = barssince(sellSignal)\ncolor1 = buy1[1] &lt; sell1[1] ? color.green : buy1[1] &gt; sell1[1] ? color.red : na\nbarcolor(barcoloring ? color1 : na)<\/code><\/pre>\n\n\n\n<p>Strategies allow you to perform&nbsp;<em>backtesting<\/em>&nbsp;(emulation of a strategy trading on historical data) and&nbsp;<em>forwardtesting<\/em>&nbsp;(emulation of a strategy trading on real-time data) according to your algorithms.<\/p>\n\n\n\n<p>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 with Dynamic Stoploss (Different stoploss for Buy and Sell Cover Orders)<\/p>\n\n\n\n<p><strong>Webhook URL for placing orders (MKT, LMT, SL, SL-LMT, CO,AMO orders)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">Broker - Aliceblue \nhttps:\/\/abapi.algomojo.com\/1.0\/PlaceOrder \n\nBroker - Upstox\nhttps:\/\/upapi.algomojo.com\/1.0\/PlaceOrder \n\nBroker - Tradejini\nhttps:\/\/tjapi.algomojo.com\/1.0\/PlaceOrder \n\nBroker - Zebu\nhttps:\/\/zbapi.algomojo.com\/1.0\/PlaceOrder<\/code><\/pre>\n\n\n\n<p><strong>Webhook Message Format&nbsp;\u2013&nbsp;Sample Placeorder Example for Aliceblue<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-json\">{\n    &quot;api_key&quot;:&quot;c1997d92a3bb556a67dca7d1446b70&quot;,\n    &quot;api_secret&quot;:&quot;5306433329e81ba41203653417063c&quot;,\n    &quot;data&quot;:\n      {\n        &quot;strg_name&quot;:&quot;Cover Order&quot;,\n        &quot;s_prdt_ali&quot;:&quot;BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML&quot;,\n        &quot;Tsym&quot;:&quot;RELIANCE-EQ&quot;,\n        &quot;exch&quot;:&quot;NSE&quot;,\n        &quot;Ttranstype&quot;:&quot;{{strategy.order.comment}}&quot;,\n        &quot;Ret&quot;:&quot;DAY&quot;,\n        &quot;prctyp&quot;:&quot;MKT&quot;,\n        &quot;qty&quot;:&quot;75&quot;,\n        &quot;discqty&quot;:&quot;0&quot;,\n        &quot;MktPro&quot;:&quot;NA&quot;,\n        &quot;Price&quot;:&quot;0&quot;,\n        &quot;TrigPrice&quot;:&quot;{{plot(&quot;tradestop&quot;)}}&quot;,\n        &quot;Pcode&quot;:&quot;CO&quot;,\n        &quot;AMO&quot;:&quot;NO&quot;\n      }\n}<\/code><\/pre>\n\n\n\n<p><strong>Dynamic Webhook Placeholder used<\/strong><\/p>\n\n\n\n<p>Among All the Place Holders we are going to use <strong>{{strategy.order.comment}} and {{plot(&#8220;tradestop&#8221;)}}<\/strong> which reads the comment from the strategy section and dynamic tradestop to change the order type dynamically based on the supertrend Buy or Sell Signal with a pre-determined stop loss.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">{{strategy.order.comment}} - Which dynamically transmits &quot;B&quot; or &quot;S &quot; values\n{{plot(&quot;tradestop&quot;)}} - Which Dynamically transmits the stop Price. The stop price is computed and plotted using the plot function as shown below<\/code><\/pre>\n\n\n\n<p><strong>Where to Check the Order in Realtime in Algomojo<\/strong><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Let me know in comments if you find this tutorial useful or incase if you need more details about algomojo integration with tradingview you can comment your inputs below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial helps you to understand how to send cover orders from the Tradingview platform using the webhook method to Algomojo Trading Platform.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[91],"tags":[13,90,33],"_links":{"self":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/comments?post=167"}],"version-history":[{"count":4,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":1584,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/167\/revisions\/1584"}],"wp:attachment":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/media?parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}