Simplified Algomojo Execution Controls for Tradingview Platform

This tutorial explains how to configure trading pinescript trading strategies with Algomojo execution controls to send MKT orders to Algomojo supported Brokers in a very simple manner.

Supported Brokers : Aliceblue, Angel Broking, Tradejini, Upstox, Zebu

LCe1w8ED (1818×926)

Tradingview Supports strategies which contain rules in pinescript language which instruct the system when to Buy/Sell orders, Modify, Cancel Orders.

We know that the Tradingview PRO account supports Webhook Alerts. Which can be used to transmit any information to 3rd Party Applications. Remember Webhook is more of one-way communication.

What is Webhook?

Webhook is a unique way of communicating in realtime from one application to another application. Webhooks are automatic. You don’t have to manually utilize them in order to make them work — once they’re set up, they run on their own.

TradingView Webhook

Tradingview 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.

Algomojo Execution Controls

What Iam trying to achieve here is trying to provide readymade controls which can be used in your pinescript trading strategies to simplify your execution controls.

Algomojo Execution control comes with 3 different blocks

Block 1 – API Controls + Algomojo Input Controls

Sample Input Controls for Angel Broking. It creates input controls related to order parameters, leverage, trading symbol, quantity controls etc. Input controls differs for different brokers. checkout the supertrend pinescript code provided for different brokers below (pinescript is provided for Aliceblue, Tradejini, Zebu, Angel Broking, Aliceblue)

//Algomojo Controls - for Angel Broking
//Block 1 : API Controls + Algomojo Input Controls


//Enter Your Algomojo API Key and API Secret Key


api_key = "b48e4db30e47326722a388c03eb4ee26"
api_secret = "fc3ed44d0914b0e6466f9ff2e3ae003a"


stgy_name = input(title="Strategy Name",type=input.string,defval="Tradingview Strategy")
variety = input(title="Variety",type=input.string,defval="NORMAL",options=["NORMAL","STOPLOSS","AMO"])
tradingsymbol = input(title="Trading Symbol",type=input.string,defval="NIFTY29APR21FUT")
symboltoken = input(title="Symbol Token",type=input.string,defval="64422")
exchange =  input(title="Exchange",type=input.string,defval="NFO",options=["NSE","NFO","MCX","BSE"])
ordertype = input(title="Order Type",type=input.string,defval="MARKET",options=["MARKET","LIMIT","STOPLOSS_LIMIT","STOPLOSS_MARKET"])
producttype =  input(title="Product Type",type=input.string,defval="CARRYFORWARD",options=["DELIVERY","CARRYFORWARD","MARGIN","INTRADAY","AMO_MARGIN","AMO_DELIVERY","AMO_CARRYFORWARD"])
duration = "DAY"
price = "0"
squareoff = "0"
stoploss = "0"
quantity = input(title="Quantity", type=input.integer, defval=5)
triggerprice = "0"
trailingStopLoss =  "0"
disclosedquantity = "0"

////////////////////////////////////////Block 1 Module Ends////////////////////////////////////////////////////////////////////////

Block 2: Autotrading API data configuration

This creates variables containing the API data string information which needs to be configured in Block 3 Execution Module

API data messaging variables

BE – variables that control the api message for Buy Entry (Fresh Buy – 1x qty)
SX – variables that control the api message for Short Exit (Short Exit – 1x qty)
BSR -variables that control the api message for Buy Stop Reverse (2x qty)

SE – variables that control the api message for Short Entry (Fresh Shorts – 1x qty)
BX – variables that control the api message for Buy Exit (Buy Exit – 1x qty)
SSR -variables that control the api message for Short Stop Reverse (2x qty)

//Block 2 : Autotrading API data configuration - Angel Broking

//BE - Buy Entry (1x qty), SX - Short Exit (1x qty), BSR - Buy Stop and Reverse (2x qty)

BE =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"BUY\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
SX =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"BUY\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
BSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"BUY\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity*2)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"

//SE - Short Entry (1x qty), Buy Exit - Short Exit (1x qty), SXR - Short Stop and Reveverse (2x qty)

SE =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"SELL\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
BX =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"SELL\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
SSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"SELL\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity*2)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"


