//@version=4 //Basic Hull Ma Pack tinkered by InSilico //Converted to Strategy by DashTrader strategy("Hull Suite Strategy AlgoJi", overlay=true, pyramiding=1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0) strat_dir_input = input(title="Strategy Direction", defval="all", options=["long", "short", "all"]) strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all strategy.risk.allow_entry_in(strat_dir_value) ////////////////////////////////////////////////////////////////////// // Testing Start dates testStartYear = input(2016, "Backtest Start Year") testStartMonth = input(1, "Backtest Start Month") testStartDay = input(1, "Backtest Start Day") testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0) //Stop date if you want to use a specific range of dates testStopYear = input(2030, "Backtest Stop Year") testStopMonth = input(12, "Backtest Stop Month") testStopDay = input(30, "Backtest Stop Day") testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0) testPeriod() => time >= testPeriodStart and time <= testPeriodStop ? true : false // Component Code Stop ////////////////////////////////////////////////////////////////////// //INPUT src = input(close, title="Source") modeSwitch = input("Hma", title="Hull Variation", options=["Hma", "Thma", "Ehma"]) length = input(55, title="Length(180-200 for floating S/R , 55 for swing entry)") switchColor = input(true, "Color Hull according to trend?") candleCol = input(false,title="Color candles based on Hull's Trend?") visualSwitch = input(true, title="Show as a Band?") thicknesSwitch = input(1, title="Line Thickness") transpSwitch = input(40, title="Band Transparency",step=5) //FUNCTIONS //HMA HMA(_src, _length) => wma(2 * wma(_src, _length / 2) - wma(_src, _length), round(sqrt(_length))) //EHMA EHMA(_src, _length) => ema(2 * ema(_src, _length / 2) - ema(_src, _length), round(sqrt(_length))) //THMA THMA(_src, _length) => wma(wma(_src,_length / 3) * 3 - wma(_src, _length / 2) - wma(_src, _length), _length) //SWITCH Mode(modeSwitch, src, len) => modeSwitch == "Hma" ? HMA(src, len) : modeSwitch == "Ehma" ? EHMA(src, len) : modeSwitch == "Thma" ? THMA(src, len/2) : na //OUT HULL = Mode(modeSwitch, src, length) MHULL = HULL[0] SHULL = HULL[2] //COLOR hullColor = switchColor ? (HULL > HULL[2] ? #00ff00 : #ff0000) : #ff9800 //PLOT ///< Frame Fi1 = plot(MHULL, title="MHULL", color=hullColor, linewidth=thicknesSwitch, transp=50) Fi2 = plot(visualSwitch ? SHULL : na, title="SHULL", color=hullColor, linewidth=thicknesSwitch, transp=50) ///< Ending Filler fill(Fi1, Fi2, title="Band Filler", color=hullColor, transp=transpSwitch) ///BARCOLOR barcolor(color = candleCol ? (switchColor ? hullColor : na) : na) // if HULL[0] > HULL[2] and testPeriod() // strategy.entry("buy", strategy.long) // if HULL[0] < HULL[2] and testPeriod() // strategy.entry("sell", strategy.short) buy_signal = HULL[0] > HULL[2] and testPeriod() sell_signal = HULL[0] < HULL[2] and testPeriod() //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(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) 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)