// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © VEMO0020 //@version=5 strategy('Algobaba Super Trend Strategy-V5', overlay=true) // <> atrPeriod = input(10, "ATR Length") factor = input.float(2.0, "Factor", step = 0.01) [supertrend, direction] = ta.supertrend(factor, atrPeriod) bodyMiddle = plot((open + close) / 2, display=display.none) upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr) downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr) fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false) fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false) //************ //Algobaba Integration START //Declare your Buy and Sell conditions don't change the variable name //************ buySignal = ta.change(direction) < 0 and close > supertrend and barstate.isconfirmed sellSignal = ta.change(direction) > 0 and close < supertrend and barstate.isconfirmed bsym = syminfo.ticker // SETTING UP VARIABLES // tlg = input.bool(defval=true, title='Long ', inline='tdir', group='Trade Setup:') tst = input.bool(defval=false, title='Short <<||>> Trade in: ', inline='tdir', group='Trade Setup:') tt1 = input.bool(defval=true, title='Futures ', inline='tdir', group='Trade Setup:') tt2 = input.bool(defval=false, title='Options ', inline='tdir', group='Trade Setup:') otype = tt2 ? 'Options' : 'Futures' ow = input.bool(defval=false, title='Sell Options...?', inline='Sellopt', group='Trade Setup:',tooltip='Tick this if you are an Option Seller.') stag = input.string(title='Strategy Type:', defval='BNOPTIONS', inline='hpar2', group='Trade Setup:') qty = input.int(title='Quantity:', defval=1, minval=1, inline='hpar2', group='Trade Setup:', tooltip='Qty in Lots for Futures') //trade_side = tst?"Short":"Long" trade_side = tlg and tst ? 'Both' : tlg ? 'Long' : 'Short' opt1 = input.bool(defval=false, title='ITM ', inline='stype', group='Strike Type:') opt2 = input.bool(defval=true, title='ATM ', inline='stype', group='Strike Type:') opt3 = input.bool(defval=false, title='OTM ', inline='stype', group='Strike Type:') stype = opt3 ? 'OTM' : opt1 ? 'ITM' : 'ATM' // ***** // Derive Option strike price based on user selection // ***** csym = otype == 'Futures' ? bsym : bsym + stype + 'CE' psym = otype == 'Futures' ? bsym : bsym + stype + 'PE' lx = (otype =='Futures'?'TYPE: LX :SYMBOL:'+csym : ow ? 'TYPE: SX :SYMBOL:'+psym : 'TYPE: LX :SYMBOL:'+ csym) +':QTY:' + str.tostring(qty) + ':STAG:' + stag //NIFTYCALL sx = (otype =='Futures'?'TYPE: SX :SYMBOL:'+psym : ow ? 'TYPE: SX :SYMBOL:'+csym : 'TYPE: LX :SYMBOL:'+ psym) + ':QTY:' + str.tostring(qty) + ':STAG:' + stag //NIFTYPUT le = (otype =='Futures'?'TYPE: LE :SYMBOL:'+csym : ow ? 'TYPE: SE :SYMBOL:'+psym : 'TYPE: LE :SYMBOL:'+ csym) + ':QTY:' + str.tostring(qty) + ':STAG:' + stag //NIFTYCALL se = (otype =='Futures'?'TYPE: SE :SYMBOL:'+psym : ow ? 'TYPE: SE :SYMBOL:'+csym : 'TYPE: LE :SYMBOL:'+ psym) + ':QTY:' + str.tostring(qty) + ':STAG:' + stag //NIFTYPUT // ****** // Adding Stoploss and Target selection // ****** ut = input.bool(defval=true, title='', inline='sltgtpts', group='Define SL & TGT in Points:') tar1 = input.float(defval=10.0, title='Target:', inline='sltgtpts', group='Define SL & TGT in Points:') us = input.bool(defval=true, title='', inline='sltgtpts', group='Define SL & TGT in Points:') stop1 = input.float(defval=5.0, title='Stop Loss:', inline='sltgtpts', group='Define SL & TGT in Points:') tar = tar1 / syminfo.mintick stop = stop1 / syminfo.mintick symbol = syminfo.ticker // ****** // INTRA DAY TRADE SESSION Initialization // ****** s = input.session(title='Start Session:', defval='0915-1515', group='Intraday Session') st = time(timeframe.period, s) e = input.session(title='End Session:', defval='1515-1530', group='Intraday Session') et = time(timeframe.period, e) // ****** // ***** // Algobaba ORDER Placement Section //for long entry conditions store in buySignal variable and for short entry store in sellSignal variables // ***** //Initiate Long Buy Order and otype=="CE" buycond = buySignal and st and (otype == 'Options' and (trade_side == 'Long' or trade_side == 'Both') or otype == 'Futures' and (trade_side == 'Long' or trade_side == 'Both')) //Initiate Short Buy Order and otype=="PE" sellcond = sellSignal and st and (otype == 'Options' and (trade_side == 'Short' or trade_side == 'Both') or otype == 'Futures' and (trade_side == 'Short' or trade_side == 'Both')) // *************** // Send signals to IAB based on user selection // *************** // BUY or SELL when condtions are met and within the Intraday Trading session and backtesting date and time if buycond and strategy.position_size < 0 strategy.entry('BUY', strategy.long, qty=qty, when=st, comment=sx + ';' + le) if buycond and strategy.position_size == 0 strategy.entry('BUY', strategy.long, qty=qty, when=st, comment=le) if sellcond and strategy.position_size > 0 strategy.entry('SELL', strategy.short, qty=qty, when=st, comment=lx + ';' + se) if sellcond and strategy.position_size == 0 strategy.entry('SELL', strategy.short, qty=qty, when=st, comment=se) //Send Exit signals to IAB for the open position if Target or Stop loss hit on BANKNIFTY Future price if ut == true and us == false strategy.exit(id='LongExit', from_entry='BUY', profit=tar, comment=lx) strategy.exit(id='ShortExit', from_entry='SELL', profit=tar, comment=sx) if us == true and ut == false strategy.exit(id='LongExit', from_entry='BUY', loss=stop, comment=lx) strategy.exit(id='ShortExit', from_entry='SELL', loss=stop, comment=sx) if ut == true and us == true strategy.exit(id='LongExit', from_entry='BUY', profit=tar, loss=stop, comment=lx) strategy.exit(id='ShortExit', from_entry='SELL', profit=tar, loss=stop, comment=sx) // *************** //ADDING SQUAREOFF TIME or Manul close all open positions // *************** strategy.close(id='BUY', when=et, comment=lx) strategy.close(id='SELL', when=et, comment=sx) // for order execution using Alerts in alert window use {{strategy.order.comment}} //ALGOBABA INTEGRATION END