// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © yashp1334 //@version=4 //@version=4 //Script by MrBadger //Free for public consumption //There is very little original here, the idea is discussed in the underground traders alliance and // was (apparently) the basis of what was at one time myfxbooks most profitable strategy. // I can't find the original video that was floating around on youtube, but if i find it again, i'll link it here. // // This is bascially just the TV default envelope code copied and modified. // THe idea is to have an envelope based on a low length, exponential basis. Then to manually "tune" // the percent input so that the envelopes engulf most bars. // // Anything that protudes beyond that level, especially at key levels, is likely to revert back to the ema. // Bear in mind, a run away trend will also push past the envelopes and continue running for several (3-5) bars // so, use it mindfully andthoughfully with all the usual cautions about risk management. strategy(title="Mean recursion envelop", shorttitle="MRE", overlay=true) len = input(5) calibrationFactor = input(.7) rangeLookback = input(100) range = sma(tr(true),rangeLookback) * .7 src = input(close, title="Source") exponential = input(false) basis = exponential ? ema(src, len) : sma(src, len) percent = range/basis *100 k = percent/100.0 upper = basis * (1 + k) lower = basis * (1 - k) buySignal = crossover(src, lower) sellSignal = crossunder(src, upper) //INTRADAY 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) //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(buySignal and st and strategy.position_size==0) strategy.entry("BUY",strategy.long,comment=le) if(sellSignal and st and strategy.position_size==0) strategy.entry("SELL",strategy.short,comment=se) if(buySignal and st and strategy.position_size!=0) strategy.entry("BUY",strategy.long,comment=sxle) if(sellSignal 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) plot(basis, "Basis", color=#FF6A00) u = plot(upper, "Upper", color=#0094FF) l = plot(lower, "Lower", color=#0094FF) fill(u, l, color=#0094FF, transp=95, title="Background") alertcondition(high>upper,"Enveloped breached", "look for reversion to mean") alertcondition(low