////////////////////////////////////////Block 2 Module Ends////////////////////////////////////////////////////////////////////////

Block3: Order Execution Module

Order execution module finally connects the signals with Alert Message containing the Block2 API data variables

//Block 3 : Execution Controls

if (longCondition and strategy.position_size==0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BE) //Buy Entry
if (longCondition and strategy.position_size<0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BSR) //Buy Stop and Reverse
if (shortCondition and strategy.position_size==0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SE) //Short Entry
if (shortCondition and strategy.position_size>0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SSR) //Short Stop and Reverse
    
////////////////////////////////////////Block 3 Module Ends////////////////////////////////////////////////////////////////////////

Once all the three blocks are properly configured in the your pinescript trading strategy configuring the Alerts are likely to be a very minimal effort.

Now Create an Alert with proper webhook and placeholder message as shown below (different broker different webhook url needs to be used as instructed below the supertrend AFL code)

Alert Message Section

Alert Message Section is simplified to the end user to configure only the placeholder {{strategy.order.alert_message}} in the Message Box so that end user need not to know about the complexity of configuring the API dat in JSON format. All the complexities are handled at pinescript coding level.

Here are the sample Supertrend Code for Different Brokers using above 3 blocks. One can configure these three blocks in their tradingview strategy to simplify their Tradingview Configuration with Execution Controls.

Algomojo Supertrend Code & Controls & Alert Configuration for Aliceblue, Tradejini, Zebu

Input Controls

Supertrend Pinescript Code for Aliceblue, Tradejini, Zebu

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rajandran

//@version=4
strategy("Supertrend Indicator",overlay=true)

//input controls




Multiplier = input(title="Multiplier", type=input.integer, defval=2,group="Indicators")
ATRLength = input(title="ATR Period", type=input.integer, defval=10,group="Indicators")


[tsl,dir] = supertrend(Multiplier,ATRLength)


//Block 1 : API Controls + Algomojo Input Controls


//Enter Your Algomojo API Key and API Secret Key


api_key = "86cbef19e7e61ccee91e497690d5814e"
api_secret = "9e16d6d19e42e82fed6c4b3b2be7c271"


strg_name = input(title="Strategy Name",type=input.string,defval="Supertrend Strategy",group="AlgoControls")
s_prdt_ali = "BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML"
Tsym = input(title="Trading Symbol",type=input.string,defval="RELIANCE-EQ",group="AlgoControls")
exch = input(title="Exchange",type=input.string,defval="NSE",options=["NSE","NFO","MCX","BSE"],group="AlgoControls")
Ret = "DAY"
qty = input(title="Quantity", type=input.integer, defval=1,group="AlgoControls")
prctyp =input(title="Order Type",type=input.string,defval="MKT",options=["MKT","LMT","SL","SL-M"],group="AlgoControls")
discqty = "0"
MktPro ="NA"
Price = "0"
TrigPrice = "0"
Pcode = input(title="PCode",type=input.string,defval="NRML",options=["CNC","NRML","MIS","CO"],group="AlgoControls")
AMO = "NO"

////////////////////////////////////////Block 1 Module Ends////////////////////////////////////////////////////////////////////////



//Block 2 : Autotrading API data configuration

//BE - Buy Entry (1x qty), SX - Short Exit (1x qty), BSR - Buy Stop and Reverse (2x qty)

