// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // @algomojo // Webhook Url : https://amapi.algomojo.com/v1/PlaceOrder // Algomojo Trading Strategy Carry Forward Strategy/Intraday Strategy with Target/Stoploss/Trailing Stoploss // Supertrend Version 3.0 // Code Date : 6th Dec 2022 // Coded by Rajandran R (Founder - Marketcalls / Co-Founder - Algomojo) //////////////////////////////////////////////////////////////////////////////////////////////////////////// //Trading Block Description //Block 1 : API Controls + Algomojo Input Controls //Block 2 : Autotrading API data configuration //Block 3 : Backtesting Controls & Target and Stoploss Controls //Block 4 : Trading Strategy and Controls (write your trading strategy in the block /////////////////////////////////////////////////////////////////////////////////////////////////////////// //@version=5 strategy('Pivot Strategy', shorttitle='Pivot Algomojo', overlay=true,process_orders_on_close=true) import algomojo/automation/22 //Block 1 : API Controls + Algomojo Input Controls //Enter Your Algomojo API Key and API Secret Key am_apikey = input.string(title='API Key', defval='xxxxx', group='AlgoControls') am_apisecret = input.string(title='API Secret Key', defval='xxxxx', group='AlgoControls') am_broker = input.string(title='Broker', defval='ALICEBLUE', options=['ALICEBLUE', 'ANGELONE', 'FIRSTOCK', 'FYERS','GOODWILL','PAYTM','SAMCO','TRADEJINI','UPSTOX','ZEBU','ZERODHA'], group='AlgoControls') am_strategy = input.string(title='Strategy Name', defval='Pivot Strategy', group='AlgoControls') am_symbol = input.string(title='Trading Symbol', defval='RELIANCE-EQ', group='AlgoControls') am_exchange = input.string(title='Exchange', defval='NSE', options=['NSE', 'NFO', 'MCX', 'BSE'], group='AlgoControls') am_quantity = input.int(title='Quantity', defval=1, group='AlgoControls') am_pricetype = input.string(title='Order Type', defval='MARKET', group='AlgoControls') am_product = input.string(title='Product', defval='MIS', options=['CNC', 'MIS', 'NRML'], group='AlgoControls') am_splitorder = input.string(title='Split Order?', defval='NO', options=['NO', 'YES'], group='AlgoControls') am_split_quantity = input.int(title='Split Quantity', defval=1, group='AlgoControls') am_Mode = input.string(title='Algo Mode', defval='ENABLE', options=['ENABLE', 'LONGONLY', 'SHORTONLY'], group='AlgoControls') ////////////////////////////////////////Block 1 Module Ends//////////////////////////////////////////////////////////////////////// //Block 2 : Autotrading API data configuration [BE,SX,BSR,SE,BX,SSR] = automation.algomodule(am_apikey, am_apisecret, am_broker, am_strategy, am_symbol, am_exchange,am_quantity, am_pricetype, am_product, am_splitorder, am_split_quantity) ////////////////////////////////////////Block 2 Module Ends//////////////////////////////////////////////////////////////////////// //Block 3 : Backtesting Controls & Live Automation Purpose FromDay = input.int(defval=1, title='From Day', minval=1, maxval=31, group='Backtesting') FromMonth = input.int(defval=1, title='From Month', minval=1, maxval=12, group='Backtesting') FromYear = input.int(defval=2018, title='From Year', minval=999, group='Backtesting') ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31, group='Backtesting') ToMonth = input.int(defval=1, title='To Month', minval=1, maxval=12, group='Backtesting') ToYear = input.int(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 ////////////////////////////////////////Block 3 Module Ends//////////////////////////////////////////////////////////////////////// //Block 4 : Trading Strategy leftBars = input(4) rightBars = input(2) swh = ta.pivothigh(leftBars, rightBars) swl = ta.pivotlow(leftBars, rightBars) swh_cond = not na(swh) hprice = 0.0 hprice := swh_cond ? swh : hprice[1] le = false le := swh_cond ? true : (le[1] and high > hprice ? false : le[1]) swl_cond = not na(swl) lprice = 0.0 lprice := swl_cond ? swl : lprice[1] se = false se := swl_cond ? true : (se[1] and low < lprice ? false : se[1]) longCondition = le shortCondition = se //Block 4 : Execution Controls if(am_Mode=="ENABLE") if longCondition and strategy.position_size == 0 and window() strategy.entry('BUY', strategy.long, alert_message=BE,stop=hprice + syminfo.mintick, comment="PivRevLE") if longCondition and strategy.position_size < 0 and window() strategy.entry('BUY', strategy.long, alert_message=BSR,stop=hprice + syminfo.mintick, comment="PivRevLE") if shortCondition and strategy.position_size == 0 and window() strategy.entry('SELL', strategy.short, alert_message=SE,stop=lprice - syminfo.mintick, comment="PivRevSE") if shortCondition and strategy.position_size > 0 and window() strategy.entry('SELL', strategy.short, alert_message=SSR,stop=lprice - syminfo.mintick, comment="PivRevSE") if(am_Mode=="LONGONLY") if longCondition and strategy.position_size == 0 and window() strategy.entry('BUY', strategy.long, alert_message=BE,stop=hprice + syminfo.mintick, comment="PivRevLE") if shortCondition and strategy.position_size > 0 and window() strategy.exit('BUY', alert_message=BX,stop=lprice - syminfo.mintick, comment="PivRevSE") if(am_Mode=="SHORTONLY") if shortCondition and strategy.position_size == 0 and window() strategy.entry('SELL', strategy.short, alert_message=SE,stop=lprice - syminfo.mintick, comment="PivRevSE") if longCondition and strategy.position_size < 0 and window() strategy.exit('SELL', alert_message=SX,stop=hprice + syminfo.mintick, comment="PivRevLE")