// 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('Kase Dev Stops V1 Strategy', shorttitle='Kase Dev Stops V1 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='Kase Dev Stops V1 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 //inputs Length = input.int(20,minval=1,maxval=100,title='length') //RWIHi and RWILo RWIHi = (high-low[Length]) / (ta.atr(Length) * math.sqrt(Length)) RWILo = (high[Length]-low) / (ta.atr(Length) * math.sqrt(Length)) diff = ta.wma(RWIHi-RWILo,3) //smoothing the difference between hi and lo value of RWI //plot(diff,'diff',linewidth=2,style=plot.style_histogram) avtr = ta.sma(ta.highest(high,2) - ta.lowest(low,2), Length) sd = ta.stdev(ta.highest(high,2) - ta.lowest(low,2), Length) //level 4 highest_0 = ta.highest(high-avtr - 0*sd,20) lowest_0 = ta.lowest(low+avtr + 0*sd,20) value0 = diff > 0 ? highest_0 : lowest_0 //level 3 highest_1 = ta.highest(high-avtr - 1*sd,20) lowest_1 = ta.lowest(low+avtr + 1*sd,20) value1 = diff > 0 ? highest_1 : lowest_1 //level 2 highest_2 = ta.highest(high-avtr - 2*sd,20) lowest_2 = ta.lowest(low+avtr + 2*sd,20) value2 = diff > 0 ? highest_2 : lowest_2 //level 1 highest_3 = ta.highest(high-avtr - 3*sd,20) lowest_3 = ta.lowest(low+avtr + 3*sd,20) value3 = diff > 0 ? highest_3 : lowest_3 icolor = diff > 0 ? color.green : color.red plot(value3,color=icolor,style=plot.style_line,linewidth=2) plot(value2,color=icolor,style=plot.style_circles,linewidth=2) plot(value1,color=icolor,style=plot.style_circles,linewidth=2) plot(value0,color=icolor,style=plot.style_circles,linewidth=2) buy = diff > 0 and close > value0 sell = (diff<0 and close < value0) or (diff >0 and close < value3) short = (diff<0 and close < value0) cover = (diff > 0 and close > value0) or (diff < 0 and close > value3) barcolor(color=icolor) //Fresh Long Entry if buy and not cover and strategy.position_size == 0 and window() strategy.entry('buy',strategy.long,comment='BUY',alert_message=BE) if buy and cover and strategy.position_size == 0 and window() strategy.entry('buy',strategy.long,comment='BUY',alert_message=BE) //Stop and Reverse to Buy if buy and cover and strategy.position_size < 0 and window() strategy.entry('buy',strategy.long,comment='BUY',alert_message=BSR) //Long Exit if sell and not short and strategy.position_size > 0 and window() strategy.close('buy',comment='SELL',alert_message=BX) //Fresh Short Entry if short and not sell and strategy.position_size == 0 and window() strategy.entry('short',strategy.short,comment='SHORT',alert_message=SE) if short and sell and strategy.position_size == 0 and window() strategy.entry('short',strategy.short,comment='SHORT',alert_message=SE) //Stop and Reverse to Buy if short and sell and strategy.position_size > 0 and window() strategy.entry('short',strategy.short,comment='SHORT',alert_message=SSR) //Short Exit if cover and not buy and strategy.position_size > 0 and window() strategy.close('short',comment='COVER',alert_message=SX)