BE = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":       {   \"strg_name\":\""+strg_name+"\",         \"s_prdt_ali\":\"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML\",         \"Tsym\":\""+Tsym+"\",         \"exch\":\""+exch+"\",         \"Ttranstype\":\"B\",         \"Ret\":\"DAY\",         \"prctyp\":\""+prctyp+"\",     \"qty\":\""+tostring(qty)+"\",       \"discqty\":\"0\",         \"MktPro\":\"NA\",         \"Price\":\"0\",         \"TrigPrice\":\"0\",          \"Pcode\":\""+Pcode+"\",            \"AMO\":\"NO\"       } }"
SX = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":       {   \"strg_name\":\""+strg_name+"\",         \"s_prdt_ali\":\"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML\",         \"Tsym\":\""+Tsym+"\",         \"exch\":\""+exch+"\",         \"Ttranstype\":\"B\",         \"Ret\":\"DAY\",         \"prctyp\":\""+prctyp+"\",     \"qty\":\""+tostring(qty)+"\",       \"discqty\":\"0\",         \"MktPro\":\"NA\",         \"Price\":\"0\",         \"TrigPrice\":\"0\",         \"Pcode\":\""+Pcode+"\",         \"AMO\":\"NO\"       } }"
BSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":       {   \"strg_name\":\""+strg_name+"\",         \"s_prdt_ali\":\"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML\",         \"Tsym\":\""+Tsym+"\",         \"exch\":\""+exch+"\",         \"Ttranstype\":\"B\",         \"Ret\":\"DAY\",         \"prctyp\":\""+prctyp+"\",      \"qty\":\""+tostring(qty*2)+"\",       \"discqty\":\"0\",         \"MktPro\":\"NA\",         \"Price\":\"0\",         \"TrigPrice\":\"0\",       \"Pcode\":\""+Pcode+"\",        \"AMO\":\"NO\"       } }" 

//SE - Short Entry (1x qty), Buy Exit - Short Exit (1x qty), SXR - Short Stop and Reveverse (2x qty)

SE = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":       {   \"strg_name\":\""+strg_name+"\",         \"s_prdt_ali\":\"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML\",         \"Tsym\":\""+Tsym+"\",         \"exch\":\""+exch+"\",         \"Ttranstype\":\"S\",         \"Ret\":\"DAY\",         \"prctyp\":\""+prctyp+"\",      \"qty\":\""+tostring(qty)+"\",       \"discqty\":\"0\",         \"MktPro\":\"NA\",         \"Price\":\"0\",         \"TrigPrice\":\"0\",         \"Pcode\":\""+Pcode+"\",         \"AMO\":\"NO\"       } }"
BX = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":       {   \"strg_name\":\""+strg_name+"\",         \"s_prdt_ali\":\"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML\",         \"Tsym\":\""+Tsym+"\",         \"exch\":\""+exch+"\",         \"Ttranstype\":\"S\",         \"Ret\":\"DAY\",         \"prctyp\":\""+prctyp+"\",      \"qty\":\""+tostring(qty)+"\",       \"discqty\":\"0\",         \"MktPro\":\"NA\",         \"Price\":\"0\",         \"TrigPrice\":\"0\",         \"Pcode\":\""+Pcode+"\",       \"AMO\":\"NO\"       } }"
SSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":       {   \"strg_name\":\""+strg_name+"\",         \"s_prdt_ali\":\"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML\",         \"Tsym\":\""+Tsym+"\",         \"exch\":\""+exch+"\",         \"Ttranstype\":\"S\",         \"Ret\":\"DAY\",         \"prctyp\":\""+prctyp+"\",      \"qty\":\""+tostring(qty*2)+"\",       \"discqty\":\"0\",         \"MktPro\":\"NA\",         \"Price\":\"0\",         \"TrigPrice\":\"0\",       \"Pcode\":\""+Pcode+"\",         \"AMO\":\"NO\"       } }" 

////////////////////////////////////////Block 2 Module Ends////////////////////////////////////////////////////////////////////////

//Block 3 : Backtesting Controls & Live Automation Purpose

FromMonth = input(defval = 9, title = "From Month", minval = 1, maxval = 12,group="Backtesting")
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31,group="Backtesting")
FromYear  = input(defval = 2018, title = "From Year", minval = 999,group="Backtesting")
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12,group="Backtesting")
ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31,group="Backtesting")
ToYear    = input(defval = 9999, title = "To Year", minval = 999,group="Backtesting")
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)  
window()  => time >= start and time <= finish ? true : false





trendcolor = dir==1  ? color.green  : color.red

plot(tsl,color=trendcolor)

buy = dir == -1 and dir[1] == 1
sell = dir ==1 and dir[1]==-1



//indicates the buy or sell signal
//plotshape(buy[1],style=shape.labelup,location = location.belowbar,color=color.green,title = "Buy",text="Buy",textcolor=color.white)
//plotshape(sell[1],style=shape.labeldown,location = location.abovebar,color=color.red,title = "Sell",text="Sell",textcolor=color.white)



