AlgoFox MultiTF SuperTrend v1.5 — Strategy by singhruma1199

By version

Performance Metrics

Description

// This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/// © Algofox//version=5strategy("AlgoFox MultiTF SuperTrend v1.5", shorttitle="AlgoFox MultiTF SuperTrend", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1, initial_capital=300000, currency=currency.NONE, commission_value=0, commission_type=strategy.commission.percent, process_orders_on_close=false, calc_on_every_tick=true, calc_on_order_fills=true)////======================================================paraTradeMode = input.string(title='Trade Mode', defval='Both', options=['Both', 'LongOnly', 'ShortOnly'], group = "Trade Settings")paraSystemMode = input.session(defval="Intraday", title="System Mode", options=["Intraday", "Positional"], group = "Trade Settings")s = input.session(title='Intraday Start Session:', defval='0915-1445', group='Trade Settings')e = input.session(title='Intraday End Session:', defval='1500-1515', group='Trade Settings')paraSTmultiplier = input.float(3, title="ST Multiplier", minval=1)paraSTperiods = input.int(10, title="ST Periods", minval = 1)paraHeikinAshiMode = input.bool(false, "Consider Heikin Ashi Candles ?")paraSTMutliTF = "On" //input.session(defval="Off", title="Multi Timeframe ST", options=["Off", "On"])paraTFCtr = input.int(defval=1, title="No. of Timeframe(s)", minval=1, maxval=4)paraTF1 = input.timeframe(defval="15", title="Timeframe 1")paraTF2 = input.timeframe(defval="30", title="Timeframe 2")paraTF3 = input.timeframe(defval="60", title="Timeframe 3")paraTF4 = input.timeframe(defval="D", title="Timeframe 4")paraTGTMode = input.string(defval="%", title="Target : ", options=["Off", "%", "Pts"], inline = "TGT", group = "Target Settings")paraTGT1 = input.float(1, "T1 : ", minval = 0, inline = "TGT", group = "Target Settings")paraTGT = input.float(2, "T2 : ", minval = 0.1, inline = "TGT", group = "Target Settings")paraSLMode = input.string(defval="%", title="Stoploss : ", options=["Off", "%", "Pts"], inline = "SL", group = "Stoploss Settings")paraSL = input.float(1, "Value : ", minval = 0.1, inline = "SL", group = "Stoploss Settings")paraTSLMode = input.string(defval="%", title="Trail SL : ", options=["Off", "%", "Pts"], inline = "TSL", group = "TSL Settings")paraTSL = input.float(1, "Value : ", minval = 0.1, inline = "TSL", group = "TSL Settings")paraShowDashboard = input.bool(true, "Show Strategy Dashboard")////======================================================////======================================================grpAlgo = "Algo Setup"paraExchange = input.string(title='Exchange', defval='delta', group=grpAlgo)paraCode = input.string(title='Code', defval='XXXXXX', group=grpAlgo)paraQtyType = input.string(title="Quantity Type", defval='Fixed',options=['Fixed','Exposure'], group=grpAlgo)paraQty = input.float(title='Quantity ', defval=1, minval=0, group=grpAlgo, tooltip='Qty in Lots for Futures')paraT1Qty = input.float(title='Target-1 Exit Qty (%)', defval=0, minval=0, maxval = 100, group=grpAlgo, tooltip='Qty in Percentage')paraMaxProfit = input.int(0, "Max Profit Per Trade", 0, group=grpAlgo, tooltip='Exit on Max. Profit in Rs.')paraMaxLoss = input.int(0, "Max Loss Per Trade", 0, group=grpAlgo, tooltip='Exit on Max. Loss in Rs.')////======================================================////======================================================haTicker = syminfo.tickeridif (paraHeikinAshiMode) haTicker := ticker.heikinashi(syminfo.tickerid)GetSuperTrend(isLocal) => [_SuperTrend, _STTrend] = ta.supertrend(paraSTmultiplier, paraSTperiods) resultST = _SuperTrend resiltDir = _STTrend // if (not isLocal) // resultST := _SuperTrend[1] // resiltDir := _STTrend[1] [resultST, resiltDir]////======================================================////======================================================st = paraSystemMode=="Positional" ? true : not na(time(timeframe.period, s))et = paraSystemMode=="Positional" ? false : not na(time(timeframe.period, e))//[SuperTrend, STTrend] = request.security(haTicker, timeframe.period, GetSuperTrend(true), lookahead=barmerge.lookahead_off) [SuperTrend1, STTrend1] = request.security(haTicker, paraTF1, GetSuperTrend(false), lookahead=barmerge.lookahead_off)[SuperTrend2, STTrend2] = request.security(haTicker, paraTF2, GetSuperTrend(false), lookahead=barmerge.lookahead_off)[SuperTrend3, STTrend3] = request.security(haTicker, paraTF3, GetSuperTrend(false), lookahead=barmerge.lookahead_off)[SuperTrend4, STTrend4] = request.security(haTicker, paraTF4, GetSuperTrend(false), lookahead=barmerge.lookahead_off)ST1Long = (paraSTMutliTF=="On" and paraTFCtr >= 1) ? STTrend1==-1 : trueST1Short = (paraSTMutliTF=="On" and paraTFCtr >= 1) ? STTrend1==1 : trueST1LongExit = (paraSTMutliTF=="On" and paraTFCtr >= 1) ? STTrend1==1 : falseST1ShortExit = (paraSTMutliTF=="On" and paraTFCtr >= 1) ? STTrend1==-1 : falseST2Long = (paraSTMutliTF=="On" and paraTFCtr >= 2) ? STTrend2==-1 : trueST2Short = (paraSTMutliTF=="On" and paraTFCtr >= 2) ? STTrend2==1 : trueST2LongExit = (paraSTMutliTF=="On" and paraTFCtr >= 2) ? STTrend2==1 : falseST2ShortExit = (paraSTMutliTF=="On" and paraTFCtr >= 2) ? STTrend2==-1 : falseST3Long = (paraSTMutliTF=="On" and paraTFCtr >= 3) ? STTrend3==-1 : trueST3Short = (paraSTMutliTF=="On" and paraTFCtr >= 3) ? STTrend3==1 : trueST3LongExit = (paraSTMutliTF=="On" and paraTFCtr >= 3) ? STTrend3==1 : falseST3ShortExit = (paraSTMutliTF=="On" and paraTFCtr >= 3) ? STTrend3==-1 : falseST4Long = (paraSTMutliTF=="On" and paraTFCtr >= 4) ? STTrend4==-1 : trueST4Short = (paraSTMutliTF=="On" and paraTFCtr >= 4) ? STTrend4==1 : trueST4LongExit = (paraSTMutliTF=="On" and paraTFCtr >= 4) ? STTrend4==1 : falseST4ShortExit = (paraSTMutliTF=="On" and paraTFCtr >= 4) ? STTrend4==-1 : falseeSignal = 0eBuy = ST1Long and ST2Long and ST3Long and ST4Long //STTrend==-1 and eShort = ST1Short and ST2Short and ST3Short and ST4Short //STTrend==1 and eSell = eShort or ST1LongExit or ST2LongExit or ST3LongExit or ST4LongExit //or STTrend==1 eCover = eBuy or ST1ShortExit or ST2ShortExit or ST3ShortExit or ST4ShortExit //or STTrend==-1 eSignal := eBuy ? 1 : eShort ? -1 : eSell or eCover ? 0 : eSignal[1]MainSignal = 0BuySignal = paraTradeMode!="ShortOnly" and st and eBuy and barstate.isconfirmed and (nz(MainSignal[1]) = 0)SellSignal = (((ShortSignal or eSell) and barstate.isconfirmed) or et) and (nz(MainSignal[1]) == 1)CoverSignal = (((BuySignal or eCover) and barstate.isconfirmed) or et) and (nz(MainSignal[1]) == -1)MainSignal := BuySignal ? 1 : ShortSignal ? -1 : ((SellSignal and MainSignal[1] > 0) or strategy.position_size == 0) ? 0 : ((CoverSignal and MainSignal[1] 0 strategy.entry('SHORT', strategy.short, comment='Short', qty=ShortTradeQty, alert_message="["+sellData+","+shortData+"]")else if ShortSignal and strategy.position_size == 0 strategy.entry('SHORT', strategy.short, comment='Short', qty=ShortTradeQty, alert_message="["+shortData+"]")var float BuyPrice = navar float ShortPrice = navar float BuyTGT = navar float ShortTGT = navar float BuyTGT1 = navar float ShortTGT1 = navar float BuySL = navar float ShortSL = navar float BuyTSL = navar float ShortTSL = naut = (paraTGTMode != "Off")us = (paraSLMode != "Off")if (strategy.position_size > 0 and strategy.position_size[1] = 0) ShortPrice := strategy.position_avg_price if (paraSLMode=="%") ShortSL := ShortPrice * (1+(paraSL/100)) else if (paraSLMode=="Pts") ShortSL := ShortPrice + (paraSL) if (paraTGTMode=="%") ShortTGT1 := ShortPrice * (1-(paraTGT1/100)) ShortTGT := ShortPrice * (1-(paraTGT/100)) else if (paraTGTMode=="Pts") ShortTGT1 := ShortPrice - (paraTGT1) ShortTGT := ShortPrice - (paraTGT)if (paraTSLMode != "Off") if (strategy.position_size > 0 and strategy.position_size[1] > 0) if (paraTSLMode=="%") BuyTSL := high[1] * (1-(paraTSL/100)) else BuyTSL := high[1] - paraTSL if (BuySL ShortTSL) ShortSL := ShortTSLif (paraMaxProfit > 0) if (strategy.position_size > 0 and strategy.opentrades.profit(strategy.opentrades - 1) >= paraMaxProfit) strategy.close("BUY", immediately = true, alert_message="["+sellData+"]") if (strategy.position_size = paraMaxProfit) strategy.close("SHORT", immediately = true, alert_message="["+coverData+"]")if (paraMaxLoss > 0) if (strategy.position_size > 0 and strategy.opentrades.profit(strategy.opentrades - 1) 0) if (paraT1Qty > 0 and paraTGT1 > 0) strategy.exit(id="LongT1Exit", from_entry="BUY", qty = T1ExQty, limit=BuyTGT1, comment="TPSell", alert_message="["+TPsellData+"]", oca_name = "LX1") strategy.exit(id='LongExit', comment="Sell", from_entry='BUY', limit=BuyTGT, alert_message="["+sellData+"]") if (strategy.position_size 0 and paraTGT1 > 0) strategy.exit(id="ShortT1Exit", from_entry="SHORT", qty = T1ExQty, limit=ShortTGT1, comment="TPCover", alert_message="["+TPcoverData+"]", oca_name = "SX1") strategy.exit(id='ShortExit', comment="Cover", from_entry='SHORT', limit=ShortTGT, alert_message="["+coverData+"]")if us == true and ut == false if (strategy.position_size > 0) strategy.exit(id='LongExit', comment="Sell", from_entry='BUY', stop=BuySL, alert_message="["+sellData+"]") if (strategy.position_size 0) if (paraT1Qty > 0 and paraTGT1 > 0) strategy.exit(id="LongT1Exit", from_entry="BUY", qty = T1ExQty, limit=BuyTGT1, stop=BuySL, comment="TPSell", alert_message="["+TPsellData+"]", oca_name = "LX1") strategy.exit(id='LongExit', comment="Sell", from_entry='BUY', limit=BuyTGT, stop=BuySL, alert_message="["+sellData+"]") if (strategy.position_size 0 and paraTGT1 > 0) strategy.exit(id="ShortT1Exit", from_entry="SHORT", qty = T1ExQty, limit=ShortTGT1, stop=ShortSL, comment="TPCover", alert_message="["+TPcoverData+"]", oca_name = "SX1") strategy.exit(id='ShortExit', comment="Cover", from_entry='SHORT', limit=ShortTGT, stop=ShortSL, alert_message="["+coverData+"]")if (et or (SellSignal and (not ShortSignal))) and strategy.position_size > 0 strategy.cancel('LongExit') strategy.cancel('LongT1Exit') strategy.close(id='BUY', comment="Sell", alert_message="["+sellData+"]")if (et or (CoverSignal and (not BuySignal))) and strategy.position_size = 0) strategy.cancel('ShortExit') strategy.cancel('ShortT1Exit')////======================================================////======================================================//plot(SuperTrend, color=(STTrend==-1?color.green:STTrend==1?color.red:color.yellow))plot(paraSTMutliTF=="On" and paraTFCtr >= 1 ? SuperTrend1 : na, color=(STTrend1==-1?color.green:STTrend1==1?color.red:color.yellow))plot(paraSTMutliTF=="On" and paraTFCtr >= 2 ? SuperTrend2 : na, color=(STTrend2==-1?color.green:STTrend2==1?color.red:color.yellow))plot(paraSTMutliTF=="On" and paraTFCtr >= 3 ? SuperTrend3 : na, color=(STTrend3==-1?color.green:STTrend3==1?color.red:color.yellow))plot(paraSTMutliTF=="On" and paraTFCtr >= 4 ? SuperTrend4 : na, color=(STTrend4==-1?color.green:STTrend4==1?color.red:color.yellow))//plotshape(BuySignal, style=shape.triangleup , location=location.belowbar, color=color.green, size=size.normal)//plotshape(ShortSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.normal)//plotshape(strategy.position_size>0?SellSignal:na, style=shape.triangledown , location=location.abovebar, color=color.green, size=size.small)//plotshape(strategy.position_size 0)?BuyPrice:na, color=color.fuchsia, linewidth=1, style=plot.style_linebr)plot((strategy.position_size > 0) and paraTGT1?BuyTGT1:na, color=color.blue, linewidth=1, style=plot.style_linebr)plot((strategy.position_size > 0)?BuyTGT:na, color=color.blue, linewidth=1, style=plot.style_linebr)plot((strategy.position_size > 0)?BuySL:na, color=color.orange, linewidth=1, style=plot.style_linebr)plot((strategy.position_size = 0 ? cell_up : cell_dnlastProfitColor = lastProfit >= 0 ? cell_up : cell_dnrowCtr = 0colCtr = 0if (barstate.islast and paraShowDashboard) table.cell(dashtable, 0, rowCtr, "AlgoFox Dashboard", text_color=txt_col, text_size=table_text_size, bgcolor=color.new(color.blue,80), tooltip="") table.cell(dashtable, 1, rowCtr, '', text_color=txt_col, text_size=table_text_size, bgcolor=color.new(color.blue,80), tooltip="") table.merge_cells(dashtable, 0, 0, 1, 0) if strategy.position_size > 0 rowCtr += 1 table.cell(dashtable, 0, rowCtr, "Buy",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="") table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_avg_price, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="") rowCtr += 1 table.cell(dashtable, 0, rowCtr, "Qty.",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="") table.cell(dashtable, 1, rowCtr, str.tostring(strategy.position_size, "#"),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="") if (stgTGTFlag) rowCtr += 1 table.cell(dashtable, 0, rowCtr, "TGT",text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="") if (BuyTGT1) table.cell(dashtable, 1, rowCtr, str.tostring(BuyTGT1, format.mintick) + "/"+ str.tostring(BuyTGT, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="") else table.cell(dashtable, 1, rowCtr, str.tostring(BuyTGT, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_up,tooltip="") if (stgSLFlag) rowCtr += 1 table.cell(dashtable, 0, rowCtr, "SL",text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="") table.cell(dashtable, 1, rowCtr, str.tostring(BuySL, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=cell_dn,tooltip="") rowCtr += 1 table.cell(dashtable, 0, rowCtr, "P&L",text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip="") table.cell(dashtable, 1, rowCtr, str.tostring(openProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=openProfitColor,tooltip="") if strategy.position_size 0 rowCtr += 1 table.cell(dashtable, 0, rowCtr, "Exit Buy",text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="") table.cell(dashtable, 1, rowCtr, str.tostring(lastProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="") else if strategy.position_size >= 0 and strategy.position_size[1] < 0 rowCtr += 1 table.cell(dashtable, 0, rowCtr, "Exit Short",text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="") table.cell(dashtable, 1, rowCtr, str.tostring(lastProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="") else rowCtr += 1 table.cell(dashtable, 0, rowCtr, "Last P&L",text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="") table.cell(dashtable, 1, rowCtr, str.tostring(lastProfit, format.mintick),text_color=txt_col,text_size=table_text_size,bgcolor=lastProfitColor,tooltip="")////======================================================

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView