Death Andgoldencross

You might also like

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

//@version=4

study("‫"التقاطع الذهبي وتقاطع الموت‬, overlay=true)

/////////////// Time Frame ///////////////


testStartYear = input(2012, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay, 0, 0)

testStopYear = input(2029, "Backtest Stop Year")


testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay, 0, 0)

testPeriod() => time >= testPeriodStart and time <= testPeriodStop ? true : false

///////////// MA Params /////////////


source1 = input(title="MA Source 1", defval=close)
maType1 = input(title="MA Type 1", defval="sma", options=["sma", "ema", "swma",
"wma"])
length1 = input(title="MA Length 1", defval=50)

source2 = input(title="MA Source 2", defval=close)


maType2 = input(title="MA Type 2", defval="sma", options=["sma", "ema", "swma",
"wma"])
length2 = input(title="MA Length 2", defval=200)

///////////// Get MA Function /////////////


getMAType(maType, sourceType, maLen) =>
res = sma(close, 1)

if maType == "ema"
res := ema(sourceType, maLen)
if maType == "sma"
res := sma(sourceType, maLen)
if maType == "swma"
res := swma(sourceType)
if maType == "wma"
res := wma(sourceType, maLen)
res

///////////// Moving Averages /////////////


fastMA = getMAType(maType1, source1, length1)
slowMA = getMAType(maType2, source2, length2)

///////////// Crosses /////////////


long = crossover(fastMA, slowMA)
short = crossunder(fastMA, slowMA)

/////////////// Plotting ///////////////


checkColor() => fastMA > slowMA
colCheck = checkColor() ? color.lime : color.red
p1 = plot(fastMA, color = colCheck, linewidth=1)
p2 = plot(slowMA, color = colCheck, linewidth=1)
fill(p1, p2, color = checkColor() ? color.lime : color.red)
plotshape(long, title="‫"شراء‬, text="‫"شراء‬, color=color.green, style=shape.labelup,
location=location.belowbar, size=size.small, textcolor=color.white) //plot for buy
icon
plotshape(short, title="‫"بيع‬, text="‫"بيع‬, color=color.red, style=shape.labeldown,
location=location.abovebar, size=size.small, textcolor=color.white) //plot for
sell icon

/////////////// Alerts ///////////////


alertcondition(long, title='Long', message='Long Signal')
alertcondition(short, title='Short', message='Short Signal')

You might also like