-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parallels.cs
104 lines (84 loc) · 3.08 KB
/
Parallels.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
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
97
98
99
100
101
102
103
104
using cAlgo.API;
namespace Parallels
{
public class ParallelGenerator
{
private readonly Robot _cbot;
public double Start { get; private set; }
public double End { get; private set; }
public double Step { get; private set; }
public double Add { get; private set; }
public double Current { get; private set; }
public bool IsAdd { get; private set; }
public List<double> Generated { get; private set; }
public double UpperBuyPrice { get; private set; }
public double UpperSellPrice { get; private set; }
public double LowerBuyPrice { get; private set; }
public double LowerSellPrice { get; private set; }
public ParallelGenerator(Robot _robot, double start, double end, double step, double add)
{
_cbot = _robot;
Start = Math.Min(start, end);
End = Math.Max(start, end);
Step = step;
Add = add;
Current = Start;
IsAdd = false;
Generated = new List<double>();
}
public void GenerateInternal()
{
Generated.Clear();
double stepAdd = Step + Add;
double stepSubtract = Step - Add;
while (Current <= End)
{
Generated.Add(Current);
if (!IsAdd)
{
Current += stepSubtract;
}
else
{
Current += stepAdd;
}
IsAdd = !IsAdd;
}
}
public void Generate()
{
double closePrice = (_cbot.Symbol.Bid + _cbot.Symbol.Ask) / 2;
int TotalSizeGenerated = Generated.Count;
if (TotalSizeGenerated <= 0)
{
return;
}
UpperBuyPrice = double.MinValue;
UpperSellPrice = double.MinValue;
LowerBuyPrice = double.MinValue;
LowerSellPrice = double.MinValue;
for (int i = 0; i < Generated.Count - 1; i++)
{
if (closePrice > Generated[i] && closePrice < Generated[i + 1])
{
if (closePrice < Generated[i] + Add)
{
_cbot.Print("Inside a Parallel");
UpperBuyPrice = Generated[i + 1];
UpperSellPrice = Generated[i] + Add;
LowerBuyPrice = Generated[i];
LowerSellPrice = Generated[i - 1] + Add;
break;
}
_cbot.Print("Between Parallels");
UpperSellPrice = Generated[i + 1] + Add;
UpperBuyPrice = Generated[i + 1];
LowerSellPrice = Generated[i] + Add;
LowerBuyPrice = Generated[i];
break;
}
}
_cbot.Print($"UpperBuy {UpperBuyPrice} UpperSell {UpperSellPrice} LowerBuy {LowerBuyPrice} LowerSell {LowerSellPrice}");
}
}
}