In this video tutorial we will demonstrate how to automate order execution of your TradingView strategy using our trading bridge. It will walkthrough the following items:
Following is the sample Pine script used in the demo for creating TradingView strategy:
// This source code is subject to the terms of use at 'Algo Trading Bridge', India. Kindly refer License Terms at https://algotradingbridge.in
// © Algo Trading Bridge, India
//@version=5
strategy('Moving Average Crossover Strategy', overlay=true, pyramiding=1, shorttitle='Moving Average Crossover Trading System')
//Objective of the Script
// 1. Trigger trade entries at Crossover of Shorter and Longer Moving Average
// 2. Strategy Orders are passed through 'comment' [le | se | sxle | lxse] to Algo Trading Bridge, India
// 3. Sample Alert Message:- {"alert_time": {{timenow}}","strategy_name": "Moving Average Crossover Trading System","exchange": "NSE","symbol": "NIFTY22JANFUT","quantity": 50,"type": "market","transaction": "{{strategy.order.comment}}","product": "margin","validity": "day"}
// 4. Sample Alert Message (LiquidBees):- {"alert_time": "{{timenow}}","strategy_name": "Live_Demo_Script","exchange": "NSE","symbol": "LIQUIDBEES-EQ","transaction": "{{strategy.order.comment}}","type": "market","quantity": 1,"product": "cnc","validity": "day"}
//Shorter Moving Average
short_MA_length = input.int(21, title='Shorter MA Length')
short_MA = ta.sma(close, short_MA_length)
//Longer Moving Average
long_MA_length = input.int(89, title='Longer MA Length')
long_MA = ta.sma(close, long_MA_length)
//Plotting Moving Averages
plot(short_MA, title='Short MA', linewidth=1, color=color.new(color.orange, 10))
plot(long_MA, title='Long MA', linewidth=1, color=color.new(color.navy, 10))
//System's Trading Logic
long_Condition = ta.crossover(short_MA, long_MA)
short_Condition = ta.crossunder(short_MA, long_MA)
//Strategy Orders submission to Algo Trading Bridge, India
//Long Entry (LE) - Creating a Long Position without having any prior positions
if long_Condition and strategy.position_size == 0
strategy.entry('L', strategy.long, comment='le', qty=1)
//Short Entry (SE) - Creating a Short Position without having any prior positions
if short_Condition and strategy.position_size == 0
strategy.entry('S', strategy.short, comment='se', qty=1)
//Reverse Short Position (SXLE) - Exit open Short Position and create a new Long Position
if long_Condition and strategy.position_size != 0
strategy.entry('L', strategy.long, comment='sxle', qty=1)
//Reverse Long Position (LXSE) - Exit open Long Position and create a new Short Position
if short_Condition and strategy.position_size != 0
strategy.entry('S', strategy.short, comment='lxse', qty=1)