longCondition = buy
shortCondition = sell

//Block 4 : Execution Controls

//Fresh Buy -> Algomojo -> Trade 1*Qty (Buy)
if (longCondition and strategy.position_size==0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BE)
//Fresh Buy + Old Short Covering -> 2*Qty (Buy)
if (longCondition and strategy.position_size<0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BSR)
//Fresh Sell -> Algomojo -> Trade 1*Qty (Sell)
if (shortCondition and strategy.position_size==0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SE)
//Fresh Sell + Old Long Exit -> 2*Qty (Sell)
if (shortCondition and strategy.position_size>0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SSR)
    
////////////////////////////////////////Block 4 Module Ends////////////////////////////////////////////////////////////////////////
    


Webhook Endpoint URL : Aliceblue, Tradejini, Zebu

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

Alert Configuration

Angel Broking – Supertrend Pinescript Code, Inputs and Alert Configuration

Supertrend Pinescript Code for Angel Broking


// Algomojo Trading Strategy for Angel Broking


//@version=4
strategy("SuperTrend Algomojo Trading Strategy", shorttitle="Supertrend Algomojo - Angel", 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)

//Algomojo Controls
//Block 1 : API Controls + Algomojo Input Controls


//Enter Your Algomojo API Key and API Secret Key


api_key = "b48e4db30e47326722a388c03eb4ee26"
api_secret = "fc3ed44d0914b0e6466f9ff2e3ae003a"


stgy_name = input(title="Strategy Name",type=input.string,defval="Tradingview Strategy")
variety = input(title="Variety",type=input.string,defval="NORMAL",options=["NORMAL","STOPLOSS","AMO"])
tradingsymbol = input(title="Trading Symbol",type=input.string,defval="NIFTY29APR21FUT")
symboltoken = input(title="Symbol Token",type=input.string,defval="64422")
exchange =  input(title="Exchange",type=input.string,defval="NFO",options=["NSE","NFO","MCX","BSE"])
ordertype = input(title="Order Type",type=input.string,defval="MARKET",options=["MARKET","LIMIT","STOPLOSS_LIMIT","STOPLOSS_MARKET"])
producttype =  input(title="Product Type",type=input.string,defval="CARRYFORWARD",options=["DELIVERY","CARRYFORWARD","MARGIN","INTRADAY","AMO_MARGIN","AMO_DELIVERY","AMO_CARRYFORWARD"])
duration = "DAY"
price = "0"
squareoff = "0"
stoploss = "0"
quantity = input(title="Quantity", type=input.integer, defval=5)
triggerprice = "0"
trailingStopLoss =  "0"
disclosedquantity = "0"

////////////////////////////////////////Block 1 Module Ends////////////////////////////////////////////////////////////////////////


//Block 2 : Autotrading API data configuration

//BE - Buy Entry (1x qty), SX - Short Exit (1x qty), BSR - Buy Stop and Reverse (2x qty)

BE =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"BUY\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
SX =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"BUY\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
BSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"BUY\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity*2)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"

//SE - Short Entry (1x qty), Buy Exit - Short Exit (1x qty), SXR - Short Stop and Reveverse (2x qty)

SE =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"SELL\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
BX =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"SELL\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"
SSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {	\"stgy_name\": \""+stgy_name+"\",        \"variety\":\""+variety+"\",        \"tradingsymbol\":\""+tradingsymbol+"\",        \"symboltoken\":\""+symboltoken+"\",        \"transactiontype\":\"SELL\",        \"exchange\":\""+exchange+"\",        \"ordertype\":\""+ordertype+"\",        \"producttype\":\""+producttype+"\",        \"duration\":\""+duration+"\",        \"price\":\""+price+"\",        \"squareoff\":\""+squareoff+"\",        \"stoploss\":\""+stoploss+"\",        \"quantity\":\""+tostring(quantity*2)+"\",        \"triggerprice\": \""+triggerprice+"\",        \"trailingStopLoss\": \""+trailingStopLoss+"\",        \"disclosedquantity\":\""+disclosedquantity+"\"	  } }"


////////////////////////////////////////Block 2 Module Ends////////////////////////////////////////////////////////////////////////


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


//Plots
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)

