pbergden

Moving Average Crossover 0001

373
The first strategy for my (also first) Everyday project. During the rest of 2016 I plan to create a new strategy everyday
and I give myself between 15 minutes and 2 hours to complete the idea.

The goal is to improve my knowledge of Pine Script, become a faster strategy coder, and experiment with different strategic trading ideas.

I'm new to strategies and algorithmic trading, and hoping to learn from the community, so any feedback, advice or corrections is very much welcome!
/pbergden

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
strategy("Moving Average Crossover", overlay=true)

ema14 = ema(close, 14)
ema28 = ema(close, 28)
sma56 = sma(close, 56)

long = cross(ema14, sma56) and ema14 > ema28
short = cross(ema14, sma56) and ema14 < ema28   

plot(ema14, title="14", color=green, linewidth=2)
plot(ema28, title="28", color=red, linewidth=2)
plot(sma56, title="56", color=blue, linewidth=3)

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

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

if time >= testPeriodStart
    if time <= testPeriodStop
        strategy.entry("Long", strategy.long, 1.0, when=long)
        strategy.entry("Short", strategy.short, 1.0, when=short)

if time >= testPeriodStart
    if time <= testPeriodStop
	    strategy.exit("Close Long", "Long", profit=2000, loss=500)
	    strategy.exit("Close Short", "Short", profit=2000, loss=500)