-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStrat_capture_breakout_TMF.c
98 lines (73 loc) · 2.53 KB
/
Strat_capture_breakout_TMF.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
capture an expected breakout of the hour prior to London open
a buy stop limit above the current price and a sell stop below the current price
a sell limit above the current price and a buy limit below the current price
one-cancels-the-other orders, or OCO orders
*/
#define HIGH AssetVar[0]
#define LOW AssetVar[1]
#define CANCELPENDING AssetVar[2]
int ocoTMF() // one-cancels-the-other orders
{
// When a pending order is executed, the other order is cancelled
if(CANCELPENDING == 1 and TradeIsPending) return 1; //exit the pending trade
if(TradeIsEntry) CANCELPENDING = 1; //trigger cancel pending
return 0;
}
int oco_sarTMF() // stop-and-reverse order enters an opposite order at market if a trade is stopped out
{
if(CANCELPENDING == 1 and TradeIsPending) return 1; //exit the pending trade
if(TradeIsEntry) CANCELPENDING = 1; //trigger cancel pending
if(TradeIsStop)
{
if(TradeIsLong) enterShort(oco_sarTMF);
else if(TradeIsShort) enterLong(oco_sarTMF);
}
return 0;
// we we don’t need to run our TMF at every tick ...
// – only when a trade hits its stop loss – ...
// ... so we can use 16 as the return value, which results in a slight increase in simulation speed
}
function run()
{
set(TICKS);
set(PLOTNOW);
BarPeriod = 5;
StartDate = 20190101;
if(is(INITRUN)) CANCELPENDING = 0;
// price series
vars highs = series(priceHigh());
vars lows = series(priceLow());
vars Price = series(price());
// get the highest high and the lowest low of pre-open
int openHour = 8;
if (lhour(WET) == openHour and minute() == 0)
{
HIGH = MaxVal(highs, 12);
LOW = MinVal(lows, 12);
CANCELPENDING = 0; //reset CANCELPENDING each day => script is limited to only one trade per day
}
if (lhour(WET) >= openHour)
{
if (between(priceClose(0), LOW, HIGH))
{
// Trail = 3*ATR(40); // Somehow with trail the profit is smaller
Entry = HIGH; Stop = LOW; // places pending buy and sell stops at these levels
if (NumOpenLong == 0) enterLong(ocoTMF); // enterLong(oco_sarTMF);
Entry = LOW; Stop = HIGH;
if (NumOpenShort == 0) enterShort(ocoTMF); // enterShort(oco_sarTMF);
}
}
if (lhour(WET) >= 20) // UTC = WET, but WET has summer time
{
exitLong("*"); exitShort("*");
}
// PlotBars = 800; // PlotBars = 200;
// PlotDate = 20170105;
PlotHeight1 = 400;
PlotWidth = 1200;
ColorEquity = ColorDD = 0;
plot("High", HIGH, MAIN|DOT, BLUE);
plot("Low", LOW, MAIN|DOT, RED);
}
////////////////////////////////////////////////////////////////////////////////////////////////////