//@version=3 // strategy(title = "Open Close Cross Strategy R5.1 revised by JustUncleL Modified_ALGO", shorttitle = "OCC Strategy R5.1 Modified_ALGO", overlay = true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, calc_on_every_tick=false) // === INPUTS === useRes = input(defval = true, title = "Use Alternate Resolution?") intRes = input(defval = 3, title = "Multiplier for Alernate Resolution") stratRes = ismonthly? tostring(interval*intRes,"###M") : isweekly? tostring(interval*intRes,"###W") : isdaily? tostring(interval*intRes,"###D") : isintraday ? tostring(interval*intRes,"####") : '60' basisType = input(defval = "TEMA", title = "MA Type:TEMA") basisLen = input(defval = 8, title = "MA Period", minval = 1) scolor = input(false, title="Show coloured Bars to indicate Trend?") delayOffset = input(defval = 0, title = "Delay Open/Close MA (Forces Non-Repainting)", minval = 0, step = 1) tradeType = input("BOTH", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"]) // === /INPUTS === // Constants colours that include fully non-transparent option. green100 = #008000FF lime100 = #00FF00FF red100 = #FF0000FF blue100 = #0000FFFF aqua100 = #00FFFFFF darkred100 = #8B0000FF gray100 = #808080FF // === BASE FUNCTIONS === // Returns MA input selection variant, default to SMA if blank or typo. variant(type, src, len) => v2 = ema(src, len) // Exponential v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential // security wrapper for repeat calls reso(exp, use, res) => use ? security(tickerid, res, exp, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : exp // === /BASE FUNCTIONS === // === SERIES SETUP === closeSeries = variant(basisType, close[delayOffset], basisLen) openSeries = variant(basisType, open[delayOffset], basisLen) // === /SERIES === // === PLOTTING === // Get Alternate resolution Series if selected. closeSeriesAlt = reso(closeSeries, useRes, stratRes) openSeriesAlt = reso(openSeries, useRes, stratRes) // trendColour = (closeSeriesAlt > openSeriesAlt) ? green : red // === /PLOTTING === // // // === ALERT conditions xlong = crossover(closeSeriesAlt, openSeriesAlt) xshort = crossunder(closeSeriesAlt, openSeriesAlt) longCond = xlong // alternative: longCond[1]? false : (xlong or xlong[1]) and close>closeSeriesAlt and close>=open shortCond = xshort // alternative: shortCond[1]? false : (xshort or xshort[1]) and close0?tpPoints:na SL = slPoints>0?slPoints:na // Make sure we are within the bar range, Set up entries and exit conditions if (tradeType!="NONE") strategy.entry("long", strategy.long, when=longCond==true and tradeType!="SHORT") strategy.entry("short", strategy.short, when=shortCond==true and tradeType!="LONG") strategy.close("long", when = shortCond==true and tradeType=="LONG") strategy.close("short", when = longCond==true and tradeType=="SHORT") strategy.exit("XL", from_entry = "long", profit = TP, loss = SL) strategy.exit("XS", from_entry = "short", profit = TP, loss = SL) // === /STRATEGY === // eof