-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStrat_GridTrader.c
38 lines (32 loc) · 1.08 KB
/
Strat_GridTrader.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
// Grid trader
// find all trades at a grid line
bool findTrade(var Price,var Grid,bool IsShort)
{
int result = false;
for(open_trades)
if((TradeIsShort == IsShort)
and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2)) {
result = true;
break_trades;
}
return result;
}
int run()
{
BarPeriod = 1440;
Hedge = 2; // allow long & short trades at the same time
EntryTime = LifeTime = 250; // close trades after 1 year
var Price, Grid = 200*PIP; // set grid distance to 200 pips
var Close = priceClose();
// place pending trades at 5 grid lines
// above and below the current price
for(Price = 0; Price < Close+5*Grid; Price += Grid)
{
if(Price < Close-5*Grid) continue; // find the lowest grid line
if(NumOpenTotal + NumPendingTotal > 200) break; // place not more than 200 trades
if(Price < Close and !findTrade(Price,Grid,true))
enterShort(1,Price,20*Grid,Grid); // place short trades below the current price
else if(Price > Close and !findTrade(Price,Grid,false))
enterLong(1,Price,20*Grid,Grid); // place long trades above the current price
}
}