-
Notifications
You must be signed in to change notification settings - Fork 10
/
StairsStrategy.cs
53 lines (41 loc) · 1.13 KB
/
StairsStrategy.cs
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
using SimpleBacktester.Data;
namespace SimpleBacktester.Strategies
{
public class StairsStrategy : ITakerStrategy
{
private readonly bool _preserverLastBar;
private RangeBarModel _lastBar;
public StairsStrategy(bool preserverLastBar)
{
_preserverLastBar = preserverLastBar;
}
public Action Decide(RangeBarModel bar, double inventoryAbsolute)
{
if (_lastBar == null)
{
_lastBar = bar;
return Action.Nothing;
}
var open = _lastBar.CurrentPrice;
var close = bar.CurrentPrice;
//var open = bar.Open;
//var close = bar.Close;
if (!_preserverLastBar)
{
_lastBar = bar;
}
if (close > open)
{
// green bar
return Action.Sell;
}
if (close < open)
{
// red bar
return Action.Buy;
}
_lastBar = bar;
return Action.Nothing;
}
}
}