Script (1)

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 14

//@strategy_alert_message {{strategy.order.

alert_message}}

//@version=5

strategy("Mlosch Strategy", overlay=true,process_orders_on_close = true )

pc_id = input.string(title='License ID', defval='', group='MT4/5 Settings', tooltip='This is your license ID')

pc_risk = input.float(title='Risk %', defval=1, step=0.1, minval=0, group='MT4/5 Settings', tooltip='Risk


Per Trade %')

pc_prefix = input.string(title='MetaTrader Symbol', defval='', group='MT4/5 Settings', tooltip='This is your


broker\'s MetaTrader symbol')

var symbol = pc_prefix

longa_close = pc_id + ',closelong,' + symbol + ''

shorta_close = pc_id + ',closeshort,' + symbol + ''

sps = strategy.position_size

bgColor = input.bool(false, "Activate High/Low View")

LondonColor = color.new(color.green, 90)

NYColor = color.new(color.red, 90)

AsiaColor = color.new(color.yellow, 90)

SydneyColor = color.new(color.blue, 90)


///Sessions

res = input.timeframe("D", "Resolution", ["D","W","M"])

london = input.session("0300-1200:1234567", "London Session")

ny = input.session("0800-1700:1234567", "New York Session")

// tokyo = input.session("2000-0400:1234567", "Tokyo Session")

// sydney = input.session("1700-0200:1234567", "Sydney Session")

//Bars

is_newbar(sess) =>

t = time(res, sess, "America/New_York")

na(t[1]) and not na(t) or t[1] < t

is_session(sess) =>

not na(time(timeframe.period, sess, "America/New_York"))

//London

London = input.bool(true, "London Session")

londonNewbar = is_newbar(london)

londonSession = is_session(london)
float londonLow = na

londonLow := if londonSession

if londonNewbar

low

else

math.min(londonLow[1],low)

else

londonLow

float londonHigh = na

londonHigh := if londonSession

if londonNewbar

high

else

math.max(londonHigh[1],high)

else

londonHigh

plotLL = plot(londonLow, color=color.new(#000000, 100))

plotLH = plot(londonHigh, color=color.new(#000000, 100))

fill(plotLL, plotLH, color = londonSession and London and bgColor ? LondonColor : na)

bgcolor(londonSession and London and not bgColor ? LondonColor : na,title = "London BG")
//New York

NY = input.bool(true, "New York Session")

nyNewbar = is_newbar(ny)

nySession = is_session(ny)

float nyLow = na

nyLow := if nySession

if nyNewbar

low

else

math.min(nyLow[1],low)

else

nyLow

float nyHigh = na

nyHigh := if nySession

if nyNewbar

high

else

math.max(nyHigh[1],high)
else

nyHigh

plotNYL = plot(nyLow, color=color.new(#000000, 100))

plotNYH = plot(nyHigh, color=color.new(#000000, 100))

fill(plotNYL, plotNYH, color = nySession and NY and bgColor ? NYColor : na)

bgcolor(nySession and NY and not bgColor ? NYColor : na,title = "NewYork BG")

grp2 = 'SuperOsc [LuxAlgo]'

length = input.int(10, minval=1,group = grp2)

mult = input.float(8., minval=1,group = grp2)

smooth = input.int(72, minval=1,group = grp2)

//Misc

// fixed = input.bool(false, 'Fixed Transparency', group='Misc')

//----

src = close

lower = 0.

upper = 0.

trend = 0

//----

atr = ta.atr(length) * mult


up = hl2 + atr

dn = hl2 - atr

upper := src[1] < upper[1] ? math.min(up, upper[1]) : up

lower := src[1] > lower[1] ? math.max(dn, lower[1]) : dn

trend := src > upper[1] ? 1 : src < lower[1] ? 0 : trend[1]

Spt = trend * lower + (1 - trend) * upper

//----

ama = 0.

osc = math.max(math.min((src - Spt) / (upper - lower), 1), -1)

alpha = math.pow(osc, 2) / length

ama := nz(ama[1] + alpha * (osc - ama[1]), osc)

hist = ta.ema(osc - ama, smooth)

//----

// fix_css = osc > 0 ? #0cb51a : #ff1100

// var_css = osc > 0 ? array.get(up_col, math.round(osc * 99)) : array.get(dn_col, math.round(osc * -1 *


99))

// sig_css = ama > 0 ? #2157f3 : #673ab7

// plot(fixed ? osc * 100 : na, 'Main Fixed', fix_css, 1, plot.style_area)

// plot(fixed ? na : osc * 100, 'Main Transp', var_css, 1, plot.style_columns, editable=false)

hist_ = osc * 100

from_cross = ta.barssince(ta.cross(hist_,0))

cr_bars = input.int(20,"From Cross")

super_b = hist_>0 and from_cross>=cr_bars


super_s = hist_<0 and from_cross>=cr_bars

grp3 = 'VuManChu B Divergences'

// PARAMETERS {

// WaveTrend

// wtShow = input.bool(true, title = 'Show WaveTrend', group = 'WaveTrend Settings')

// wtGoldShow = input.bool(true, title = 'Show Gold dots', group = 'WaveTrend Settings')

// wtSellShow = input.bool(true, title = 'Show Sell dots', group = 'WaveTrend Settings')

// wtDivShow = input.bool(true, title = 'Show Div. dots', group = 'WaveTrend Settings')

// vwapShow = input.bool(true, title = 'Show Fast WT', group = 'WaveTrend Settings')

wtChannelLen = input.int(9, title = 'WT Channel Length', group = 'WaveTrend Settings')

wtAverageLen = input.int(12, title = 'WT Average Length', group = 'WaveTrend Settings')

wtMASource = input.source(hlc3, title = 'WT MA Source', group = 'WaveTrend Settings')

wtMALen = input.int(3, title = 'WT MA Length', group = 'WaveTrend Settings')

// FUNCTIONS {

// Divergences

f_top_fractal(src) =>

src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0]

f_bot_fractal(src) =>

src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0]

f_fractalize(src) =>

f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
f_findDivs(src, topLimit, botLimit, useLimits) =>

fractalTop = f_fractalize(src) > 0 and (useLimits ? src[2] >= topLimit : true) ? src[2] : na

fractalBot = f_fractalize(src) < 0 and (useLimits ? src[2] <= botLimit : true) ? src[2] : na

highPrev = ta.valuewhen(fractalTop, src[2], 0)[2]

highPrice = ta.valuewhen(fractalTop, high[2], 0)[2]

lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2]

lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2]

bearSignal = fractalTop and high[2] > highPrice and src[2] < highPrev

bullSignal = fractalBot and low[2] < lowPrice and src[2] > lowPrev

bearDivHidden = fractalTop and high[2] < highPrice and src[2] > highPrev

bullDivHidden = fractalBot and low[2] > lowPrice and src[2] < lowPrev

[fractalTop, fractalBot, lowPrev, bearSignal, bullSignal, bearDivHidden, bullDivHidden]

// WaveTrend

f_wavetrend(src, chlen, avg, malen, tf) =>

tfsrc = request.security(syminfo.tickerid, tf, src)

esa = ta.ema(tfsrc, chlen)

de = ta.ema(math.abs(tfsrc - esa), chlen)

ci = (tfsrc - esa) / (0.015 * de)

wt1 = request.security(syminfo.tickerid, tf, ta.ema(ci, avg))

wt2 = request.security(syminfo.tickerid, tf, ta.sma(wt1, malen))

wtVwap = wt1 - wt2

wtCross = ta.cross(wt1, wt2)

wtCrossUp = wt2 - wt1 <= 0


wtCrossDown = wt2 - wt1 >= 0

wtCrosslast = ta.cross(wt1[2], wt2[2])

wtCrossUplast = wt2[2] - wt1[2] <= 0

wtCrossDownlast = wt2[2] - wt1[2] >= 0

[wt1, wt2, wtCross, wtCrossUp, wtCrossDown, wtCrosslast, wtCrossUplast, wtCrossDownlast, wtVwap]

// Calculates WaveTrend

[wt1, wt2, wtCross, wtCrossUp, wtCrossDown, wtCross_last, wtCrossUp_last, wtCrossDown_last,


wtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)

// } ALERTS

wt_b_lev = input.float(-58,"Long Below")

wt_s_lev = input.float(58,"Short Above")

wt_b = ta.crossover(wt1, wt2) and (wt2<wt_b_lev)

wt_s = ta.crossunder(wt1, wt2) and (wt2>wt_s_lev)

session_ok = (nySession and NY ) or (londonSession and London)

loss_done = ta.change(strategy.losstrades)

from_lost = ta.barssince(loss_done)

no_tr = input.int(10,"No Trade after Loss")

f_b = super_b and wt_b and session_ok and sps<=0 and (strategy.losstrades>1?from_lost>=no_tr:true)

f_s = super_s and wt_s and session_ok and sps>=0 and (strategy.losstrades>1?from_lost>=no_tr:true)

//

swingsl = input.int(10,"Bars SL")


buff = input.float(0.1,"SL Buffer")

lowest_ = ta.lowest(swingsl)-buff

highest_ = ta.highest(swingsl)+buff

rr = input.float(2,"Take Profit R:R")

be = input.float(1,"Break Even R:R")

risk_ = input.float(2,"Risk Per Trade %")

mtbuff = input.float(0.03,"MT Buffer %")*0.01

tpbuff = input.float(0.01,"MT TP Buff %")*0.01

ttpon = input.bool(true,"",inline = "ttp")

ttpbuff = input.float(0.1,"Trailing TP Buffer %",inline = "ttp")*0.01

var float l_sl = 0

var float l_ep = 0

var float l_tp = 0

var float l_be = 0

var int l_sl_ = 0

var float n_tsl_l = 0

if f_b

l_sl_ := 0

n_tsl_l := 0
if sps<0

alert(shorta_close,alert.freq_once_per_bar_close)

l_ep := close

l_sl := lowest_*(1-mtbuff)

l_tp := l_ep + rr*(l_ep-l_sl)

l_be := l_ep + be*(l_ep-l_sl)

l_qty = (risk_*0.01*strategy.equity) / (l_ep-l_sl)

longa = pc_id + ',buy,' + symbol + ',risk=' + str.tostring(pc_risk, '#.##')+ ',sl=' + str.tostring(l_sl, '#.#####')
+ ',tp=' + str.tostring(l_tp*(1+tpbuff), '#.#####')

strategy.entry("Long",strategy.long,qty = l_qty,alert_message = longa )

if sps>0 and high>=l_be and l_sl_[1]==0

l_sl := l_ep*(1+mtbuff)

l_sl_ := 1

if sps>0 and high>=l_tp and l_sl_[1]==1 and ttpon

l_sl := l_tp*(1-ttpbuff)

l_sl_ := 2

if low>low[1] and l_sl_[1]==2 and ttpon

l_sl_ := 3

if low>low[1] and l_sl_==3

n_tsl_l := low
f_l_sl =ttpon ? math.max(l_sl,n_tsl_l) :l_sl

strategy.exit("Ex Long","Long",stop = f_l_sl,limit =ttpon?na: l_tp ,alert_message = longa_close)

var float s_sl = 0

var float s_ep = 0

var float s_tp = 0

var float s_be = 0

var int s_sl_ = 0

var float n_tsl_s = 99999999

if f_s

s_sl_ := 0

n_tsl_s := 99999999

if sps>0

alert(longa_close,alert.freq_once_per_bar_close)

s_ep := close

s_sl := highest_*(1+mtbuff)

s_tp := s_ep - rr*(s_sl-s_ep)

s_be := s_ep - be*(s_sl-s_ep)

s_qty = (risk_*0.01*strategy.equity) / (s_sl-s_ep)

shorta = pc_id + ',sell,' + symbol + ',risk=' + str.tostring(pc_risk, '#.##') + ',sl=' + str.tostring(s_sl,


'#.#####')+ ',tp=' + str.tostring(s_tp*(1-tpbuff), '#.#####')

strategy.entry("Short",strategy.short,qty = s_qty,alert_message = shorta )


// if sps<0 and low<=s_be

// s_sl := s_ep*(1-mtbuff)

if sps<0 and low<=s_be and s_sl_[1]==0

s_sl := s_ep*(1-mtbuff)

s_sl_ := 1

if sps<0 and low<=s_tp and s_sl_[1]==1 and ttpon

s_sl := s_tp*(1+ttpbuff)

s_sl_ := 2

if high<high[1] and s_sl_[1]==2 and ttpon

s_sl_ := 3

if high<high[1] and s_sl_==3

n_tsl_s := high

f_s_sl =ttpon ? math.min(s_sl,n_tsl_s) :s_sl

strategy.exit("Ex Short","Short",stop = f_s_sl,limit =ttpon?na: s_tp,alert_message = shorta_close )

You might also like