//Backtesting Controls

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
shortCondition = sellSignal

//Block 3 : Execution Controls

if (longCondition and strategy.position_size==0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BE)
if (longCondition and strategy.position_size<0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BSR)
if (shortCondition and strategy.position_size==0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SE)
if (shortCondition and strategy.position_size>0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SSR)
    
////////////////////////////////////////Block 3 Module Ends////////////////////////////////////////////////////////////////////////
    
buy1= barssince(buySignal)
sell1 = barssince(sellSignal)
color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na
barcolor(barcoloring ? color1 : na)

Webhook Endpoint URL : Angel Broking

Broker - Angel
https://anapi.algomojo.com/1.0/PlaceOrder

Supertrend Alert Configuration – Angel Broking

Algomojo Supertrend Code & Controls & Alert Configuration for Upstox

Supertrend Pinescript Code for Upstox


// Algomojo Trading Strategy for Upstox


//@version=4
strategy("SuperTrend Algomojo Trading Strategy", shorttitle="Supertrend Algomojo - Upstox", 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)


//Block 1 : API Controls + Algomojo Input Controls


//Enter Your Algomojo API Key and API Secret Key


api_key = "781981bf5cc2662152dab1ed64e8ef30"
api_secret = "02aa902dbe344f7a88af59e0aa7e5d01"

//Algomojo Input Parameters


stgy_name = input(title="Strategy Name",type=input.string,defval="Tradingview Strategy")
symbol = input(title="Trading Symbol",type=input.string,defval="RELIANCE")
exchange = input(title="Exchange",type=input.string,defval="nse_eq",options=["nse_eq","bse_eq","nse_fo","mcx_fo","ncd_fo","bcd_fo"])
duration = "DAY"
order_type = input(title="Order Type",type=input.string,defval="MKT",options=["MKT","LMT","SL","SL-M"])
quantity = input(title="Quantity", type=input.integer, defval=5)
disclosed_quantity = "0"
MktPro = "NA"
price  = "0"
trigger_price = "0"
product = input(title="Product Type",type=input.string,defval="MIS",options=["CNC","MIS","NRML","CO"])
is_amo = "NO"

////////////////////////////////////////Block 1 Module Ends////////////////////////////////////////////////////////////////////////


//Block 2 : Autotrading API data configuration

//BE - Buy Entry (1x qty), SX - Short Exit (1x qty), BSR - Buy Stop and Reverse (2x qty)

