TradingView
ROBO_Trading
4 фев 2018 г., 09:05

Noro's Trend MAs Strategy v2.0 

Bitcoin / DollarBitfinex

Описание

Don't use on pairs of type "crypto/crypto"!

Only for pairs like "crypto/fiat" ("BTC/USD", "BTC/CNY", "ETH/USD", "ETH/CNY", etc)

Trade strategy which uses only 2 MA.
The slow MA (blue) is used for definition of a trend
The fast MA (red) is used for an entrance to the transaction

For:

- For H1
- For crypto/fiat
- Good for "BTC/USD", "ETH/USD"

Recomended:

Long = true (if it is profitable as a result of backtests)
Short = true (if it is profitable as a result of backtests)
Stops = false
Stop, % = any
OHLC4 = any
Use Fast MA = true
Fast MA Period = 5
Slow MA Period = 21
Bars Q = (2 for "bitcoin/fiat" or 1 for "crypto/fiat")
Extreme = true (if "crypto/fiat")

In the new version 2.0

- CryptoBottom is added
Комментарии
Chrysalte
Hello,

I have done a change to get period :

//@version=2
strategy(title = "Noro's Trend MAs Strategy v2.0 +CB", shorttitle = "Trend MAs str 2.0", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)

//Settings
needlong = input(true, "long")
needshort = input(true, "short")
needstops = input(false, "stops")
stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %")
useohlc4 = input(false, defval = false, title = "Use OHLC4")
usefastsma = input(true, "Use fast MA Filter")
fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period")
slowlen = input(21, defval = 20, minval = 2, maxval = 200, title = "slow MA Period")
bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q")
needbg = input(false, defval = false, title = "Need trend Background?")
needarr = input(false, defval = false, title = "Need entry arrows?")
needex = input(true, defval = true, title = "Need extreme? (crypto/fiat only!!!)")
FromMonth = input(defval = 10, title = "From Month", minval = 1)
FromDay = input(defval = 3, title = "From Day", minval = 1)
FromYear = input(defval = 2017, title = "From Year", minval = 2014)
ToMonth = input(defval = 1, title = "To Month", minval = 1)
ToDay = input(defval = 1, title = "To Day", minval = 1)
ToYear = input(defval = 9999, title = "To Year", minval = 2014)



src = useohlc4 == true ? ohlc4 : close

//PriceChannel 1
lasthigh = highest(src, slowlen)
lastlow = lowest(src, slowlen)
center = (lasthigh + lastlow) / 2

//PriceChannel 2
lasthigh2 = highest(src, fastlen)
lastlow2 = lowest(src, fastlen)
center2 = (lasthigh2 + lastlow2) / 2

//Trend
trend = low > center and low[1] > center[1] ? 1 : high < center and high[1] < center[1] ? -1 : trend[1]

//Bars
bar = close > open ? 1 : close < open ? -1 : 0
redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0
greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0

//Fast RSI
fastup = rma(max(change(close), 0), 2)
fastdown = rma(-min(change(close), 0), 2)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))

//CryptoBottom
mac = sma(close, 10)
len = abs(close - mac)
sma = sma(len, 100)
max = max(open, close)
min = min(open, close)
up3 = close < open and len > sma * 3 and min < min[1] and fastrsi < 10 ? 1 : 0

//Signals
up = trend == 1 and (low < center2 or usefastsma == false) and (redbars == 1) ? 1 : 0
dn = trend == -1 and (high > center2 or usefastsma == false) and (greenbars == 1) ? 1 : 0

up2 = high < center and high < center2 and bar == -1 ? 1 : 0
dn2 = low > center and low > center2 and bar == 1 ? 0 : 0

//Lines
plot(center, color = blue, linewidth = 3, transp = 0, title = "Slow MA")
plot(center2, color = red, linewidth = 3, transp = 0, title = "PriceChannel 2")

//Arrows
plotarrow(up == 1 and needarr == true ? 1 : 0, colorup = black, colordown = black, transp = 0)
plotarrow(dn == 1 and needarr == true ? -1 : 0, colorup = black, colordown = black, transp = 0)

//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 90)

//Alerts
alertcondition(up == 1, title='buy', message='Uptrend')
alertcondition(dn == 1, title='sell', message='Downtrend')

//Trading
stoplong = up == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]
stopshort = dn == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]

longCondition = up == 1 or (up2 == 1 and needex == true) or up3 == 1
if (longCondition)
strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=((time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))))
strategy.exit("Stop Long", "Long", stop = stoplong, when=((time < timestamp(ToYear, ToMonth, ToDay, 23, 59))))

shortCondition = dn == 1
if (shortCondition)
strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=((time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))))
strategy.exit("Stop Short", "Short", stop = stopshort, when=((time < timestamp(ToYear, ToMonth, ToDay, 23, 59))))


Chrysalte
@Chrysalte, AND alerts don't work for me, I don't know why.
ROBO_Trading
@Chrysalte, for all
IvanShity
@Chrysalte, alerts work only with "study" type
ROBO_Trading
Chrysalte
@IvanShity, thanks !
ROBO_Trading
test1001test
@Chrysalte,
Error: connot compile script
line 88: mismatched input 'strategy.entry' expecting 'end of line without line continuation'

what's wrong?

strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=((time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))))
Chrysalte
@test1001test, Try to copy-paste the full script.

It is probably related to the input of the begining. Let me know after if it works :)
test1001test
@Chrysalte,

I copy and paste the full script
The problem remained
Ещё