//@version=4 strategy("MA Cross - MTF", shorttitle="MA-X", overlay=true) // Original idea by ChartArt, updated by AlphaBet_ // Updates // - Converted to v4 // - Made some graphical changes and provided more control over plots // - Added RMA and VWMA // - Added alerts // Updates v1.1 // - Resolved issue where old script was not calculating the higher TFs correctly // - This fix causes the Ribbon Fill color to break, you can disable the Ribbon Fill if this bothers you. // - Slow MA color now changes to orange when Ribbon Fill is disabled. // - Added more alert options and fixed an issue where not all crosses generated alerts. // ═══════════════════════════════════ COLOURS ════════════════════════════════════════════════════════ // lime0 = color.new(#00FF00,0), lime50 = color.new(#00FF00,50), lime85 = color.new(#00FF00,85), lime95 = color.new(#00FF00,95) green0 = color.new(#008000,0), green85 = color.new(#008000,85), green95 = color.new(#008000,95) red0 = color.new(#ff0000,0), red50 = color.new(#ff0000,50), red85 = color.new(#ff0000,85), red95 = color.new(#ff0000,95) silver50 = color.new(#c0c0c0,50), yellow0 = color.new(#ffff00,0), orange0 = color.new(#ffa500,0), orange50 = color.new(#ffa500,50), // ═══════════════════════════════════ GLOBAL CONFIG ══════════════════════════════════════════════════ // ma1 = "SMA", ma2 = "EMA", ma3 = "WMA", ma4 = "Linear", ma5 = "RMA", ma6 = "VWMA" // ═══════════════════════════════════ Display display = input("══", "══ Display ══", options=["══"]) sMAs = input(true, "Show MAs?"), sRibFill = input(true, "Fill Ribbon?"), sBarCol = input(true, "Bar Color?"), smaX = input(true, "Show MA Cross?"), smaXbg = input(true,"Show MA Cross BG?"), sLS = input(true, "Show Alerts?") // ═══════════════════════════════════ MTF & MA INPUT ══════════════════════════════════════════════════ // mtfMA = input("══", "══ MA & MTF ══", options=["══"]) fMA = input(11, "Fast MA"), sMA = input(21, "Slow MA") pSrc = input(close, "MA Source"), offset = input(0, "Offset", type=input.integer, minval=-500, maxval=500) // ═══════════════════════════════════ MA Calculation maType = input(ma2, "MA Type", options=[ma1, ma2, ma3, ma4, ma5, ma6]) sma_1 = sma(pSrc, fMA), ema_1 = ema(pSrc, fMA), wma_1 = wma(pSrc, fMA), linreg_1 = linreg(pSrc, fMA, 0), rma_1 = rma(pSrc, fMA), vwma_1 = vwma(pSrc, fMA) sma_2 = sma(pSrc, sMA), ema_2 = ema(pSrc, sMA), wma_2 = wma(pSrc, sMA), linreg_2 = linreg(pSrc, sMA, 0), rma_2 = rma(pSrc, sMA), vwma_2 = vwma(pSrc, sMA) fMASel = maType == "SMA" ? sma_1 : maType == "EMA" ? ema_1 : maType == "WMA" ? wma_1 : maType == "Linear" ? linreg_1 : maType == "RMA" ? rma_1 : maType == "VWMA" ? vwma_1 : na sMASel = maType == "SMA" ? sma_2 : maType == "EMA" ? ema_2 : maType == "WMA" ? wma_2 : maType == "Linear" ? linreg_2 : maType == "RMA" ? rma_2 : maType == "VWMA" ? vwma_2 : na // ═══════════════════════════════════ MA Trend Direction Colour fMAcol = fMASel > fMASel[1] and sMAs ? lime0 : fMASel < fMASel[1] and sMAs ? red50 : na mMAcol = sMASel > sMASel[1] and sMAs ? orange50 : sMASel < sMASel[1] and sMAs ? orange0 : na sMAcol = sMASel > sMASel[1] and sMAs and sRibFill ? lime50 : sMASel < sMASel[1] and sMAs and sRibFill ? red0 : mMAcol // ═══════════════════════════════════ MA Plots ══════════════════════════════════════════════════════ // MA1 = plot(fMASel, "Fast MA", fMAcol, 1, plot.style_line, join=true, transp=100) MA2 = plot(sMASel, "Mid MA", sMAcol, 1, plot.style_line, join=true, transp=100) maFill = fMASel > sMASel[1] and sRibFill ? lime85 : fMASel < sMASel[1] and sRibFill ? red85 : na fill(MA1, MA2, maFill, title= "MA Fill") // ═══════════════════════════════════ MA Trend Based Bar Colour TrendingUp() => fMASel > sMASel TrendingDown() => fMASel < sMASel TrendingDown_1 = TrendingDown() barcolor(TrendingUp() and sBarCol ? green0 : TrendingDown_1 and sBarCol ? red0 : na) // ═══════════════════════════════════ MA Cross maX = cross(fMASel, sMASel) and smaX ? fMASel : na plot(maX, "MA Cross", yellow0, 3, plot.style_cross) // ═══════════════════════════════════ MA Cross Background Color Alert Uptrend() => TrendingUp() and TrendingDown()[1] Downtrend() => TrendingDown() and TrendingUp()[1] Downtrend_1 = Downtrend() bgcolor(Uptrend() and smaXbg? green95 : Downtrend_1 and smaXbg ? red95 : na, title = "Background Color") // ═══════════════════════════════════ Long, Short & Cross Alerts Long = Uptrend(), Short = Downtrend(), Cross = Long or Short xLong = crossunder(close, sMASel), xShort = crossover(close, sMASel) plotshape(Long and sLS, "Long", shape.triangleup, location.bottom, lime50, size=size.small) plotshape(Short and sLS, "Short", shape.triangledown, location.top, red50, size=size.small) // ═══════════════════════════════════ ALERTS ══════════════════════════════════════════════════════ // alertcondition(Long, "Long", "Possible Long Entry") alertcondition(Short, "Short", "Possible Short Entry") //alertcondition(Cross, "Any MA Cross", "MA Cross") alertcondition(xLong, "Long Exit", "Possible Long Exit") alertcondition(xShort, "Short Exit", "Possible Short Exit") // ═══════════════════════════════════ Intraday AlgoJi ══════════════════════════════════════════════════════ // 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="1515-1520") et=time(timeframe.period,e) quant=input(title="Trade Quantity",defval=1) //AlgoJi adding stoploss and target option ut=input(defval=false,title="USE TARGET") us=input(defval=false,title="USE STOPLOSS") tar=input(defval=10.0,title="TARGET IN RS") stop=input(defval=7.0,title="STOP LOSS IN RS") tar:=tar/syminfo.mintick stop:=stop/syminfo.mintick //setting automated alerts required by apibridge 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(Long and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(Short and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(Long and st and strategy.position_size!=0) strategy.entry("BUY",strategy.long,comment=sxle) if(Short and st and strategy.position_size!=0) strategy.entry("SELL",strategy.short,comment=lxse) //======================================================================= if(Long and st and strategy.position_size!=0) strategy.close(id="BUY",when=xLong,comment=lx) if(Short and st and strategy.position_size!=0) strategy.close(id="SELL",when=xShort,comment=sx) //======================================================================== if(ut==true and us==false) strategy.exit(id="LX",from_entry="BUY",profit=tar,comment=lx) strategy.exit(id="SX",from_entry="SELL",profit=tar,comment=sx) if(us==true and ut==false) strategy.exit(id="LX",from_entry="BUY",loss=stop,comment=lx) strategy.exit(id="SX",from_entry="SELL",loss=stop,comment=sx) if(ut==true and us==true) strategy.exit(id="LX",from_entry="BUY",profit=tar,loss=stop,comment=lx) strategy.exit(id="SX",from_entry="SELL",profit=tar,loss=stop,comment=sx) strategy.close(id="BUY",when=et,comment=lx) strategy.close(id="SELL",when=et,comment=sx)