-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstdrev.thinkscript
50 lines (38 loc) · 1.74 KB
/
stdrev.thinkscript
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
49
50
def OPEN_ACTUAL_TIME = 0930;
def CLOSE_ACTUAL_TIME = 1600;
def is_trading_hours = If((SecondsFromTime(OPEN_ACTUAL_TIME) >= 0 && SecondsTillTime(CLOSE_ACTUAL_TIME) > 0), 1, 0);
def stoploss = close < close[-10] * 0.95;
def rsi = RSI("average type" = "EXPONENTIAL");
input price = close;
input deviations = 1.1;
input short_gap = 0.3;
input full_range = no;
input length = 1024;
input spread = 0.0001;
input overshoot = 0.2;
input tradesize = 1;
input only_when_open = no;
def regression;
def std_deviation;
if (full_range) {
regression = InertiaAll(price);
std_deviation = StDevAll(price);
} else {
regression = InertiaAll(price, length);
std_deviation = StDevAll(price, length);
}
plot upper = regression + deviations * std_deviation;
plot breaker = regression + overshoot * std_deviation;
plot middle = regression;
plot lower = regression - deviations * std_deviation;
plot upper_s = regression + (deviations + short_gap) * std_deviation;
plot breaker_s = regression - overshoot * std_deviation;
plot middle_s = regression;
plot lower_s = regression - (deviations + short_gap) * std_deviation;
upper.SetDefaultColor(GetColor(8));
middle.SetDefaultColor(GetColor(8));
lower.SetDefaultColor(GetColor(8));
AddOrder(OrderType.BUY_TO_OPEN, (price crosses above lower - spread) and (is_trading_hours or not only_when_open), tradeSize = tradesize);
AddOrder(OrderType.SELL_TO_OPEN, (price crosses below upper_s + spread) and (is_trading_hours or not only_when_open), tradeSize = tradesize);
AddOrder(OrderType.SELL_TO_CLOSE, (price crosses above breaker) and (is_trading_hours or not only_when_open), tradeSize = tradesize);
AddOrder(OrderType.BUY_TO_CLOSE, (price crosses below breaker_s) and (is_trading_hours or not only_when_open), tradeSize = tradesize);