//@version=4 //Supertrend Strategy by breizh29 using *rajandran.r* Supertrend Indicator //modified my mycoder to set alerts for api bridge strategy("Super Trend 2 MACD", overlay=true) // MACD input source = input(close) fastLength = input(12, minval=1, title="MACD fast moving average") slowLength=input(26,minval=1, title="MACD slow moving average") signalLength=input(9,minval=1, title="MACD signal line moving average") // Calculation fastMA = sma(source, fastLength) slowMA = sma(source, slowLength) Macd = fastMA - slowMA Signal = sma(Macd, signalLength) //res = input(title="Main SuperTrend Time Frame", type=resolution, defval="120") Factor=input(1, minval=1,maxval = 100) Pd=input(1, minval=1,maxval = 100) tp1 = input(500,title="Take Profit in Points") sl1 = input(400,title="Stop Loss in Points") tp=tp1/syminfo.mintick sl=sl1/syminfo.mintick Up=hl2-(Factor*atr(Pd)) Dn=hl2+(Factor*atr(Pd)) MUp=hl2-(Factor*atr(Pd)) MDn=hl2+(Factor*atr(Pd)) Mclose=close float TrendUp=na TrendUp:=TrendUp[1] float TrendDown=na TrendDown:=TrendDown[1] TrendUp:=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up TrendDown:=close[1]MTrendUp[1]? max(MUp,MTrendUp[1]) : MUp MTrendDown:=Mclose[1] TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1) Tsl = Trend==1? TrendUp: TrendDown float MTrend=na MTrend:=MTrend[1] MTrend := Mclose > MTrendDown[1] ? 1: Mclose< MTrendUp[1]? -1: nz(MTrend[1],1) MTsl = MTrend==1? MTrendUp: MTrendDown linecolor = Trend == 1 ? color.green : color.red plot(Tsl, color = linecolor , style = plot.style_line , linewidth = 2,title = "SuperTrend") Mlinecolor = MTrend == 1 ? color.blue : color.orange plot(MTsl, color = Mlinecolor , style = plot.style_line , linewidth = 2,title = "Main SuperTrend") //plotshape(cross(close,Tsl) and close>Tsl , "Up Arrow", shape.triangleup,location.belowbar,color.green,0,1) //plotshape(cross(Tsl,close) and close Signal goshort = Trend == -1 and Trend[1] == 1 and MTrend == -1 and Macd < Signal s=input(title="INTRA DAY TRADE SESSION",type=input.session,defval="0915-1450") st=time(timeframe.period,s) e=input(title="END SESSION",type=input.session,defval="1500-1530") et=time(timeframe.period,e) quant=input(title="Trade Quantity",defval=25) lxse="TYPE: LX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) sxle="TYPE: SX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) le="TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) lx="TYPE:LX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) se="TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) sx="TYPE:SX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) if(golong and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(goshort and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(golong and st and strategy.position_size!=0) strategy.entry("BUY",strategy.long,comment=sxle) if(goshort and st and strategy.position_size!=0) strategy.entry("SELL",strategy.short,comment=lxse) strategy.exit("Close Buy","BUY",profit=tp,loss=sl,comment=lx) strategy.exit("Close Sell","SELL",profit=tp,loss=sl,comment=lx) strategy.close(id="BUY",when=et,comment=lx) strategy.close(id="SELL",when=et,comment=sx)