// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © lukescream //@version=4 strategy("EMA Slope Trend Follower AlgoJi", initial_capital=10000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.06, slippage = 2, default_qty_value=30, overlay=false) //definizione input average = input (title="Source MA Type", type=input.string, defval="EMA",options=["EMA","SMA"]) len = input(130, minval=1, title="Source MA Length") slopeFlen = input (9,title="Fast Slope MA Length") slopeSlen= input (21,title="Slow Slope MA Length") trendfilter=input(true,title="Trend Filter") trendfilterperiod=input(200,title="Trend Filter MA Period") trendfiltertype=input (title="Trend Filter MA Type", type=input.string, defval="EMA",options=["EMA","SMA"]) volatilityfilter=input(false,title="Volatility Filter") volatilitystdevlength=input(20,title="Vol Filter STDev Length") volatilitystdevmalength=input(30,title="Vol Filter STDev MA Length") //variabili out = if average == "EMA" ema(close,len) else sma(close,len) slp = change(out)/out emaslopeF = ema(slp,slopeFlen) emaslopeS = ema(slp,slopeSlen) //variabili accessorie e condizioni TrendConditionL=if trendfiltertype =="EMA" close>ema(close,trendfilterperiod) else close>sma(close,trendfilterperiod) TrendConditionS=if trendfiltertype =="EMA" closesma(stdev(close,volatilitystdevlength),volatilitystdevmalength) ConditionEntryL= if trendfilter == true if volatilityfilter == true emaslopeF>emaslopeS and TrendConditionL and VolatilityCondition else emaslopeF>emaslopeS and TrendConditionL else if volatilityfilter == true emaslopeF>emaslopeS and VolatilityCondition else emaslopeF>emaslopeS ConditionEntryS= if trendfilter == true if volatilityfilter == true emaslopeF 0 // strategy.close("SLPLong") // if ConditionEntryL // strategy.entry("SLPLong",long=true) // if ConditionEntryS // strategy.entry("SLPShort",long=false) buy_signal = ConditionEntryL sell_signal = ConditionEntryS //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) //and st if(buy_signal and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(sell_signal and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(buy_signal and st and strategy.position_size!=0) strategy.entry("BUY",strategy.long,comment=sxle) if(sell_signal and st and strategy.position_size!=0) strategy.entry("SELL",strategy.short,comment=lxse) strategy.close(id="BUY",when=ConditionExitL and strategy.position_size!=0 ,comment=lx) strategy.close(id="SELL",when=ConditionExitS and strategy.position_size!=0,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)