-
Notifications
You must be signed in to change notification settings - Fork 10
/
趋势骑手
48 lines (38 loc) · 1.37 KB
/
趋势骑手
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © aaaasdasdaaa
//@version=4
strategy("趋势骑手", overlay=true)
fastlength = input(12)
slowlength = input(36)
adxlevel = input(40)
fast_ema = ema(close,fastlength)
slow_ema = ema(close,slowlength)
signal = fast_ema - slow_ema
plot(fast_ema, color = color.red)
plot(slow_ema, color = color.yellow)
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
longCondition = crossover(close, fast_ema) and (signal > 0)
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
if (crossunder(sig,adxlevel))
strategy.close("My Long Entry Id")
shortCondition = crossunder(close, fast_ema) and (signal < 0)
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
if (crossover(sig,adxlevel))
strategy.close("My Short Entry Id")