BE =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {    \"stgy_name\":\""+stgy_name+"\",         \"symbol\":\""+symbol+"\",         \"exchange\":\""+exchange+"\",         \"transaction_type\":\"B\",        \"duration\":\""+duration+"\",        \"order_type\":\""+order_type+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"disclosed_quantity\":\""+disclosed_quantity+"\",        \"MktPro\":\""+MktPro+"\",        \"price\":\""+price+"\",        \"trigger_price\":\""+trigger_price+"\",        \"product\":\""+product+"\",        \"is_amo\":\""+is_amo+"\"      } }"
SX =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {    \"stgy_name\":\""+stgy_name+"\",         \"symbol\":\""+symbol+"\",         \"exchange\":\""+exchange+"\",         \"transaction_type\":\"B\",        \"duration\":\""+duration+"\",        \"order_type\":\""+order_type+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"disclosed_quantity\":\""+disclosed_quantity+"\",        \"MktPro\":\""+MktPro+"\",        \"price\":\""+price+"\",        \"trigger_price\":\""+trigger_price+"\",        \"product\":\""+product+"\",        \"is_amo\":\""+is_amo+"\"      } }"
BSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {    \"stgy_name\":\""+stgy_name+"\",         \"symbol\":\""+symbol+"\",         \"exchange\":\""+exchange+"\",         \"transaction_type\":\"B\",        \"duration\":\""+duration+"\",        \"order_type\":\""+order_type+"\",        \"quantity\":\""+tostring(quantity*2)+"\",        \"disclosed_quantity\":\""+disclosed_quantity+"\",        \"MktPro\":\""+MktPro+"\",        \"price\":\""+price+"\",        \"trigger_price\":\""+trigger_price+"\",        \"product\":\""+product+"\",        \"is_amo\":\""+is_amo+"\"      } }"

//SE - Short Entry (1x qty), Buy Exit - Short Exit (1x qty), SXR - Short Stop and Reveverse (2x qty)

SE =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {    \"stgy_name\":\""+stgy_name+"\",         \"symbol\":\""+symbol+"\",         \"exchange\":\""+exchange+"\",         \"transaction_type\":\"S\",        \"duration\":\""+duration+"\",        \"order_type\":\""+order_type+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"disclosed_quantity\":\""+disclosed_quantity+"\",        \"MktPro\":\""+MktPro+"\",        \"price\":\""+price+"\",        \"trigger_price\":\""+trigger_price+"\",        \"product\":\""+product+"\",        \"is_amo\":\""+is_amo+"\"      } }"
BX =  "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {    \"stgy_name\":\""+stgy_name+"\",         \"symbol\":\""+symbol+"\",         \"exchange\":\""+exchange+"\",         \"transaction_type\":\"S\",        \"duration\":\""+duration+"\",        \"order_type\":\""+order_type+"\",        \"quantity\":\""+tostring(quantity)+"\",        \"disclosed_quantity\":\""+disclosed_quantity+"\",        \"MktPro\":\""+MktPro+"\",        \"price\":\""+price+"\",        \"trigger_price\":\""+trigger_price+"\",        \"product\":\""+product+"\",        \"is_amo\":\""+is_amo+"\"      } }"
SSR = "{   \"api_key\":\""+api_key+"\", \"api_secret\":\""+api_secret+"\",     \"data\":      {    \"stgy_name\":\""+stgy_name+"\",         \"symbol\":\""+symbol+"\",         \"exchange\":\""+exchange+"\",         \"transaction_type\":\"S\",        \"duration\":\""+duration+"\",        \"order_type\":\""+order_type+"\",        \"quantity\":\""+tostring(quantity*2)+"\",        \"disclosed_quantity\":\""+disclosed_quantity+"\",        \"MktPro\":\""+MktPro+"\",        \"price\":\""+price+"\",        \"trigger_price\":\""+trigger_price+"\",        \"product\":\""+product+"\",        \"is_amo\":\""+is_amo+"\"      } }"

////////////////////////////////////////Block 2 Module Ends////////////////////////////////////////////////////////////////////////

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



//Plots
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)

//Backtesting Controls

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
shortCondition = sellSignal


//Block 3 : Execution Controls

if (longCondition and strategy.position_size==0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BE) //Buy Entry
if (longCondition and strategy.position_size<0)
    strategy.entry("BUY", strategy.long,qty=1, when = window(),alert_message=BSR) //Buy Stop and Reverse
if (shortCondition and strategy.position_size==0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SE) //Short Entry
if (shortCondition and strategy.position_size>0)
    strategy.entry("SELL", strategy.short,qty=1, when = window(),alert_message=SSR) //Short Stop and Reverse
    
////////////////////////////////////////Block 3 Module Ends////////////////////////////////////////////////////////////////////////
    
buy1= barssince(buySignal)
sell1 = barssince(sellSignal)
color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na
barcolor(barcoloring ? color1 : na)

Webhook Endpoint URL : Upstox

Broker - Upstox
https://upapi.algomojo.com/1.0/PlaceOrder

Supertrend Alert Configuration – Upstox

If in case you have any concerns, questions or feedback do sent your questions to support@algomojo.com

10 thoughts on “Simplified Algomojo Execution Controls for Tradingview Platform”

  1. Bhuvaneswaran K

    I have tested it in My trading system.
    I am an Upstox user.
    I could only trade with reliance, i have tried to change in setting for the other script, but Not working .
    How to apply this for other scripts also.

      1. How to I place PE exit and CE entry? Same holds good for CE exit and PE entry in single order in sequence? Also if there is no position place the respective buy orders?

        Note: I can’t edit the source code.

  2. There is no difference between BE and SX message,
    Similarly there is no difference between SE and BX message.
    How will algomojo system decide if i am placing an order or want to exit an exiting BUY/SELL order.

Leave a Comment

Your email address will not be published. Required fields are marked *