Final KSR Strategy Code

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

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © askkuldeeprandhawa

//@version=4

strategy("KSR Strategy", overlay=true)

//par1=input(10)
par1=input(title="Strategy EMA 1", type=input.integer, defval=11, minval=1,
maxval=200, step=1)
par2=input(title="Strategy EMA 2", type=input.integer, defval=37, minval=1,
maxval=200, step=1)
ema1=ema(close,par1)
ema2=ema(close,par2)
buy=ema1>ema2
sell=ema2>ema1
mycolor= iff(buy,color.green,iff(sell,color.blue,color.red))
barcolor(color=mycolor)

par3=input(title="EMA 1", type=input.integer, defval=50, minval=1, maxval=500,


step=1)
par4=input(title="EMA 2", type=input.integer, defval=100, minval=1, maxval=500,
step=1)
par5=input(title="EMA 3", type=input.integer, defval=200, minval=1, maxval=500,
step=1)
plot(ema(close,par3),"EMA 1",color=color.blue)
plot(ema(close,par4),"EMA 2",color=color.red)
plot(ema(close,par5),"EMA 3",color=color.black)

ibuy=crossover(ema1,ema2)
iSell=crossunder(ema1,ema2)
//iSell=crossunder(close,ema1)
varp=tostring(close[1])
//plotshape(ibuy, "Up Arrow", shape.triangleup, location.belowbar, color.green, 0,
0,"Buy" , color.green, true, size.tiny)
//plotshape(iSell, "Down Arrow", shape.triangledown, location.abovebar, color.red,
0, 0, "Sell", color.red, true, size.tiny)

crossed =crossover(ema(close,par1), ema(close,par2))


if crossed
l = label.new(bar_index, na, tostring(close),
color=color.green,
textcolor=color.white,
style=label.style_labelup, yloc=yloc.belowbar)

crossed2 =crossunder(ema(close,par1), ema(close,par2))


if crossed2
l = label.new(bar_index, na, tostring(close),
color=color.red,
textcolor=color.white,
style=label.style_labeldown, yloc=yloc.abovebar)

plot(ema(close,par1),"EMA Short",color=color.white)
plot(ema(close,par2),"EMA Long",color=color.orange)
//plot(ema(close,50),"EMA 50",color=color.purple)
longCondition = crossover(ema(close, par1), ema(close, par2))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)

shortCondition = crossunder(ema(close, par1), ema(close, par2))


if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)

// Heiken Ashi Code


// Begin here

ma1_len = input(title="HK MA1", type=input.integer, defval=7, minval=1, maxval=100,


step=1)
ma2_len = input(title="HK MA2", type=input.integer, defval=21, minval=1,
maxval=100, step=1)

o = ema(open, ma1_len)
c = ema(close, ma1_len)
h = ema(high, ma1_len)
l = ema(low, ma1_len)

tim1=input('D',"Short Time")
tim2=input('W',"Long Time")

ema_p=input(title="EMA Period", type=input.integer, defval=16, minval=1,


maxval=100, step=1)
refma = ema(close, ema_p)
plot(refma, title="EMA" , linewidth=1, color=close < refma ? color.orange :
color.blue)
ha_t = heikinashi(syminfo.tickerid)
ha_o = security(ha_t, tim2, o)
ha_c = security(ha_t, tim2, c)
ha_h = security(ha_t, tim2, h)
ha_l = security(ha_t, tim2, l)
o2 = ema(ha_o, ma2_len)
c2 = ema(ha_c, ma2_len)
h2 = ema(ha_h, ma2_len)
l2 = ema(ha_l, ma2_len)
ha_col = ha_c > ha_o ? color.red : color.green
//plotcandle(o2, o2, c2, c2, title="Heikin Ashi Smoothed", color=ha_col)
plotshape(true, style=shape.circle, color=ha_c > ha_o ? color.green : color.red,
location=location.bottom)
// End Here

ha_t1 = heikinashi(syminfo.tickerid)
ha_o1 = security(ha_t1, tim1, o)
ha_c1 = security(ha_t1, tim1, c)
ha_h1 = security(ha_t1, tim1, h)
ha_l1 = security(ha_t1, tim1, l)
o3 = ema(ha_o1, ma2_len)
c3 = ema(ha_c1, ma2_len)
h3 = ema(ha_h1, ma2_len)
l3 = ema(ha_l1, ma2_len)
ha_col1 = ha_c1 > ha_o1 ? color.red : color.green
//plotcandle(o2, o2, c2, c2, title="Heikin Ashi Smoothed", color=ha_col)
plotshape(true, style=shape.circle, color=ha_c1 > ha_o1 ? color.green : color.red,
location=location.top)

You might also like