// NAVRANG081@GMAIL.COM //@version=4 strategy("ALGO", overlay=true, initial_capital = 50000, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01) i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time) i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time) inDateRange = time >= i_startTime and time <= i_endTime resolution = input("2D", type=input.resolution) HTFMultiplier = input(22, minval=1, step=1) offset = input(0, minval=0, step=1) lookahead = input(true) gaps = false f_secureSecurity_on_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_on) f_secureSecurity_on_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_on, gaps=barmerge.gaps_off) f_secureSecurity_off_on(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_on) f_secureSecurity_off_off(_symbol, _res, _src, _offset) => security(_symbol, _res, _src[_offset], lookahead = barmerge.lookahead_off, gaps=barmerge.gaps_off) f_multiple_resolution(HTFMultiplier) => target_Res_In_Min = timeframe.multiplier * HTFMultiplier * ( timeframe.isseconds ? 1. / 60. : timeframe.isminutes ? 1. : timeframe.isdaily ? 1440. : timeframe.isweekly ? 7. * 24. * 60. : timeframe.ismonthly ? 30.417 * 24. * 60. : na) target_Res_In_Min <= 0.0417 ? "1S" : target_Res_In_Min <= 0.167 ? "5S" : target_Res_In_Min <= 0.376 ? "15S" : target_Res_In_Min <= 0.751 ? "30S" : target_Res_In_Min <= 1440 ? tostring(round(target_Res_In_Min)) : tostring(round(min(target_Res_In_Min / 1440, 365))) + "D" f_get_htfHighOpen(resolution, HTFMultiplier, lookahead, gaps, offset)=> derivedResolution = resolution == ""?f_multiple_resolution(HTFMultiplier):resolution nhigh_on_on = f_secureSecurity_on_on(syminfo.tickerid, derivedResolution, high, offset) nopen_on_on = f_secureSecurity_on_on(syminfo.tickerid, derivedResolution, open, offset) nhigh_on_off = f_secureSecurity_on_off(syminfo.tickerid, derivedResolution, high, offset) nopen_on_off = f_secureSecurity_on_off(syminfo.tickerid, derivedResolution, open, offset) nhigh_off_on = f_secureSecurity_off_on(syminfo.tickerid, derivedResolution, high, offset) nopen_off_on = f_secureSecurity_off_on(syminfo.tickerid, derivedResolution, open, offset) nhigh_off_off = f_secureSecurity_off_off(syminfo.tickerid, derivedResolution, high, offset) nopen_off_off = f_secureSecurity_off_off(syminfo.tickerid, derivedResolution, open, offset) nhigh = lookahead and gaps ? nhigh_on_on : lookahead and not gaps ? nhigh_on_off : not lookahead and gaps ? nhigh_off_on : not lookahead and not gaps ? nhigh_off_off : na nopen = lookahead and gaps ? nopen_on_on : lookahead and not gaps ? nopen_on_off : not lookahead and gaps ? nopen_off_on : not lookahead and not gaps ? nopen_off_off : na [nhigh, nopen ] [nhigh, nopen ] = f_get_htfHighOpen(resolution, HTFMultiplier, lookahead, gaps, offset) [nhighlast,nopenlast ] = f_get_htfHighOpen(resolution, HTFMultiplier, lookahead, gaps, offset+1) plot(nhigh , title="HTF High",style=plot.style_circles, color=color.green, linewidth=1) plot(nopen , title="HTF OPEN",style=plot.style_circles, color=color.fuchsia, linewidth=1) buyCondition = nhigh > nopenlast sellCondition = nhigh < nopenlast strategy.entry("Buy", strategy.long, when= buyCondition and inDateRange, oca_name="oca_buy", oca_type=strategy.oca.cancel) strategy.entry("Sell", strategy.short, when= sellCondition and inDateRange, oca_name="oca_sell", oca_type=strategy.oca.cancel)