Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LOVE JOY PEACE PATIENCE KINDNESS GOODNESS FAITHFULNESS GENTLENESS SELF-CONTROL
- // Orig Auth: © twingall
- // Updated Murat's Strategy to Study w/ Alerts: @joshuamcgowan
- // Date: 2-27-2020
- //@version=4
- strategy(title = "% above SMA200- Murat idea strategy", overlay=false, currency=currency.USD, commission_value=0.075,commission_type=strategy.commission.percent, initial_capital=1000)
- ///////////////////////////////////////////////
- //* Backtesting Period Selector | Component *//
- ///////////////////////////////////////////////
- testStartYear = input(2019, "Backtest Start Year",minval=1980)
- testStartMonth = input(1, "Backtest Start Month",minval=1,maxval=12)
- testStartDay = input(1, "Backtest Start Day",minval=1,maxval=31)
- testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
- testStopYear = input(2020, "Backtest Stop Year",minval=1980)
- testStopMonth = input(12, "Backtest Stop Month",minval=1,maxval=12)
- testStopDay = input(31, "Backtest Stop Day",minval=1,maxval=31)
- testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
- testPeriod() => time >= testPeriodStart and time <= testPeriodStop ? true : false
- ///////////////////////////////////////////////
- //* Inputs and Variables *//
- ///////////////////////////////////////////////
- SMA = sma(close, 200)
- diff = ((close - SMA)/close)*100
- ATR = atr(9)
- plot(diff)
- condition = diff>10
- anticondition = diff<-10
- ///////////////////////////////////////////////
- //* Strategy Entry & Exit Conditions *//
- ///////////////////////////////////////////////
- if condition and testPeriod()
- stop_level = close + 2*ATR
- profit_level = close - 2*ATR
- strategy.entry(id="Short", long=false)
- strategy.exit("TP/SL", "Short", stop=stop_level, limit=profit_level)
- if anticondition and testPeriod()
- stop_level = close - 2*ATR
- profit_level = close + 2*ATR
- strategy.entry(id="Long", long=true)
- strategy.exit("TP/SL", "Long", stop=stop_level, limit=profit_level)
- // END //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement